ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

PHPMailer SMTP连接失败

2019-10-29 16:32:20  阅读:270  来源: 互联网

标签:email mandrill php


我正在尝试通过Mandrill用PHPMailer发送电子邮件,但没有成功(在localhost上测试).
有人可以告诉我问题出在哪里吗?

这是来自PHPMailer的详细信息:

2014-04-27 17:51:06 SERVER -> CLIENT: 220 smtp.mandrillapp.com ESMTP
2014-04-27 17:51:06 CLIENT -> SERVER: EHLO 127.0.0.1
2014-04-27 17:51:06 SERVER -> CLIENT: 250-ip-10-107-129-238
                                      250-PIPELINING
                                      250-SIZE 26214400
                                      250-STARTTLS
                                      250-AUTH PLAIN LOGIN
                                      250-ENHANCEDSTATUSCODES
                                      250 8BITMIME
2014-04-27 17:51:06 CLIENT -> SERVER: STARTTLS
2014-04-27 17:51:06 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2014-04-27 17:51:06 CLIENT -> SERVER: QUIT
2014-04-27 17:51:16 SERVER -> CLIENT:
2014-04-27 17:51:16 SMTP ERROR: QUIT command failed: SMTP connect() failed. Message could not be sent.
Mailer Error: SMTP connect() failed.

这是我的代码:

$mail = new PHPMailer;
        $mail->IsSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.mandrillapp.com';                 // Specify main and backup server
        $mail->Port = 587;                                    // Set the SMTP port
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = 'example@mail.com';                 // yes, I have entered my username mail
        $mail->Password = 'xxxxxxxxxxxx-xxxxxxxxx';           // yes, API key is here
        $mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
        $mail->From = 'from@example.com';
        $mail->FromName = 'Your From name';
        if($test_mode) {
            $mail->SMTPDebug = 2;
            $mail->AddAddress('mymail@gmail.com');
        } else {
            $mail->AddAddress($email);
        }
        $mail->IsHTML(true);                                  // Set email format to HTML
        $mail->WordWrap = 70;                                 // Set word wrap to 70 characters
        //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments

        $mail->Subject = 'Subject';
        $mail->Body    = 'This is the HTML message body <strong>in bold!</strong>';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

        if(!$mail->Send()) {
            //redirect to
            echo 'Message could not be sent.<br>';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
            exit;
        }

编辑:
我可以删除它:

$mail->SMTPSecure = 'tls';

它会工作!但是现在禁用了加密.为什么启用加密后无法使用?

解决方法:

php.ini中不受欢迎的php_openssl.dll

标签:email,mandrill,php
来源: https://codeday.me/bug/20191029/1961324.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有