phpmailer suddenly got very slow

时间:2016-10-20 19:26:34

标签: phpmailer

I use phpmailer for sending emails and while it worked flawlesly until now, I noticed that sending emails got very very slow, around 2-3 minutes. The mails are sent, but the waiting time is killing me.

My code is:

   protected function SendPHPMailerMail($from = null, $name = null, $subject = null, $message = null)
{

    require_once ('phpmailer/PHPMailerAutoload.php');


    if($from && $name && $subject && $message)
    {
        $mail = new PHPMailer;
        //$mail->SMTPDebug  = 3;
        $mail->Debugoutput = 'html';            
        $mail->isSMTP();

        $mail->Host = 'smtp.gmail.com';      // sets GMAIL as the SMTP server
        $mail->SMTPAuth   = true;                  // enable SMTP authentication
        $mail->SMTPSecure = 'tls';                 // sets the prefix to the servier
        $mail->Port       = 587;                   // set the SMTP port for the GMAIL server
        $mail->Username   = 'x@gmail.com';  // GMAIL username
        $mail->Password   = 'pass';            // GMAIL password
        $mail->AddReplyTo($from, $name);
        $mail->AddAddress('x@gmail.com', 'Me');
        $mail->SetFrom('x@gmail.com', 'Me');
        $mail->Subject = $subject;
        $mail->Body    = $message;
        $mail->Send();
    }
}

I tried debugging, there are no errors. I read in a different question thread that using gethostbyname('smtp.gmail.com'); worked for some, but not for me. I haven't changed anything on the server and this popped out of nowhere. Not sure what to do.

Thanks!

edit: used SMTPdebug=2 and this is what I get

SERVER -> CLIENT: 220 smtp.gmail.com ESMTP 90sm16517084otw.3 - gsmtp
CLIENT -> SERVER: EHLO www.host.com
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [107.182.234.254]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
CLIENT -> SERVER: EHLO www.host.com
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [107.182.234.254]250-   SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334 VXNlcm5hbWU6
CLIENT -> SERVER: Y29udGFjdEBmaWxlY2x1c3Rlci5jb20=
SERVER -> CLIENT: 334 UGFzc3dvcmQ6
CLIENT -> SERVER: Z2l6bW8uMTIzcXdl
SERVER -> CLIENT: 235 2.7.0 Accepted
CLIENT -> SERVER: MAIL FROM:<x@gmail.com>
SERVER -> CLIENT: 250 2.1.0 OK 90sm16517084otw.3 - gsmtp
CLIENT -> SERVER: RCPT TO:<x@gmail.com>
SERVER -> CLIENT: 250 2.1.5 OK 90sm16517084otw.3 - gsmtp
CLIENT -> SERVER: DATA
SERVER -> CLIENT: 354 Go ahead 90sm16517084otw.3 - gsmtp
CLIENT -> SERVER: Date: Thu, 20 Oct 2016 20:44:01 +0000
CLIENT -> SERVER: To: Me <x@gmail.com>
CLIENT -> SERVER: From: Me <x@gmail.com>
CLIENT -> SERVER: Reply-To: X <sender@gmail.com>
CLIENT -> SERVER: Subject: Partnership and business development
CLIENT -> SERVER: Message-ID: <6dae364927ad751cc524f07a77f5eea1@www.host.com>
CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.16 (https://github.com/PHPMailer/PHPMailer)
CLIENT -> SERVER: MIME-Version: 1.0
CLIENT -> SERVER: Content-Type: text/plain; charset=iso-8859-1
CLIENT -> SERVER: 
CLIENT -> SERVER: message
CLIENT -> SERVER: 
CLIENT -> SERVER: .
SERVER -> CLIENT: 250 2.0.0 OK 1476996370 90sm16517084otw.3 - gsmtp
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 closing connection 90sm16517084otw.3 - gsmtp

I replaced the actual values of the site and emails.

0 个答案:

没有答案