2013-11-02 43 views
0

我使用Google的郵件服務器發送郵件。對於電子郵件發送,我正在使用PHPMailer。這是我使用我的example.com/contactus網站上的片段:使用Google的郵件服務器向PHPMailer發送郵件失敗

 $mail    = new PHPMailer(); 
     $mail->IsSMTP(); 
     $mail->SMTPDebug = 2; 
     $mail->SMTPAuth = true;     // enable SMTP authentication 
     $mail-> Host  = 'ssl://smtp.gmail.com'; 
     $mail->Port  = 465;     // set the SMTP port for the GMAIL server 

     $mail->Username = "[email protected]"; // GMAIL username 
     $mail->Password = "myprivatepassword";   // GMAIL password 
     $mail->SetFrom($form_email, $form_username); 
     $mail->AddAddress("[email protected]", "Example Support"); 
     $mail->AddReplyTo($form_email, $form_username); 

     $mail->Subject = $subject2; 
     $mail->Body  = $message2;   

     $mail->CharSet  = 'UTF-8'; 
     $mail->Encoding = '8bit'; 
     $mail->ContentType = 'text/html; charset=utf-8\r\n'; 
     $mail->WordWrap = 70; 

     if(!$mail->Send()) { 
      echo "Mailer Error: " . $mail->ErrorInfo; 
     } else { 
      echo "Message sent!"; 
     } 

代碼發送電子郵件給我([email protected]),其標題是:

from: user1 <[email protected]> 
reply-to: user1 <[email protected]> (this is $form_email) 
to: Example Support <[email protected]> 

問題當我使用不同的地址進行用戶名和密碼驗證時,不會發送消息。錯誤是:

2013-11-02 14:46:18 SERVER -> CLIENT: 220 mx.google.com ESMTP u46sm21298429eep.17 - gsmtp 2013-11-02 14:46:18 CLIENT -> SERVER: EHLO www.example.com 2013-11-02 14:46:18 SERVER -> CLIENT: 250-mx.google.com at your service, [2a01:4f8:140:71ed::2] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN 250-ENHANCEDSTATUSCODES 250 CHUNKING 2013-11-02 14:46:18 CLIENT -> SERVER: AUTH LOGIN 2013-11-02 14:46:18 SERVER -> CLIENT: 334 VXNlcm5hbWU6 2013-11-02 14:46:18 CLIENT -> SERVER: ZGFwcHdhbGxAZ21haWwuY29t 2013-11-02 14:46:18 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 2013-11-02 14:46:18 CLIENT -> SERVER: U3BvdGxpZ2h0OA== 2013-11-02 14:46:18 SERVER -> CLIENT: 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at https://support.google.com/mail/bin/answer.py?answer=787 534 5.7.14 54 u46sm21298429eep.17 - gsmtp 2013-11-02 14:46:18 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at https://support.google.com/mail/bin/answer.py?answer=787 534 5.7.14 54 u46sm21298429eep.17 - gsmtp 2013-11-02 14:46:18 CLIENT -> SERVER: QUIT 2013-11-02 14:46:18 SERVER -> CLIENT: 221 2.0.0 closing connection u46sm21298429eep.17 - gsmtp SMTP connect() failed. Mailer Error: SMTP connect() failed. 

我不知道爲什麼它,我每天都在使用,爲什麼是不是與我有其他的Gmail帳戶我的私人Gmail帳戶工作。它應該是一個設置在Gmail可能,但哪一個?

回答

0

嗯,我找不到它爲什麼不工作。最後,我更改爲SendGrid。他們提供了一個簡單的API,我使用基本技能在一個小時內設置了電子郵件發送。