我有以下代码:
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";
}
下面是回应:
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.
我该怎么解决?我在php.ini
文件中尝试过,但没有成功。
问题的关键这部分错误:
->客户端:2202.0.0准备启动TLS警告:stream_socket_enable_crypto((:此流在中不支持SSL/cryptoC: ''dev''localhost_www''bin''class.smtp.php在线262 2014-06-1115:46:34客户端
这意味着您的本地PHP设置没有启用php_openssl.dll
。您可以通过进入您的php.ini
&找到一条像这样的线:
; extension=php_openssl.dll
并取消注释:
extension=php_openssl.dll
保存它,重新启动Apache&一切都应该很好。
如果您想确保您正在编辑正确的php.ini
文件,请在web根目录中创建一个名为phpinfo.php
的文件。然后在其中放置以下命令:
phpinfo();
然后通过这样的web浏览器加载phpinfo.php
;更改http://localhost/
以匹配您的服务器URL:
http://localhost/phpinfo.php
当该页面加载时,它将向您显示服务器的所有PHP设置。查找读取Loaded Configuration File
的行,并更改在那里加载的php.ini
。