PHPMailer无法连接到debian下的google smtp服务器
我正在尝试用PHPMailer发送电子邮件。这是我发送电子邮件的功能。它在Ubuntu 14.04的本地主机上运行良好PHPMailer无法连接到debian下的google smtp服务器,php,smtp,gmail,debian,phpmailer,Php,Smtp,Gmail,Debian,Phpmailer,我正在尝试用PHPMailer发送电子邮件。这是我发送电子邮件的功能。它在Ubuntu 14.04的本地主机上运行良好 function smtpMail($to, $from, $from_name, $subject, $body) { $mail = new PHPMailer; $mail->IsSMTP(); // tells PHPMailer to use SMTP $mail->
function smtpMail($to, $from, $from_name, $subject, $body) {
$mail = new PHPMailer;
$mail->IsSMTP(); // tells PHPMailer to use SMTP
$mail->Host = gethostbyname('smtp.gmail.com'); // sets the hostname of the mail server
$mail->Port = 587; // sets the SMTP port number
$mail->SMTPSecure = 'tls'; // sets the encryption system to use
$mail->SMTPDebug = 2; // debug level
$mail->SMTPAuth = true; // whether to use SMTP authentication
$mail->Username = 'jdoe@company.org'; // username to use for SMTP authentication
$mail->Password = 'qwerty'; // password to use for SMTP authentication
$mail->CharSet = 'UTF-8';
$mail->IsHTML(true);
$mail->setFrom($from, $from_name); // sets who the message is to be sent from
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if (!$mail->Send ()) {
return 'Mail error: ' . $mail->ErrorInfo;
//return 'KO';
}
return 'OK';
}
现在我正在尝试将其部署到服务器上。代码是一样的,但它不再工作了。服务器是运行在debian 8.2中的apache2。
PHPMailer打印这些行
2015-12-09 13:35:41 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2015-12-09 13:35:41 SMTP Error: Could not connect to SMTP host.
2015-12-09 13:35:41 CLIENT -> SERVER: QUIT
2015-12-09 13:35:41 SERVER -> CLIENT:
2015-12-09 13:35:41 SMTP ERROR: QUIT command failed:
在服务器上,以下命令工作正常:
dig smtp.gmail.com
ping smtp.gmail.com
telnet smtp.gmail.com
我试着用telnet发送一封电子邮件,它也在工作。我听了这个(对不起,是法语)
我做错了什么?好的,我找到了答案
我的证书似乎不匹配。。请尝试SMTPDebug=4
,看看它是否告诉您任何新信息。看起来您可能缺少SSL扩展名或CA文件过时,或者ISP正在重定向您,导致验证失败。