无法使用PHPMailer

时间:2018-02-27 11:18:32

标签: php phpmailer

我正在尝试在我的PHP脚本上发送电子邮件。由于我的主机禁用了mail(),我不得不使用PHPMailer。我已经设置了所需的所有变量。但是我仍然无法发送任何东西。我已经尝试过第三方网站来测试SMTP服务器并且它有效。我也尝试通过Telnet连接该SMTP服务器,但是它给了我连接错误,就像在PHP脚本上一样。

我在调试文本中看​​不到有关主机的任何信息。我是否以错误的方式在脚本中设置主机?最后,主机不支持TLS,SSL,因此我将SMTPSecure设置为false。

$mail = new PHPMailer();
        try {
            $mail->SMTPDebug = 2;                                 
            $mail->isSMTP();                           
            $mail->Host = 'smtp.myhost.com'; 
            $mail->SMTPAuth = true;                     
            $mail->Username = 'verify@mydomain.com';  
            $mail->Password = 'mypass';            
            $mail->SMTPSecure = false;              
            $mail->Port = 25;                      

            //Recipients
            $mail->setFrom('verify@mydomain.com');
            $mail->addAddress('recipient@test.com');

            //Content
            $mail->isHTML(true);
            $mail->Subject = 'Here is the subject';
            $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
            $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

            $mail->send();
            echo 'Message has been sent';
        } catch (Exception $e) {
            echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
        }

这是调试文本:

2018-02-27 11:05:59 SERVER -> CLIENT: 
2018-02-27 11:05:59 CLIENT -> SERVER: EHLO mydomain.com
2018-02-27 11:05:59 SERVER -> CLIENT: 
2018-02-27 11:05:59 SMTP ERROR: EHLO command failed: 
2018-02-27 11:05:59 CLIENT -> SERVER: HELO mydomain.com
2018-02-27 11:05:59 SERVER -> CLIENT: 
2018-02-27 11:05:59 SMTP ERROR: HELO command failed: 
SMTP Error: Could not authenticate.
2018-02-27 11:05:59 CLIENT -> SERVER: QUIT
2018-02-27 11:05:59 SERVER -> CLIENT: 
2018-02-27 11:05:59 SMTP ERROR: QUIT command failed: 
SMTP connect() failed. 
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

0 个答案:

没有答案