PHPMailer仅在SMTPDebug = true时发送电子邮件

Chr*_*len 7 php debugging smtp 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 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;
        }
Run Code Online (Sandbox Code Playgroud)

Chr*_*len 14

通过设置

        $mail->SMTPDebug = false;
Run Code Online (Sandbox Code Playgroud)

而不是完全省略该行,它每次都有效.