编程语言
首页 > 编程语言> > PHPMailer SMTP连接失败

PHPMailer SMTP连接失败

作者:互联网

我正在尝试通过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