我想通過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]
請告訴我關於這件事情。謝謝。
smtp服務器可能會在smtp會話期間做一些檢查,例如與垃圾郵件作鬥爭。 'b.c' - 未知域,所以它不想從此域路由郵件 – CyberDem0n 2012-08-15 16:23:37
我以前使用過有效域,並且它生成了相同的確切消息。 – rofans91 2012-08-15 16:27:54
這不只是關於域名。 GMail對垃圾郵件的攻擊非常激烈。很可能,他們還會檢查整個電子郵件地址是否有效(它存在於域中)。嘗試從您自己的域名發送郵件並創建一個電子郵件帳戶,例如「noreplay @ domain.com」,以便其他郵件服務器可以看到「發件人」地址有效。如果您不希望它收到任何郵件,可以將此電子郵件的配額設置爲0MB。 – 2012-08-15 16:29:45