簡體   English   中英

PHPMailer:SMTP 錯誤:無法連接到服務器:(0)與godaddy

[英]PHPMailer: SMTP ERROR: Failed to connect to server: (0) with godaddy

我收到錯誤:

    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 網絡/電子郵件帳戶。 但是,針對此錯誤的大多數解決方案與 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";
 }

如果您提供了不正確的信息,我深表歉意。 但是,您應該確保服務器的 smtp 端口未使用25

我已經弄清楚出了什么問題:本質上,我只需要替換$mail->isSMTP(); $mail->isMail(); 它奏效了——只是為了讓其他人知道他們是否有同樣的問題!

我有同樣的問題,我嘗試使用端口 465 的 SSL 然后它說服務不可用然后我嘗試這個解決了我的問題希望它也解決了你的問題 1)確保你使用 $mail->IsSMTP(); 用於身份驗證。 Ismail 僅適用於與郵件 function 相同的服務器

2) 這個東西解決了我的問題 $mail->SMTPSecure = "tsl"; $郵件->端口= 587;

我現在添加這兩行 email 發送在早些時候完美運行我遇到此錯誤 SMTP 連接()失敗。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting但上面的東西解決了我的問題希望它對你有用謝謝

在使用 Gmail 的 SMTP 服務器發送電子郵件之前,您需要在您的 Google 帳戶安全設置下進行一些安全和權限級別設置。

  1. 改變

$mail->host = "本地主機";

$mail->Host = "smtp.gmail.com";

使用真正的 email 作為發送方和接收方“確保密碼”

  1. 改變

$mail->SMTPSecure = 'ssl';

$mail->SMTPSecure = 'tls';

   //tls for localhost and ssl for host server 'onligne'

可能對你有用:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM