PHPMailer 使用 Gmail 作为 SMTP 服务器.无法连接到 SMTP 主机.邮件程序错误:SMTP 错误:无法连接到 SMTP 主机 [英] PHPMailer to use Gmail as SMTP server.Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host

查看:68
本文介绍了PHPMailer 使用 Gmail 作为 SMTP 服务器.无法连接到 SMTP 主机.邮件程序错误:SMTP 错误:无法连接到 SMTP 主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 phpMailer 通过电子邮件向用户发送确认消息.我的代码是这样的:

i am trying to use phpMailer to send confirmation messages to users via email. my code is this:

<?php
include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->Port = 465; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "sender@gmail.com"; // your SMTP username or your gmail username
$mail->Password = "mypasswrord"; // your SMTP password or your gmail password
$from = "webmaster@example.com"; // Reply to this email
$to="receiver@yahoo.com"; // Recipients email ID
$name="Jersey Name"; // Recipient's name
$mail->From = $from;
$mail->FromName = "Webmaster"; // Name to indicate where the email came from when the recepient received
$mail->AddAddress($to,$name);
$mail->AddReplyTo($from,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Sending Email From Php Using Gmail";
$mail->Body = "This Email Send through phpmailer, This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>

我已经在 php.ini 中启用了 ssl.

i already enabled ssl in php.ini.

PS> sender@gmail.com 是保护隐私的屏蔽邮件.但我确实在那部分输入了一个真实的电子邮件地址

PS> sender@gmail.com is a mask email to protect the privacy. but i did put a true email address in that part

推荐答案

在你的 php.ini 中确保你已经取消注释了

in you php.ini make sure you have uncommented the line with

extension=php_openssl.dll

这篇关于PHPMailer 使用 Gmail 作为 SMTP 服务器.无法连接到 SMTP 主机.邮件程序错误:SMTP 错误:无法连接到 SMTP 主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆