簡體   English   中英

PHPMailer:Godaddy 上的 SMTP 主機連接錯誤

[英]PHPMailer : SMTP host connection error on Godaddy

郵件程序錯誤:SMTP 錯誤:無法連接到 SMTP 主機。

當我在godaddy 中運行此代碼時會生成此錯誤。

<?php
require("PHPMailer_5.2.0/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host     = "smtpout.secureserver.net"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username@domain.com"; // SMTP username
$mail->Password = "******"; // SMTP password
$mail->From     = "username@domain.com";
$mail->FromName = "User";
$mail->AddAddress("Sendto@gmail.com"); // name is optional
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$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";
if (!$mail->Send()) {
    echo "Message could not be sent. <p>";
    echo "Mailer Error: " . $mail->ErrorInfo;
    exit;
}
echo "Message has been sent";
?>

如果我理解正確,使用您正在使用的 SMTP 地址,您也需要指定端口(465)。

但是,根據 Godaddy 文檔,您應該使用以下 SMTP 服務器:

relay-hosting.secureserver.net

此代碼可能對您有所幫助。

$mail->Host     = "smtpout.secureserver.net";

您的主機名應該類似於mydomain.com

$mail->Port = 465;

我使用 localhost 作為 smtp 服務器,端口 25,沒有 ssl 和沒有身份驗證解決了這個問題。 我正在使用 wordpress,在 Godaddy 服務器上使用 divi 主題。

試試下面的代碼它對我有用!

<?php
require("src/PHPMailer.php");
require("src/SMTP.php");
require("src/Exception.php");

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

$mail = new PHPMailer(true);

try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->SMTPAutoTLS = false;
$mail->Port = 25;

//Recipients
$mail->setFrom('from@gmail.com', 'Mailer');
$mail->addAddress('to@gmail.com', 'XYZTABC');
//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 "<pre>";
    print_r($e);
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

暫無
暫無

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

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