2017-05-15 56 views
-1

我真的希望你們中的一個人可以幫助我。我一直用這個拉着我的頭髮約2個小時。我的客戶電子郵件服務器上的其中一個帳戶遭到入侵,Google開始阻止我們發送電子郵件的企圖。所以我試圖從基本的PHP郵件命令切換到PHPMailer並通過Google的SMTP服務器發送。此客戶使用Google專業版的所有帳戶。PHP郵件與PHPMailer通過谷歌SMTP

我使用了以下內容:

$mail    = new PHPMailer(); 

    $mail->isSMTP(); // telling the class to use SMTP 
    $mail->SMTPDebug = 1;      // enables SMTP debug information (for testing) 
    $mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
    $mail->SMTPSecure = "tls";     // sets the prefix to the server 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->Port  = 587;     // set the SMTP port for the GMAIL server 
    $mail->Username = "[email protected]"; // GMAIL username 
    $mail->Password = "*********";   // GMAIL password 

    $mail->SetFrom('[email protected]', 'Jimmy'); 

    $mail->Subject = $this->subject; 

    $body    = $this->message; 
    //$body    = eregi_replace("[\]",'',$body);   

    $mail->MsgHTML($body); 

    $mail->AddAddress($this->to, 'bob'); 

    if(!$mail->Send()) { 
     error_log("Mailer Error: " . $mail->ErrorInfo); 
     echo '[br /]Fail'; 
    } else { 
     error_log("Message sent!"); 
     echo '[br /]Pass'; 
    } 

我知道證書是正確的,因爲我可以與他們登錄。我已經做了所有種類的東西這個腳本,它正試圖使用​​的帳戶發送:從TLS

  1. 更改到SSL
  2. '疏通Captcha驗證碼的帳戶
  3. 禁用2因素身份驗證(它已經關閉)
  4. 啓用「不夠安全的應用」

我不知道還能做什麼。這是我不斷收到的錯誤:

2017-05-15 03:12:30 CLIENT -> SERVER: EHLO americanbeautytools.com 
2017-05-15 03:12:30 CLIENT -> SERVER: STARTTLS 
2017-05-15 03:12:30 CLIENT -> SERVER: EHLO americanbeautytools.com 
2017-05-15 03:12:30 CLIENT -> SERVER: AUTH LOGIN 
2017-05-15 03:12:30 CLIENT -> SERVER: xxx= 
2017-05-15 03:12:30 CLIENT -> SERVER: xxx= 
2017-05-15 03:12:32 SMTP ERROR: Password command failed: 535 Incorrect authentication data 
2017-05-15 03:12:32 SMTP Error: Could not authenticate. 
2017-05-15 03:12:32 CLIENT -> SERVER: QUIT 
2017-05-15 03:12:32 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 

有關密碼命令失敗的部分是我沒有得到的部分。當我用這個電子郵件帳戶登錄時,這怎麼會是錯誤的?

我已經看了大約15個關於這個主題的話題,而他們的建議都沒有解決我的問題。這是一個谷歌專家帳戶,我的客戶通過谷歌運行,所以它不會是'免費'限制的事情。

+0

差不多*你發現,*和*排除指南這些線程中的每一個*,會告訴你**設置'SMTPDebug = 2' **。當它設置爲1時,你不會看到服務器說的任何東西。 – Synchro

+0

如果您將代碼基於PHPMailer提供的gmail示例,那麼首先您就不會陷入這個難題。 – Synchro

+0

@Synchro - 我確實已將它設置爲2,並且沒有提供任何其他有用的信息。你的第二條評論沒有幫助。我有我的代碼鏡像PHPMailer的例子,它的許多變化和錯誤仍然存​​在。我完成了這個設置。我正在切換到外部郵件提供商。 –

回答

-1

使用G套件帳戶或sendgrid帳戶進行測試。我已經使用我的gmail憑證進行了測試。

$mail = new PHPMailer; 
$mail->isSMTP(); 
$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 465; 
$mail->SMTPSecure = 'ssl'; 
$mail->SMTPAuth = true; 
$mail->Username = '[email protected]'; // SMTP username 
$mail->Password = '123456789'; // SMTP password 
$mail->setFrom('[email protected], 'Krishna'); 
$mail->addAddress($to_addr, 'Test');  // Add a recipient 
$mail->Subject = $subject; 
$mail->isHTML(true); 
$mail->Body = $message; 
+0

請不要在沒有解釋它如何回答問題的情況下發布代碼。 – Synchro

+0

@Synchro請不要給任何建議,如果你沒有任何答案.. –

+0

這是不可能回答這個問題,因爲海報還沒有提供足夠的信息繼續下去。當這個問題得到解決後,我可以回答。同時,與你不同,我不會發布猜測作爲答案。 – Synchro

-1
<?php 

     require ('../PHPMailerAutoload.php'); //add PhPMailerAutoload.php file Path 
     $mail = new PHPMailer(); // create Object 

     $name=$_POST['Name']; //get name from post method 
     $to=$_POST['email']; //get email from post method 
     $message = $_POST['message']; //get msg from post method 

     $mail->isSMTP(); // telling the class to use SMTP 
     $mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 
     $mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
     $mail->SMTPSecure = "ssl";     // sets the prefix to the server 
     $mail->SMTPAuth = true;     // enable SMTP authentication 
     $mail->Port  = 465;     // set the SMTP port for the GMAIL server 
     $mail->Username = "[email protected]"; // GMAIL username 
     $mail->Password = "*********";   // GMAIL password 
     $mail->SetFrom('[email protected]', 'Jimmy'); //Set who the message is to be sent from 
     $mail->Subject = "Email from Mailer"; // $this->subject; 
     $mail->Body = "test Email msg";  // $this->message; 
     $mail->isHTML(true); 
     $mail->MsgHTML($message); 
     $mail->addAddress($to,$name); 
     $mail->WordWrap = 70; 

     if(!$mail->Send()) { 
      echo 'Message could not be sent.'.'<br>'; 
      echo "Mailer Error: " . $mail->ErrorInfo); 
      exit; 

     } else { 
      echo 'Message sent.'.'<br>'; 
      exit; 
     } 


    ?> 
+0

請不要發佈未註釋的,過時的代碼。 – Synchro

相關問題