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 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流