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 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗