我的问题很简单:用PHPMailer发一封电子邮件,我遵守了godaddy的规则:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTP_AUTH = false;
$mail->Port = 25;
$mail->Host = "relay-hosting.secureserver.net";
$mail->FromName = "mycomercial@mycomercialemail.com.br";
$mail->SMTPDebug = 2;
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("mygmailemail@gmail.com");
if(!$mail->Send()) {
echo "Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}这段代码是我在许多论坛上看到的,但我仍然无法发送电子邮件,我收到的是:
2018-10-16 22:31:25 SMTP错误:连接服务器失败:连接被拒绝(111) 2018-10-16 22:31:25 SMTP连接()失败
这就是他们推荐的服务器?为什么我联系不上?谢谢大家的帮助
发布于 2018-10-17 15:48:52
嗯,我已经联系了goDaddy支持部门(很好),他们说在服务器内部使用本地主机,所以我更改了代码,仍然没有工作,但至少连接到服务器,给了我错误: STARTTLS,在网上搜索我找到了这个解决方案:解决方案。
$mail = new PHPMailer(true);
$mail->IsSMTP(); // Using SMTP.
$mail->SMTPDebug = 1;
$mail->SMTPAuth = false; // Enables SMTP authentication.
$mail->Host = "localhost"; // GoDaddy support said to use localhost
$mail->Port = 25;
$mail->SMTPSecure = 'none';
//havent read yet, but this made it work just fine
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->AddReplyTo('comercial@email.com.br', 'Me');
$mail->AddAddress('my@gmail.com', 'Them');
$mail->SetFrom('comercial@email.com.br', 'Me');
$mail->Subject = 'PHPMailer Test Subject via smtp, basic with authentication';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML("Hi, this is an test email");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}为了最终完成这个脚本,他们还给了我这个脚本:Github来测试以三种不同的方式发送的电子邮件,但是这个脚本发送的电子邮件可能会发送给你的垃圾邮件(第一个脚本变得正常),所以他们说有必要用TXT记录和DNS配置一些东西,这是支持我的数据:
添加TXT记录 主持人:@ TXT值:v=spf1 a mx ptr include:secureserver.net -all TTL: 1小时
但我不太清楚这件事,不知道,我不能为这个解决办法留下来,因为我必须去看医生,谢谢你的关照。
发布于 2020-02-26 17:25:43
问题是SMTP通过goDaddy连接有点棘手,因为它们对发送电子邮件施加了严格的限制。如果不需要SMTP,则可以使用以下代码强制phpMailer使用内置的mail()函数:
$mail = new PHPMailer();
$mail->isMail(); //using mail() functionhttps://stackoverflow.com/questions/52844912
复制相似问题