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

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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵