PHPMailer:SMTP错误:无法通过Godaddy连接到服务器(0)

时间:2020-05-03 02:40:24

标签: php html phpmailer cpanel

我遇到了错误:

    2020-05-03 02:33:55 SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

我查看了所有GoDaddy文章和堆栈文章,我可以找到它们并尝试使用它们的解决方案-例如更改端口等。我还尝试使用Gmail和cPanel Web /电子邮件帐户。但是,针对该错误的大多数解决方案与GoDaddy无关,它们的解决方案与XAMPP等有关。 任何帮助,我们将不胜感激:)

作为参考,这是PHP代码:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;


require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; 
$mail->Host = "localhost";
$mail->Port = 465; 
$mail->IsHTML(true);
$mail->Username = "abc@def.com";
$mail->Password = "xxx";
$mail->SetFrom("abc@def.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("uvw@xyz.com");

 if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
 } else {
    echo "Message has been sent";
 }

3 个答案:

答案 0 :(得分:0)

对于您提供的信息不正确,我深表歉意。但是,您应确保服务器的smtp端口未使用 25

答案 1 :(得分:0)

我弄清楚出了什么问题: 本质上,我只需要将$mail->isSMTP();替换为$mail->isMail();就可以了-只是让其他人知道他们是否也遇到同样的问题!

答案 2 :(得分:0)

我有同样的问题 我尝试使用端口465的SSL,然后说服务不可用 然后我尝试这个东西可以解决我的问题 希望它也解决你的 1)确保使用 $ mail-> IsSMTP();用于身份验证。 Ismail仅适用于具有邮件功能的同一服务器

2)这件事解决了我的问题 $ mail-> SMTPSecure =“ tsl”; $ mail->端口= 587;

我现在添加这两行,电子邮件发送正常 早些时候我遇到这个错误 SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 但以上的事情解决了我的问题 希望它对你有用 谢谢

相关问题