【发布时间】:2023-03-20 09:26:01
【问题描述】:
我的项目包含一个发送电子邮件的功能,即PHPMailer。从我的本地主机服务器发送电子邮件运行良好,但今天停止发送电子邮件,现在它显示此错误消息
SMTP Error: Could not connect to SMTP host.
我添加了此代码 $mail->SMTPDebug = 1; 以查看调试错误,现在向我显示此消息:
SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: The requested name is valid, but no data of the requested type was found. (0) SMTP Error: Could not connect to SMTP host
我已经在php.ini 中有enabled extension=php_openssl.dll。
这是我的代码:
$mail = new PHPMailer();
$mail->SMTPSecure = 'ssl';
$mail->IsSMTP();
$mail->Username = "myemail@gmail.com"; // your GMail user name
$mail->Password = "password";
$mail->AddAddress($email); // recipients email
$mail->FromName = "username"; // readable name
$mail->IsHTML(true);
$mail->Subject = "title";
$mail->Body = " Message";
$mail->SMTPDebug = 1;
$mail->Host = "ssl://smtp.gmail.com"; // GMail
$mail->Port = 465;
$mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->From = $mail->Username;
if($mail->Send()){
} else {
}
谢谢
【问题讨论】: