使用Gmail SMTP发送电子邮件时出错 [英] Error sending e-mail using Gmail SMTP
本文介绍了使用Gmail SMTP发送电子邮件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试使用Gmail SMTP和 PHPmailer
发送电子邮件。
问题是我有这个错误:
SMTP - >错误:无法连接到服务器:php_network_getaddresses:getaddrinfo失败:没有这样的主机是已知的。 (0)
SMTP错误:无法连接到SMTP主机。邮件程序错误:SMTP错误:无法连接到SMTP主机。
以下是我使用的代码:
?php
require_once($ _ SERVER ['DOCUMENT_ROOT']。'/ FreeUni / Kiosk / class.phpmailer.php');
$ mail = new PHPMailer();
$ mail-> IsSMTP();
// GMAIL配置
$ mail-> SMTPAuth = true; //启用SMTP认证
$ mail-> SMTPSecure =ssl; //设置服务器的前缀
$ mail-> Host =ssl://smtp.gmail.com:465; //将GMAIL设置为SMTP服务器
$ mail->用户名=XXXX@gmail.com; // GMAIL用户名
$ mail->密码=XXXXXX; // GMAIL密码
$ mail-> SMTPDebug = 1;
//结束Gmail
$ mail-> From =gvakh10@gmail.com;
$ mail-> FromName =你的名字;
$ mail-> Subject =some subject;
$ mail-> MsgHTML(the message);
//$mail-> AddReplyTo(\"reply@email.com\",reply name); //他们在这里回答,可选
$ mail-> AddAddress( XXXX@gmail.com,name to);
$ mail-> IsHTML(true); //发送为HTML
if(!$ mail-> Send()){//查看我们是否返回消息或值bolean
echoMailer Error:。 $ MAIL-> ERRORINFO;
} else echoMessage sent!;
?>
我已经在网上搜索,但找不到解决方案。
解决方案
我替换了
$ mail-> Host =ssl ://smtp.gmail.com:465;
只需
$ mail-> Host =smtp.gmail.com:465;
!!
谢谢大家。
I'm trying to send e-mail using Gmail SMTP and PHPmailer
.
The problem is that i have this Error:
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
解决方案
I replaced
$mail->Host = "ssl://smtp.gmail.com:465";
with just
$mail->Host ="smtp.gmail.com:465";
and it worked !!!
Thanks everybody.
这篇关于使用Gmail SMTP发送电子邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文