Phpmailer发送附件,但不是身体

时间:2011-07-18 17:37:33

标签: php email phpmailer

我有一个表单,我试图通过PHPmailer提交电子邮件。出于某种原因,phpmailer发送电子邮件的附件,但不发送正文/消息。继承我的phpmailer文件..

$name = "Purchase Form";
$email_subject = "New Purchase Ticket";

$body = "geg";

foreach ($_REQUEST as $field_name => $value){
if (!empty($value)) $body .= "$field_name = $value\n\r";
}
$Email_to = "jonahkatz@yahoo.com"; // the one that recieves the email
$email_from = "No reply!";
//
//==== PHP Mailer With Attachment Func ====\\
//
function SendIt() {
//
global $attachments,$body,$name,$Email_to,$email_subject,$email_from;
//
$mail = new PHPMailer();
$mail->IsQmail();// send via SMTP
$mail->From = $email_from;
$mail->FromName = $name;
$mail->AddAddress($Email_to);
$mail->AddReplyTo($email_from);
$mail->WordWrap = 50;// set word wrap
$mail->IsHTML = true;
$mail ->MsgHTML($body);
$mail->AltBody = 'to view blah';
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->Subject = $email_subject;
if(!$mail->Send())
{
}
//
{echo "Message has been sent";}


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


SendIt();




}




?>

有什么输入?感谢。

1 个答案:

答案 0 :(得分:2)

->MsgHTML()没有设置正文。它返回带有inlined-img urls的修改版本以及诸如此类和DOES将AltBody设置为HTML的文本版本。你仍然需要做

$mail->Body = $body;