1
<?php
$file           =   $_FILES["file"]["tmp_name"];
$file1          =   $_FILES["file1"]["tmp_name"];

$attachment_path    =   $file;
$attachment_path1   =   $file1;

$body   = "some text";

include("class.phpmailer.php");

//Create a new PHPMailer instance
$mail = new PHPMailer();
//Set who the message is to be sent from
$mail->SetFrom('mail@example.com', $username);
//Set who the message is to be sent to
$mail->AddAddress('mail@example.com', 'Ticket Relief');
//Set the subject line
$mail->Subject = 'Inquiry from website by Form Fillup';
//Replace the plain text body with one created manually
$mail->Body = $body;
//Attach an image file
$mail->AddAttachment($attachment_path, "attachment1", "base64", "application/octet-stream");
$mail->AddAttachment($attachment_path1, "attachment1", "base64", "application/octet-stream");

//Send the message, check for errors
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Email has been sent! Please <a href='index.php'>Click Here </a> to go back to home page";
}

?>

およびhtmlコード

<form action="functions.php" method="post" enctype="multipart/form-data">

                   <div class="outer1">
                        <label> Please Choose File</label>
                        <input type="file" class="span4" name="file">
                    </div>
                    <div class="outer1">
                        <label> Please Choose File</label>
                        <input type="file" class="span4" name="file1">
                    </div>                     
                   <div class="outer1">
                        <input type="submit" class="submit btn btn-success btn-large pull-right" value="Submit">
                   </div>
                </form>         
  1. メールを受信して​​いますが、添付ファイルを開くことができません。不明な形式です。
  2. ファイルが 200kb 以上の場合、メールの送信に 40 ~ 45 秒かかり、600kb 以上の場合、処理に 1 分以上かかります。

これらの問題について助けが必要です

4

1 に答える 1

0

まず、アップロードが実際に成功したことを確認します。これを試して:

if(isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK && 
   isset($_FILES['file1']) && $_FILES['file1']['error'] == UPLOAD_ERR_OK

) {
  $mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
  $mail->AddAttachment($_FILES['file1']['tmp_name'], $_FILES['file1']['name']); 
}
else {
  // Do something else, upload is not successful
}

次のような文字列だけでなく、ファイル名を2番目の引数として設定する必要がありますattachment1

AddAttachment($path, $filename, ...
                      //^ put here the file name like $_FILES['file1']['name']
于 2013-09-09T10:22:19.983 に答える