简体   繁体   English

PHPMailer无法在Debian下连接到Google SMTP服务器

[英]PHPMailer fails to connect to google smtp server under debian

I am trying to send an e-mail with PHPMailer. 我正在尝试使用PHPMailer发送电子邮件。 Here is my function to send an e-mail. 这是我发送电子邮件的功能。 It is working fine on localhost from an Ubuntu 14.04. 从Ubuntu 14.04在localhost上运行良好。

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';
}

Now I am trying to deploy it on a server. 现在,我正在尝试将其部署在服务器上。 The code is the same but it is not working anymore. 代码是相同的,但不再起作用。 The server is an apache2 running inside a debian 8.2. 该服务器是在debian 8.2中运行的apache2。 PHPMailer prints these lines. 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:

From the server the following commands are working fine : 在服务器上,以下命令运行正常:

dig smtp.gmail.com
ping smtp.gmail.com
telnet smtp.gmail.com

I tried to send an e-mail with telnet and it is also working. 我试图通过telnet发送电子邮件,但它也可以正常工作。 I followed this tutorial (sorry it's in french) What am I doing wrong? 我遵循了本教程 (很抱歉它是法文)我在做什么错?

Ok I found the answer here 好吧,我在这里找到了答案

It appears that my certificates were not matching. 看来我的证书不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM