【发布时间】:2016-06-02 20:57:12
【问题描述】:
我尝试使用 PHPMailer 并收到消息正文为空或屏幕为空白且未打印消息已发送的错误。我的文件夹结构是所有东西都在同一个文件夹中,以防万一有人需要知道。我也关注了这篇文章,但似乎没有用。 PHPMailer Mailer Error: Message body empty
<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
echo $body;
//$body = preg_replace('/[\]/','',$body);
//$body = "To view the message, please use an HTML compatible email viewer!";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "no-reply@yourdomain.com"; // GMAIL username
$mail->Password = "xxx"; // GMAIL password
$mail->SetFrom('no-reply@yourdomain.com', 'First Last');
//$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->IsHTML(true);
$mail ->MsgHTML($body);
$mail->Body = $body;
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
//$mail->IsHTML(true);
$address = "someemail@yourdomain.com";
$mail->AddAddress($address, "John Doe");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
内容.html:
<body style="margin: 10px;">
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
<br>
<br>
This is a test of PHPMailer.<br>
<br>
This particular example uses <strong>HTML</strong>, with a <div> tag and inline<br>
styles.<br>
<br>
Also note the use of the PHPMailer logo above with no specific code to handle
including it.<br />
Included are two attachments:<br />
phpmailer.gif is an attachment and used inline as a graphic (above)<br />
phpmailer_mini.gif is an attachment<br />
<br />
PHPMailer:<br />
Author: Andy Prevost (codeworxtech@users.sourceforge.net)<br />
Author: Marcus Bointon (coolbru@users.sourceforge.net)<br />
</div>
</body>
我已将回显放入代码中以进行故障排除,以查看它是否正在获取数据。我认为这确实与用于邮件托管的 Gmail 有关。但它是他们使用的。提前感谢您提供的任何方向。
克里斯
【问题讨论】:
-
contents.html中有什么内容? -
抱歉刚刚添加到帖子中。
-
是
contents.html还是Contents.html?那可能是你的问题... -
它的小写字母,就像现在一样,除了
contents.html的回声之外,我只是得到了空白屏幕,我认为这可能是一个 gmail 问题,但不确定。 -
您没有收到“Mailer Error:”并出现一些错误?