当SMTPDebug = true时,PHPMailer只会发送电子邮件 [英] PHPMailer only sends email when SMTPDebug = true

查看:411
本文介绍了当SMTPDebug = true时,PHPMailer只会发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHPmailer。当$ mail-> SMTPDebug = true;但是当我删除该行时,它会静默地失败。我说默认失败,因为它没有给出任何错误,但电子邮件似乎没有交付。

  $ mail = new PHPMailer; 

$ mail-> SMTPDebug = true;
$ mail-> SMTPAuth = true;
$ mail-> CharSet ='utf-8';
$ mail-> SMTPSecure ='ssl';
$ mail-> Host ='smtp.gmail.com';
$ mail-> Port ='465';
$ mail-> Username ='xxxxx@gmail.com';
$ mail-> Password ='xxxxx';
$ mail-> Mailer ='smtp';
$ mail-> AddReplyTo(support@xxxxx.com','xxxxx支持');
$ mail-> From ='xxxxx@gmail.com';
$ mail-> FromName ='xxxxx应用程序';
$ mail-> Sender ='xxxxx应用程序';
$ mail-> Priority = 3;

//给我们
$ mail-> AddAddress('xxxxx@xxxxx.com','xxxxx xxxxx');
//申请人
$ mail-> AddAddress($ email,$ first_name。'。$ last_name);
$ mail-> IsHTML(true);

$ last_4_digits = substr($ card_num,-4);
//构建电子邮件内容

$ mail-> Subject ='Application From'。$ first_name。'。$ last_name;
$ mail-> Body = $ body_html;
$ mail-> AltBody = $ body_text;

如果(!$ mail-> send()){
echo'无法发送消息。
echo'Mailer Error:'。 $ mail-> ErrorInfo;
退出;
}


解决方案

通过设置

  $ mail-> SMTPDebug = false; 

而不是完全省略该行,每次都可以工作。


I'm using PHPmailer. It works when $mail->SMTPDebug = true; but when I remove that line, it silently fails. I say silently fails as it doesn't give any errors, and yet the email doesn't seem to be delivered.

        $mail = new PHPMailer;

        $mail->SMTPDebug = true;
        $mail->SMTPAuth = true;
        $mail->CharSet = 'utf-8';
        $mail->SMTPSecure = 'ssl';
        $mail->Host = 'smtp.gmail.com';
        $mail->Port = '465';
        $mail->Username = 'xxxxx@gmail.com';
        $mail->Password = 'xxxxx';
        $mail->Mailer = 'smtp';
        $mail->AddReplyTo('support@xxxxx.com', 'xxxxx Support');
        $mail->From = 'xxxxx@gmail.com';
        $mail->FromName = 'xxxxx Applications';
        $mail->Sender = 'xxxxx Applications';
        $mail->Priority = 3;

        //To us
        $mail->AddAddress('xxxxx@xxxxx.com', 'xxxxx xxxxx');
        //To Applicant
        $mail->AddAddress($email, $first_name.''.$last_name);
        $mail->IsHTML(true);

        $last_4_digits = substr($card_num, -4);
        //build email contents

        $mail->Subject = 'Application From '.$first_name.' '.$last_name;
        $mail->Body    = $body_html;
        $mail->AltBody = $body_text;

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

解决方案

By setting

        $mail->SMTPDebug = false;

instead of omitting the line completely, it works every time.

这篇关于当SMTPDebug = true时,PHPMailer只会发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆