Error sending e-mail using Gmail SMTP(使用 Gmail SMTP 发送电子邮件时出错)
本文介绍了使用 Gmail SMTP 发送电子邮件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 Gmail SMTP 和 PHPmailer 发送电子邮件.
I'm trying to send e-mail using Gmail SMTP and PHPmailer.
问题是我有这个错误:
SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0)
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
这是我正在使用的代码:
Here's the code I am using:
?php
require_once($_SERVER['DOCUMENT_ROOT'].'/FreeUni/Kiosk/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
//GMAIL config
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the server
$mail->Host = "ssl://smtp.gmail.com:465"; // sets GMAIL as the SMTP server
$mail->Username = "XXXX@gmail.com"; // GMAIL username
$mail->Password = "XXXXXX"; // GMAIL password
$mail->SMTPDebug = 1;
//End Gmail
$mail->From = "gvakh10@gmail.com";
$mail->FromName = "you name";
$mail->Subject = "some subject";
$mail->MsgHTML("the message");
//$mail->AddReplyTo("reply@email.com","reply name");//they answer here, optional
$mail->AddAddress("XXXX@gmail.com","name to");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {//to see if we return a message or a value bolean
echo "Mailer Error: " . $mail->ErrorInfo;
} else echo "Message sent!";
?>
我已经在网上搜索过,但找不到解决方案
I've already searched the web but couldn't find the solution
推荐答案
我换了
$mail->Host = "ssl://smtp.gmail.com:465";
只有
$mail->Host="smtp.gmail.com:465";
成功了!!!
谢谢大家.
这篇关于使用 Gmail SMTP 发送电子邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:使用 Gmail SMTP 发送电子邮件时出错
基础教程推荐
猜你喜欢
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
