添加多个附件

时间:2012-02-16 21:01:40

标签: php phpmailer

我制作了一个包含多个附件的电子邮件表单。我使用的代码如下: 错误是当我为多个附件编写循环,并在提交按钮事件上设置所有代码时,没有任何事情发生..之前,它。发送邮件,附件除了循环附件

   <?php
   (isset($_POST['Submit1']))
    {
include "class.phpmailer.php";
$From = "madeeha.rehman5@gmail.com";
$FromName = "From Name";
$To = "madeeha.rehman5@gmail.com";
$ToName = "To Name";
$Subject = "Hello there, you will receive some files";
$Body = "This is a test email which includes attachment";

$mail = new PHPMailer();

$mail->From     = $From;
$mail->FromName = $FromName;

$mail->AddAddress($To , $ToName);

$mail->WordWrap = 50;               // set word wrap
$mail->Priority = 1; 
$mail->IsHTML(true);  
$mail->Subject  =  $Subject;
$mail->Body     =  $Body;

foreach($_FILES as $key => $file){
     $target_path = "uploads/";
    $target_path = $target_path .basename($file['name']);

   if(move_uploaded_file($file['tmp_name'], $target_path)) {
    echo "the file ".basename($file['name'])." has been uploaded";
   }else {
    echo "there was an error";
     }
    $mail->AddAttachment($target_path);
     }
$mail->AddAttachment("imgj.jpg");
$mail->AddAttachment("Mailbox.png");    // attachment

if(!$mail->Send())
{
    echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
    echo 'Message has been sent.';

}
}
    ?>

html代码是          “enctype =”multipart / form-data“&gt;                                  任何人告诉我,为什么这个PHP代码在做nthng

0 个答案:

没有答案
相关问题