PHPMailer Mailer错误:消息体空 [英] PHPMailer Mailer Error: Message body empty
问题描述
我所做的一切都是上传整个PHPMailer_5.2.2文件夹,配置如下页面代码你看到,我不断得到邮件错误:邮件正文空
,但我可以清楚地看到content.html文件中有html并且不是空的。这是我从PHPMailer使用的示例文件PHPMailer_5.2.2 / examples / test_smtp_gmail_basic.php
我尝试使用Outlook for Gmail中的设置,我知道我的用户名和密码,SMTP端口是587,它设置为TLS,我尝试用以下代码中的TLS替换SSL,我仍然收到相同的错误。
我还尝试了以下代码:已经建议:
更改了这个:
$ MAIL-> MsgHTML($体);
到这个
code> $ mail-> body = $ body;
我仍然有同样的错误,还有其他需要配置的东西吗?这是我第一次使用PHPMailer,我可以让标准的php邮件正常工作,但是我想尝试这个是因为我要发邮件的页面有很多html,我不希望通过所有的HTML并输入字符转义,所以有人推荐使用这个。
<?php
// error_reporting E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America / Toronto');
require_once('../ class.phpmailer.php');
//include(\"class.smtp.php); //可选,如果尚未加载,则从class.phpmailer.php中调用
$ mail = new PHPMailer();
$ body = file_get_contents('contents.html');
$ body = preg_replace('/ [\] /','',$ body);
$ mail-> IsSMTP(); //告诉班级使用SMTP
$ mail-> Host =smtp.gmail.com; // SMTP server
$ mail-> SMTPDebug = 1; //启用SMTP调试信息(用于测试)
// 1 =错误和消息
// 2 =仅消息
$ mail-> SMTPAuth = true; //启用SMTP验证
$ mail-> SMTPSecure =ssl; //将前缀设置为服务器
$ mail-> Host =smtp.gmail.com; //将GMAIL设置为SMTP服务器
$ mail-> Port = 587; //设置GMAIL服务器的SMTP端口
$ mail-> Username =xxx@gmail.com; // GMAIL username
$ mail-> Password =xxx; // GMAIL password
$ mail-> SetFrom('xxx@gmail.com','First Last');
$ mail-> AddReplyTo(xxx,First Last);
$ mail-> Subject =PHPMailer通过smtp(Gmail)测试主题,基本;
$ mail-> AltBody =要查看消息,请使用HTML兼容的电子邮件查看器! //可选,注释和测试
$ mail-> MsgHTML($ body);
$ address =xxx.net;
$ mail-> AddAddress($ address,John Doe);
//$mail->AddAttachment(\"images/phpmailer.gif); // attachment
//$mail->AddAttachment(\"images/phpmailer_mini.gif); //附件
if(!$ mail-> Send()){
echoMailer Error:。 $ MAIL-> ERRORINFO;
} else {
echoMessage sent!;
}
?>
我有同样的问题,我解决了只是改变:
This:
$ mail-> body ='Hello这是我的消息。
进入:
$ mail-> Body ='你好,这是我的消息。
body
into 身体
有什么错误!
I'm trying to get the basic example working for PHPMailer.
All I done was upload the whole PHPMailer_5.2.2 folder, configured the page below as per the code you see and I keep getting Mailer Error: Message body empty
, but I can clearly see the contents.html file has html in it and isn't empty. This is the example file I'm using from the PHPMailer PHPMailer_5.2.2/examples/test_smtp_gmail_basic.php
I tried using the settings I have in Outlook for Gmail that works, I know my username and password, the SMTP port is 587 and it's set to TLS, I tried replacing SSL with TLS in the code below, I still get same error.
I also tried the following code, which has been suggested:
changed this:
$mail->MsgHTML($body);
to this
$mail->body = $body;
I still got same error, is there something else I need to configure? It's my first time using PHPMailer, I can get the standard php mail working, but I want to try this because the page I'm going to be emailing has lots of html and I don't want to have to go through all the html and enter character escapes so someone recommending using this.
<?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');
$body = preg_replace('/[\]/','',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.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 = 587; // set the SMTP port for the GMAIL server
$mail->Username = "xxx@gmail.com"; // GMAIL username
$mail->Password = "xxx"; // GMAIL password
$mail->SetFrom('xxx@gmail.com', 'First Last');
$mail->AddReplyTo("xxx","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "xxx.net";
$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!";
}
?>
I had the same problem and I solved just changing:
This:
$mail->body = 'Hello, this is my message.';
Into this:
$mail->Body = 'Hello, this is my message.';
body
into Body
what a little mistake!
这篇关于PHPMailer Mailer错误:消息体空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!