我在电子邮件和 Office 下使用 GoDaddy 专业电子邮件(不是工作区电子邮件)。对于我的网站,我想使用 PHPMailer 向用户发送电子邮件。我已根据 GoDaddy 电子邮件服务器信息使用了所有凭据。
根据 GoDaddy 的说法,发送服务器设置为:
我已将 PHPMailer 代码设置如下:
<?php
try
{
$email = new PHPMailer(TRUE);
$email->isSMTP();
$email->SMTPDebug = 2;
$email->SMTPAuth = TRUE;
$email->SMTPAutoTLS = FALSE;
$email->SMTPSecure = "ssl";
$email->Host = "smtpout.secureserver.net";
$email->Port = 465;
$email->Username = "myUserName";
$email->Password = "MyPassword";
$email->setFrom("[email protected]", "Name");
$email->addAddress("[email protected]", "Name");
$email->isHTML(TRUE);
$email->Body = "My HTML Code";
$email->Subject = "My Subject";
$email->send();
}
catch (Exception $e)
{
// $email->ErrorInfo;
}
?>
上面的代码抛出以下错误:
2019-08-14 10:55:58 SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
我已经寻找解决方案。一些 Stackoverflow 问题讨论了有关 GoDaddy Workspace 电子邮件的问题。但到目前为止,我对找到解决方案感到沮丧。如果我做错了什么,请帮助我。
我发现以下设置有效。 这可能有用。
使用80作为端口
<?php
try
{
$email = new PHPMailer(TRUE);
$email->isSMTP();
$email->SMTPDebug = 2;
$email->SMTPAuth = TRUE;
$email->SMTPAutoTLS = FALSE;
$email->SMTPSecure = "tls";
$email->Host = "smtpout.secureserver.net";
$email->Port = 80;
$email->Username = "GoDaddy Professional Email Username";
$email->Password = "GoDaddy Professional Email Password";
$email->setFrom("[email protected]", "Name");
$email->addAddress("[email protected]", "Name");
$email->isHTML(TRUE);
$email->Body = "My HTML Code";
$email->Subject = "My Subject";
$email->send();
}
catch (Exception $e)
{
// $email->ErrorInfo;
}
?>`
我的回答是:Hiranmoy 在 8 月 14 日 14:56 的建议应该是批准的答案。 Godaddy 因这个简单的功能而引起的大量头痛值得一个经过测试的、有效的解决方案,而 Hiranmoy 的解决方案是我经过数小时的搜索后找到的唯一一个。这是 Hiranmoy 的片段,添加了缺失的内容:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'Exception.php';
require 'PHPMailer.php';
require 'SMTP.php';
try
{
$email = new PHPMailer(TRUE);
$email->isSMTP();
$email->SMTPDebug = 2;
$email->SMTPAuth = TRUE;
$email->SMTPAutoTLS = FALSE;
$email->SMTPSecure = "tls";
$email->Host = "smtpout.secureserver.net";
$email->Port = 80;
$email->Username = "GoDaddy Professional Email Username";
$email->Password = "GoDaddy Professional Email Password";
$email->setFrom("[email protected]", "Name");
$email->addAddress("[email protected]", "Name");
$email->isHTML(TRUE);
$email->Body = "My HTML Code";
$email->Subject = "My Subject";
$email->send();
}
catch (Exception $e)
{
// $email->ErrorInfo;
}
?>
截至 2024 年 10 月,当我通过 Firebase 的触发电子邮件扩展发送电子邮件时,GoDaddy 的这些 SMTP 设置对我有效:
host: "smtp.office365.com",
port: 587,
secure: false,
auth: {
user: "email",
pass: "password"
}