PHPMailer通过ajax发送邮件

$.ajax({
    type: 'POST',
    url: 'sendmail.php',
    dataType: "json",
    data: formData,
    success: function(response) {
        console.log(response.success);
        if (response.success) {
            $('.form-sent').css({display: 'none'});
            $('.sent-sucess').css({display: 'block'});
        } else {
            alert(response.message);
        }
    },
    error: function(xhr, status, error){
        console.log(xhr);
        console.log(error);
    }
});

PHP Code

$mail = new PHPMailer(true);
try {
    $mail->SMTPDebug = 2;
    $mail->isSMTP();                            // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';             // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                     // Enable SMTP authentication
    $mail->Username = 'xxxx@gmail.com';          // SMTP username
    $mail->Password = 'xxx'; // SMTP password
    $mail->SMTPSecure = 'tls';                  // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                          // TCP port to connect to

    $mail->setFrom('xxx@gmail.com', 'Support System');
    $mail->addReplyTo($_POST['ema‌​il‌​']);
    $mail->addAddress('xxx@yahoo.com');   // Add a recipient

    $mail->isHTML(true);  // Set email format to HTML

    $bodyContent = '<h4>Customer: ' . $_POST['ema‌​il‌​'] . '</h4><p>' . $_POST['message'] . '</p>';

    $mail->Subject = $_POST['subject'];
    $mail->Body    = $bodyContent;

    $mail->send();
        // echo json_encode(['success'=>true]);
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
  • When I send mail, mail is send success but ajax return error not success.
  • Response is:

2018-06-16 18:12:44 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP e5-v6sm12554738pgs.59 - gsmtp
2018-06-16 18:12:44 CLIENT -> SERVER: EHLO xxx.test
2018-06-16 18:12:44 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2405:4800:548f:2d02:19f9:f439:c390:803e]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2018-06-16 18:12:44 CLIENT -> SERVER: STARTTLS
2018-06-16 18:12:45 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2018-06-16 18:12:45 CLIENT -> SERVER: EHLO xxx.test
2018-06-16 18:12:45 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2405:4800:548f:2d02:19f9:f439:c390:803e]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2018-06-16 18:12:45 CLIENT -> SERVER: AUTH LOGIN
2018-06-16 18:12:45 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2018-06-16 18:12:45 CLIENT -> SERVER: <credentials hidden>
2018-06-16 18:12:45 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2018-06-16 18:12:45 CLIENT -> SERVER: <credentials hidden>
2018-06-16 18:12:46 SERVER -> CLIENT: 235 2.7.0 Accepted
2018-06-16 18:12:46 CLIENT -> SERVER: MAIL FROM:<xxx@gmail.com>
2018-06-16 18:12:46 SERVER -> CLIENT: 250 2.1.0 OK e5-v6sm12554738pgs.59 - gsmtp
2018-06-16 18:12:46 CLIENT -> SERVER: RCPT TO:<k.abel1986@yahoo.com>
2018-06-16 18:12:46 SERVER -> CLIENT: 250 2.1.5 OK e5-v6sm12554738pgs.59 - gsmtp
2018-06-16 18:12:46 CLIENT -> SERVER: DATA
2018-06-16 18:12:47 SERVER -> CLIENT: 354 Go ahead e5-v6sm12554738pgs.59 - gsmtp
2018-06-16 18:12:47 CLIENT -> SERVER: Date: Sat, 16 Jun 2018 18:12:43 +0000
2018-06-16 18:12:47 CLIENT -> SERVER: To:xxx@yahoo.com
2018-06-16 18:12:47 CLIENT -> SERVER: From: Support System <xxx@gmail.com>
2018-06-16 18:12:47 CLIENT -> SERVER: Reply-To: emailtest1@gmail.com
2018-06-16 18:12:47 CLIENT -> SERVER: Subject: test send mail
2018-06-16 18:12:47 CLIENT -> SERVER: Message-ID: <Z8XqVgxJEztW9kdU3hz42VsB79duQMQjsq7bLQhx8eQ@xxx.test>
2018-06-16 18:12:47 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.5 (https://github.com/PHPMailer/PHPMailer)
2018-06-16 18:12:47 CLIENT -> SERVER: MIME-Version: 1.0
2018-06-16 18:12:47 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2018-06-16 18:12:47 CLIENT -> SERVER:
2018-06-16 18:12:47 CLIENT -> SERVER: <h4>Customer: emailtest1@gmail.com</h4><p>test send mail</p>
2018-06-16 18:12:47 CLIENT -> SERVER:
2018-06-16 18:12:47 CLIENT -> SERVER: .
2018-06-16 18:12:48 SERVER -> CLIENT: 250 2.0.0 OK 1529172767 e5-v6sm12554738pgs.59 - gsmtp
2018-06-16 18:12:48 CLIENT -> SERVER: QUIT
2018-06-16 18:12:48 SERVER -> CLIENT: 221 2.0.0 closing connection e5-v6sm12554738pgs.59 - gsmtp

It's something wrong, please help me.