2012-08-15 72 views
0

我想通過PHP Mailer使用Gmail SMTP服務器發送電子郵件。PHP郵件程序錯誤:郵件地址無效

我在我的機器上運行Zend Server Community Edition。

以下是我的代碼(編輯爲隱藏某些機密信息)。

require_once('phpmailer/class.phpmailer.php'); 

     $mail    = new PHPMailer(); 

     $body    = "test msg"; 

     $mail->IsSMTP(); 
     $mail->SMTPDebug = 2;      

     $mail->SMTPAuth = true;     
     $mail->SMTPSecure = "tls";     
     $mail->Host  = "smtp.gmail.com";  
     $mail->Port  = "587";      
     $mail->Username = "<valid-id>"; 
     $mail->Password = "<valid-password>";    

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

     $mail->AddReplyTo("[email protected]","Name"); 

     $mail->Subject = "subject"; 

     $mail->MsgHTML($body); 

     $address = "[email protected]"; 
     $mail->AddAddress($address, "halo:); 

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

儘管完全遵循PHP Mailer wiki頁面的示例,但我無法管理相應地發送電子郵件。

這是由函數產生的錯誤信息:

SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060) The following From address failed: [email protected] Mailer Error: The following From address failed: [email protected]

請告訴我關於這件事情。謝謝。

+0

smtp服務器可能會在smtp會話期間做一些檢查,例如與垃圾郵件作鬥爭。 'b.c' - 未知域,所以它不想從此域路由郵件 – CyberDem0n 2012-08-15 16:23:37

+0

我以前使用過有效域,並且它生成了相同的確切消息。 – rofans91 2012-08-15 16:27:54

+1

這不只是關於域名。 GMail對垃圾郵件的攻擊非常激烈。很可能,他們還會檢查整個電子郵件地址是否有效(它存在於域中)。嘗試從您自己的域名發送郵件並創建一個電子郵件帳戶,例如「noreplay @ domain.com」,以便其他郵件服務器可以看到「發件人」地址有效。如果您不希望它收到任何郵件,可以將此電子郵件的配額設置爲0MB。 – 2012-08-15 16:29:45

回答

2

你嘗試過:

$mail->SMTPAuth = true;     
$mail->SMTPSecure = "ssl";     
$mail->Host  = "smtp.gmail.com";  
$mail->Port  = "465"; 

我在你的代碼已經改變了我的電子郵件,我的SMTP用戶,我設置^^^,密碼和行:

$mail->AddAddress($address, "Mihai"); // you forgot a quote 

使用PHPMailer5.2.1和結果:

SMTP -> FROM SERVER:220 mx.google.com ESMTP gq2sm2073759bkc.13 
SMTP -> FROM SERVER: 250-mx.google.com at your service, [***.***.***.***] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH 250 ENHANCEDSTATUSCODES 
SMTP -> FROM SERVER:250 2.1.0 OK gq2sm2073759bkc.13 
SMTP -> FROM SERVER:250 2.1.5 OK gq2sm2073759bkc.13 
SMTP -> FROM SERVER:354 Go ahead gq2sm2073759bkc.13 
SMTP -> FROM SERVER:250 2.0.0 OK 1345113839 gq2sm2073759bkc.13 
Message sent! 

收到的郵件:

X-Mailer: PHPMailer 5.2.1 (http://code.google.com/a/apache-extras.org/p/phpmailer/) 
+0

是的,我也試過這個以及... – rofans91 2012-08-15 17:15:53

+0

你會得到什麼錯誤? – 2012-08-16 06:18:58

+0

同樣的錯誤信息... – rofans91 2012-08-16 10:38:00

相關問題