PHP#u Mailer赢得';t打印调试信息

PHP#u Mailer赢得';t打印调试信息,php,smtp,phpmailer,Php,Smtp,Phpmailer,我正在尝试使用PHP Mailer SMTP发送电子邮件,但是,即使在打开SMTPDebug之后,也没有显示任何内容,当$Mail->send()时,我得到的结果是false 这就是我所拥有的 $Mail = new PHPMailer(); $Mail->SMTPDebug = 2; $Mail->IsSMTP(); $Mail->SMTPAuth = true; $Mail->Host = "smtp.gmail.com"; $Mail->

我正在尝试使用PHP Mailer SMTP发送电子邮件,但是,即使在打开SMTPDebug之后,也没有显示任何内容,当$Mail->send()时,我得到的结果是false

这就是我所拥有的

$Mail = new PHPMailer();          
$Mail->SMTPDebug = 2;
$Mail->IsSMTP(); 
$Mail->SMTPAuth = true;
$Mail->Host = "smtp.gmail.com";
$Mail->SMTPSecure = "tls"; 
$Mail->Port = 587; 
$Mail->Priority = 1;
$Mail->CharSet = 'UTF-8';
$Mail->Username = 'xxxxx@yyyyyyy.com';
$Mail->Password = 'xxxxxxxxxxxxxxxxxx';
$Mail->Encoding = '8bit';
$Mail->Subject = $subject;
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = "xxxxxxx@yyyyyyyyy.com";
$Mail->FromName = "XXXXXXXXXXXXXXXXX";
$Mail->AddReplyTo($replyToEmail, $replyToName);
$Mail->WordWrap = 998; // RFC 2822 Compliant for Max 998 characters per line
$Mail->IsHTML(true);    
$Mail->body=$tpl;
$Mail->AddAddress($email);
$Mail->Send(); <------ false and doesn't print out why
$Mail=new PHPMailer();
$Mail->SMTPDebug=2;
$Mail->IsSMTP();
$Mail->SMTPAuth=true;
$Mail->Host=“smtp.gmail.com”;
$Mail->SMTPSecure=“tls”;
$Mail->Port=587;
$Mail->Priority=1;
$Mail->CharSet='UTF-8';
$Mail->Username=xxxxx@yyyyyyy.com';
$Mail->Password='xxxxxxxxxxxxxxxx';
$Mail->Encoding='8bit';
$Mail->Subject=$Subject;
$Mail->ContentType='text/html;字符集=utf-8\r\n';
$Mail->From=”xxxxxxx@yyyyyyyyy.com";
$Mail->FromName=“xxxxxxxxxxxxxxxx”;
$Mail->AddReplyTo($replyToEmail,$replyToName);
$Mail->WordWrap=998;//符合RFC 2822,每行最多998个字符
$Mail->IsHTML(true);
$Mail->body=$tpl;
$Mail->AddAddress($email);
$Mail->Send() 使用试捕

try {
$Mail = new PHPMailer(true);   //<-- edit add true here        
$Mail->SMTPDebug = 2;
$Mail->IsSMTP(); 
$Mail->SMTPAuth = true;
$Mail->Host = "smtp.gmail.com";
$Mail->SMTPSecure = "tls"; 
$Mail->Port = 587; 
$Mail->Priority = 1; //Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Username = 'xxxxx@yyyyyyy.com';
$Mail->Password = 'xxxxxxxxxxxxxxxxxx';
$Mail->Encoding = '8bit';
$Mail->Subject = $subject;
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = "xxxxxxx@yyyyyyyyy.com";
$Mail->FromName = "XXXXXXXXXXXXXXXXX";
$Mail->AddReplyTo($replyToEmail, $replyToName);
$Mail->WordWrap = 998; // RFC 2822 Compliant for Max 998 characters per line
$Mail->IsHTML(true);    
$Mail->body=$tpl;
$Mail->AddAddress($email);
$Mail->Send(); //<------ false and doesn't print out why
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Error from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Other error messages
}
试试看{
$Mail=new PHPMailer(true);//SMTPDebug=2;
$Mail->IsSMTP();
$Mail->SMTPAuth=true;
$Mail->Host=“smtp.gmail.com”;
$Mail->SMTPSecure=“tls”;
$Mail->Port=587;
$Mail->Priority=1;//正常,5=低)
$Mail->CharSet='UTF-8';
$Mail->Username=xxxxx@yyyyyyy.com';
$Mail->Password='xxxxxxxxxxxxxxxx';
$Mail->Encoding='8bit';
$Mail->Subject=$Subject;
$Mail->ContentType='text/html;charset=utf-8\r\n';
$Mail->From=”xxxxxxx@yyyyyyyyy.com";
$Mail->FromName=“xxxxxxxxxxxxxxxx”;
$Mail->AddReplyTo($replyToEmail,$replyToName);
$Mail->WordWrap=998;//符合RFC 2822,每行最多998个字符
$Mail->IsHTML(true);
$Mail->body=$tpl;
$Mail->AddAddress($email);

$Mail->Send();//假设您使用的是未经修改的PHPMailer版本,则您的某些属性/方法使用的大小写不正确。从PHPMailer简单示例中,可在以下网址获得:

需要'phpmailerautoad.php';
$mail=新的PHPMailer;
//$mail->SMTPDebug=3;//启用详细调试输出
$mail->isSMTP();//设置邮件程序以使用SMTP
$mail->Host='smtp1.example.com;smtp2.example.com';//指定主SMTP服务器和备份SMTP服务器
$mail->SMTPAuth=true;//启用SMTP身份验证
$mail->Username=user@example.com“;//SMTP用户名
$mail->Password='secret';//SMTP密码
$mail->SMTPSecure='tls';//启用tls加密,也接受'ssl'
$mail->Port=587;//要连接的TCP端口
$mail->setFrom('from@example.com","梅勒",;
$mail->addAddress('joe@example.net“,”Joe User');//添加收件人
$mail->addAddress('ellen@example.com');//名称是可选的
$mail->addReplyTo('info@example.com","信息",;
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->addAttachment('/var/tmp/file.tar.gz');//添加附件
$mail->addAttachment('/tmp/image.jpg','new.jpg');//可选名称
$mail->isHTML(true);//将电子邮件格式设置为HTML
$mail->Subject='主题在这里';
$mail->Body='这是以粗体显示的HTML邮件正文!';
$mail->AltBody='这是非HTML邮件客户端的纯文本正文';
如果(!$mail->send()){
echo“无法发送消息”;
回显“邮件错误:”。$mail->ErrorInfo;
}否则{
回音“消息已发送”;
}

看看PHP的错误报告是否会产生任何结果
$Mail->Priority=1;Normal,5=low)
如果这是你的真实代码,你应该会因此而得到一个解析错误,并且有一些原因。这些注释是否已经被阅读过?这是我在发布问题时删除的注释,我会按字面意思理解发布的代码。如果有什么东西看起来不对劲,然后我评论。你没有使用我建议你做的吗?它没有显示任何错误,因为你没有像所有示例一样检查
send()
的返回值或查看
ErrorInfo
。除非被要求,否则库不应该生成虚假输出。如果你连接有任何问题(在任何SMTP会话之前)然后SMTPDebug=2将不显示任何内容-将连接级别信息增加到3,这将告诉您所有这些以及更多信息。Fred也说了!谢谢,但不会引发异常phpmailer不会引发异常,除非您告诉它-将
true
传递给构造函数。true我没有C/Cwell@Synchro谢谢,这帮我找到了问题所在其他人似乎更喜欢抱怨而不是帮助谢谢你Daniell,当你刚到这里时,你做了正确的事情:)只是想帮助别人。多年来,我一直在埋头工作,似乎早就应该尝试帮助别人了。我想,不知怎的,案件敏感性并不是问题所在。
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}