简体   繁体   English

PHPMailer提供“ SMTP连接失败”错误消息

[英]PHPMailer giving “SMTP Connection failed” error message

I have the following code: 我有以下代码:

require 'bin\PHPMailerAutoload.php';

$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

$mail->From = "[an e-mail address]@gmail.com";
$mail->AddAddress("[an e-mail address]@gmail.com");

$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));

$mail->AltBody = 'sprava';

if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent";
}

And here is the response: 这是响应:

    2014-06-11 15:46:34 SERVER 
-> CLIENT: 220 mx.google.com ESMTP v47sm60079970eel.22 - gsmtp 2014-06-11 15:46:34 CLIENT 
-> SERVER: EHLO localhost 2014-06-11 15:46:34 SERVER 
-> CLIENT: 250-mx.google.com at your service, [95.103.53.55] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250 CHUNKING 2014-06-11 15:46:34 CLIENT 
-> SERVER: STARTTLS 2014-06-11 15:46:34 SERVER 
-> CLIENT: 220
    2.0.0 Ready to start TLS Warning: stream_socket_enable_crypto(): this stream does not support SSL/crypto in C:\dev\localhost_www\bin\class.smtp.php on line 262 2014-06-11 15:46:34 CLIENT 
-> SERVER: QUIT 2014-06-11 15:46:44 SERVER 
-> CLIENT: 2014-06-11 15:46:44 SMTP ERROR: QUIT command failed: SMTP connect() failed. Mailer Error: SMTP connect() failed.

How can I fix that? 我该如何解决? I tried that thing with php.ini file but without success. 我用php.ini文件尝试了一下,但是没有成功。

The key to the issues this this part of the error: 问题的关键是此部分错误:

-> CLIENT: 220 2.0.0 Ready to start TLS Warning: stream_socket_enable_crypto(): this stream does not support SSL/crypto in C:\\dev\\localhost_www\\bin\\class.smtp.php on line 262 2014-06-11 15:46:34 CLIENT ->客户端:220 2.0.0准备启动TLS警告:stream_socket_enable_crypto():此流不支持262行上的C:\\ dev \\ localhost_www \\ bin \\ class.smtp.php中的SSL / crypto 2014-06-11 15 :46:34客户

That means that your local PHP setup does not have php_openssl.dll enabled. 这意味着您的本地PHP安装程序未启用php_openssl.dll You can enable that by going into your php.ini & finding a line that looks like this: 您可以通过进入php.ini并找到如下所示的行来启用该功能:

; extension=php_openssl.dll

And uncommenting it: 并取消注释:

extension=php_openssl.dll

Save that, restart Apache & all should be good. 保存,重新启动Apache,一切都很好。

And if you want to make sure your are editing the correct php.ini file, create a file named phpinfo.php in your web root. 并且,如果要确保您正在编辑正确的php.ini文件,请在您的Web根目录中创建一个名为phpinfo.php的文件。 And then place the following command in there: 然后在其中放置以下命令:

phpinfo();

Then load phpinfo.php via a web browser like this; 然后通过这样的网络浏览器加载phpinfo.php change http://localhost/ to match your server URL: 更改http://localhost/以匹配您的服务器URL:

http://localhost/phpinfo.php

When that page loads, it will show you all of your server's PHP settings. 加载该页面后,它将向您显示服务器的所有PHP设置。 Look for the line that reads Loaded Configuration File and change the php.ini that is loaded there. 查找读取“ Loaded Configuration File的行,并更改在那里加载的php.ini

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

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