gpt4 book ai didi

phpmailer 不发送电子邮件

转载 作者:可可西里 更新时间:2023-11-01 01:07:17 27 4
gpt4 key购买 nike

我正在使用 phpmailer,但出现以下错误:

消息未发送邮件程序错误:SMTP 错误:无法连接到 SMTP 主机。

<?php
require("class.phpmailer.php");
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'ssl://smtp.myhost.com:465';
$mailer->SMTPAuth = TRUE;
$mailer->Username = 'myemail@myhost.com';
$mailer->Password = 'mypass';
$mailer->From = 'myemailagain@myhost.com';
$mailer->FromName = 'myname';
$email1 = $_GET['email'];
$verification = rand();
$mailer->Body = 'Welcome to our site';
$mailer->Subject = 'verification';
$mailer->AddAddress($email1);
if(!$mailer->Send())
{
echo "Message was not sent<br/ >";
echo "Mailer Error: " . $mailer->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>

注意:我使用“myhost.com”,但它不是我的真实域

最佳答案

我认为您指定的主机不正确。试试这个:

$mailer->Host="smtp.myhost.com";
$mailer->Port=465;
$mailer->SMTPSecure="ssl"; //If this doesn't work, try 'tls'

如果还是不行,考虑设置:

$mailer->SMTPDebug=1;

另外,确保启用了 PHP 的 OpenSSL 扩展。

关于phpmailer 不发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7998776/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com