SMTP错误:无法连接到服务器:(0)和SMTP connect()失败。邮件错误:SMTP connect()失败

时间:2019-03-28 11:42:11

标签: phpmailer

我正在尝试通过phpMailer发送邮件,但出现以下错误

  

2019-03-28 10:54:00 SMTP错误:无法连接到服务器:(0)   2019-03-28 10:54:00 SMTP connect()失败。邮件错误:SMTP   connect()失败。

我在下面提到了链接

https://stackoverflow.com/questions/43815571/mailer-error-smtp-connect-failed
https://stackoverflow.com/questions/21088062/phpmailer-smtp-connection-error
https://stackoverflow.com/questions/43999573/phpmailer-smtp-connect-error
https://stackoverflow.com/questions/36735979/mailer-error-smtp-connect-failed
https://stackoverflow.com/questions/30476024/smtp-connect-failed-phpmailer

,但是在实现了以上链接中提到的解决方案之后,出现了相同的错误。

我尝试使用PHP mail()函数获得相同的凭据,它可以工作,但是我想通过SMTP发送邮件。

这是我的代码

require('mail/class.phpmailer.php');
require('mail/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->SMTPDebug = 2;
$mail->isSMTP(); 
$mail->Mailer = "smtp";                                            
$mail->Host       = 'mail.example.com';  
$mail->SMTPAuth   = true;                                  
$mail->Username   = 'From@example.com';                     
$mail->Password   = 'password';                             
$mail->SMTPSecure = 'ssl'; 
$mail->Port       = 465;                                    
$mail->setFrom('From@example.com', 'from');
$mail->addAddress('To@example.com', 'To');
$mail->isHTML(true);                               
$mail->Subject = 'subject';
$mail->Body    = 'This is message';
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

0 个答案:

没有答案