【发布时间】:2014-02-11 04:50:23
【问题描述】:
我正在尝试让 PHPMailer 使用 Google Apps SMTP 服务器工作。我试过了:
- 在 php.ini 中取消注释 openssl
- 在端口 465 上远程登录 Google 的服务器(成功)
- 在端口 465 上远程登录我的网络服务器(成功)
- 从我的服务器远程登录 Google 的服务器(成功)
- 检查 DNS SPF/MX 记录(并清理到 IPv4)
- 端口 587 上的 tls
- webhost 确认他们允许出站 SMTP 流量
- 谷歌验证码的解锁技巧
- 阅读我在 StackOverflow 上可以找到的所有内容(解决方案涵盖上述内容)
有人可以提供连接超时的解决方案吗?
这是我的代码:
require_once ( 'class.phpmailer.php' ); // Add the path as appropriate
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server
$Mail->SMTPDebug = 1; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "ssl"; //Secure conection
$Mail->Port = 465; // set the SMTP port
$Mail->Username = 'account@googleappsaddress.com'; // SMTP account username
$Mail->Password = 'mypassword'; // SMTP account password
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Test Email Using Gmail';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = 'myemail@gmail.com';
$Mail->FromName = 'GMail Test';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->AddAddress( $to ); // To:
$Mail->isHTML( TRUE );
$Mail->Body = $body;
$Mail->AltBody = $MessageTEXT;
$Mail->Send();
$Mail->SmtpClose();
if(!$Mail->Send()) {
$error = 'Mail error: '.$Mail->ErrorInfo;
echo($error);
return false;
} else {
$error = 'Message sent!';
return true;
}
【问题讨论】:
-
您是否与虚拟主机确认他们允许端口 465? “smtp”是端口 25。端口 465 是“ssmtp” - smtp over ssl,可能会因为它是不同的协议而被阻止
-
@MarcB,是的。我也成功通过 465 访问另一台服务器。
-
检查服务器上没有运行应用级防火墙。如果命令行中的 telneting->google 可以工作,但网络服务器不能正常工作,则可能是某些东西阻止了网络服务器以这种方式读取。
-
我可以从我的网络服务器(通过 ssh)telnet 到 gmail 的 SMTP 服务器的 465 端口
标签: php smtp phpmailer google-apps