PHPMailer SMTP连接失败 [英] PHPMailer SMTP connect failed

查看:339
本文介绍了PHPMailer SMTP连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PHPMailer ,但没有成功(在localhost上测试).
有人可以告诉我问题出在哪里吗?

I'm trying to send email over Mandrill with PHPMailer but withouth sucess (testing on localhost).
Can someone tell me where is the problem?

这是来自PHPMailer的详细信息:

This is the verbose information from 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';

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

and it will work! But now the encryption is disabled. Why is this not working with encryption enabled?

推荐答案

php.ini中未出现 php_openssl.dll

Uncoment php_openssl.dll in php.ini

这篇关于PHPMailer SMTP连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆