PHP邮件不包括正文

时间:2013-10-11 08:16:18

标签: php phpmailer

我有以下表格:

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

<input required="required" name="name" type="text" placeholder="Name" /><br /><br />
<input required="required" name="email" type="text" placeholder="Email" /><br /><br />
<input required="required" name="phone" type="text" placeholder="Phone Number" /><br /><br />
<input required="required" name="website" type="text" placeholder="URL to blog / website" /><br /><br />
<input type="file" name="file" /><br /><br />
<textarea name="message" cols="" rows="10" placeholder="Message (optional)"></textarea><br /><br />
<input name="send_form" type="submit" value="Submit" style="float:right; width:200px;" />
</form>

这是我的php:

$mail             = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "xxxxxx"; // sets the SMTP server
$mail->Username   = "xxxxxxx";// SMTP account username
$mail->Password   = "xxxx";        // SMTP account password
$mail->From = $_REQUEST['email'];
$mail->FromName = $_REQUEST['name'];    
$mail->IsHTML(true);
$mail->Subject = "CV Upload";

$body = 'Name:'.$_REQUEST['name'].'<br /><br />Email:'.$_REQUEST['email'].'<br /><br />Email:'.$_REQUEST['website'].'<br /><br />Message:'.$_REQUEST['message'].'<br /><br />'; 

$mail->Body    = $body;
$mail->AltBody = $text_body;
$mail->AddAddress("danyob@rbh.co.uk");
$mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
if($mail->Send()){
    $success = true;        
}else{
    $success = false;
}//if($mail->Send()){}

由于某种原因,我收到的电子邮件中没有显示内容的正文。主题行和其他一切都有效。上面有什么问题吗?

1 个答案:

答案 0 :(得分:0)

$mail->Body之前检查$mail->Send()的结果,并使用启用HTML 邮件客户端检查邮件。注意$mail->AltBody填充了$text_body变量的内容,该变量未在您提供的代码中定义。它可能是空的,如果您使用纯文本邮件客户端,则根本不会看到任何文本。您可以尝试进行简单测试并尝试使用这些代码行来查看邮件客户端中可见的内容:

$mail->Body    = '<h1>HTML</h1>';
$mail->AltBody = 'Plain text';