我正在尝试让PHPMailer使用Google Apps SMTP服务器。我试过了:
有人可以为超时连接提供解决方案吗?
这是我的代码:
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;
}
答案 0 :(得分:0)
事实证明我是巧合的牺牲品。当我ssh'ed到我的服务器并telnet到Gmail,它是开放的 - 但是,由于openssl没有被注释,我怀疑这是它最初失败的原因。
然而,在尝试使其正常工作时,主机防火墙将Gmail列入黑名单。他们目前正在调查原因,但简短的回答是它是白名单并且正在运作。