doulutian4843 2014-06-11 15:50
浏览 151
已采纳

PHPMailer给出“SMTP连接失败”错误消息

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.

  • 写回答

1条回答 默认 最新

  • duan2477 2014-06-11 15:55
    关注

    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

    That means that your local PHP setup does not have php_openssl.dll enabled. You can enable that by going into your php.ini & finding a line that looks like this:

    ; extension=php_openssl.dll
    

    And uncommenting it:

    extension=php_openssl.dll
    

    Save that, restart Apache & all should be good.

    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. And then place the following command in there:

    phpinfo();
    

    Then load phpinfo.php via a web browser like this; change http://localhost/ to match your server URL:

    http://localhost/phpinfo.php
    

    When that page loads, it will show you all of your server’s PHP settings. Look for the line that reads Loaded Configuration File and change the php.ini that is loaded there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 win11系统打开软件很慢
    • ¥30 XIAO esp32c3 读取FDC2214的数据
    • ¥20 我用malloc申请了一块空间 判空显示指针不为null 但是在输出data指针所指的地址是缺全是0 空指针不能输入值进去数组为什么呀
    • ¥15 在工控机(Ubuntu系统)上外接USB蓝牙硬件进行蓝牙通信
    • ¥15 关于PROCEDURE和FUNCTION的问题
    • ¥100 webapi的部署(标签-服务器)
    • ¥20 怎么加快手机软件内部计时的时间(关键词-日期时间)
    • ¥15 C语言除0问题的检测方法
    • ¥15 为什么四分管的内径有的是16mm有的15mm,四分不应该是12.7mm吗
    • ¥15 macos13下 ios交叉编译的问题