PHPmailer无法在服务器上运行,但可以在本地主机上运行

时间:2019-07-17 04:28:21

标签: php phpmailer

我在这样的codeigniter中配置了smtp mailer,

$config['useragent']        = 'PHPMailer';              // Mail engine switcher: 'CodeIgniter' or 'PHPMailer'
$config['protocol']         = 'smtp';                   // 'mail', 'sendmail', or 'smtp'
$config['mailpath']         = '/usr/sbin/sendmail';
$config['smtp_host']        = 'tls://smtp.gmail.com:587';
$config['smtp_user']        = 'xxxx@gmail.com';
$config['smtp_pass']        = 'xxxxxxxx';
$config['smtp_port']        = 587;
$config['smtp_timeout']     = 30;                       // (in seconds)
$config['smtp_crypto']      = 'tls';                       // '' or 'tls' or 'ssl'
$config['smtp_debug']       = 0;                        // PHPMailer's SMTP debug info level: 0 = off, 1 = commands, 2 = commands and data, 3 = as 2 plus connection status, 4 = low level data output.
$config['smtp_auto_tls']    = true;                     // Whether to enable TLS encryption automatically if a server supports it, even if `smtp_crypto` is not set to 'tls'.
$config['smtp_conn_options'] = array();                 // SMTP connection options, an array passed to the function stream_context_create() when connecting via SMTP.
$config['wordwrap']         = true;
$config['wrapchars']        = 76;
$config['mailtype']         = 'html';                   // 'text' or 'html'
$config['charset']          = 'utf-8';                     // 'UTF-8', 'ISO

我使用phpmailer库发送此电子邮件,并且在我的gmail帐户上激活了不太安全的应用程序,发生了什么问题?因为在localhost上一切正常

这是错误

ERROR - 2019-07-17 12:49:32 --> Severity: Warning --> stream_socket_enable_crypto(): Peer certificate CN=`bigcarica.harapmaklum.com' did not match expected CN=`smtp.gmail.com' /home/matoaind/public_html/application/third_party/phpmailer/class.smtp.php 368

1 个答案:

答案 0 :(得分:2)

您正在要求它连接到端口587上的smtp.gmail.com,但是您的错误消息表明它正在连接到其他服务器。这是因为您的托管服务提供商正在将SMTP通信重定向到他们自己的服务器。该脚本正在检测到该错误,并拒绝名称不匹配的情况。这是使用TLS的主要原因之一-它使您能够检测中间人攻击(这实际上是什么)。

请参阅提供商的文档,以了解他们希望您如何发送电子邮件,或要求他们删除此重定向。

此确切的问题在故障排除指南中涵盖了错误消息链接。