Phpmailer发送附件,但不发送正文


Phpmailer sending attachments, but not the body

我有一个表单,我试图通过电子邮件提交使用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();


}


?>

输入吗?谢谢。

->MsgHTML()不设置正文。它返回带有内联img url和其他内容的修改版本,并将AltBody设置为HTML的文本版本。你仍然需要做

$mail->Body = $body;