2012-08-15 73 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

相关问题