phpmailer SMTP错误 [英] phpmailer SMTP error
本文介绍了phpmailer SMTP错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此php代码通过gmail帐户发送电子邮件.但它显示smtp错误. 我已经用谷歌搜索了.但未找到任何具体答案.谁能帮忙找到解决方案??
I am using this php code to send email through gmail account . but its showing smtp error . I have googled it . but not found any specific answer . would anyone please help to find the solution ??
我已将此代码托管在我的网络服务器中
I have hosted this code in my webserver
错误: "SMTP错误:无法连接到SMTP主机.未发送消息 Mailer错误:SMTP错误:无法连接到SMTP主机.SMTP错误:无法连接到SMTP主机."
error : "SMTP Error: Could not connect to SMTP host. Message was not sent Mailer Error: SMTP Error: Could not connect to SMTP host.SMTP Error: Could not connect to SMTP host."
代码:
<?php
require("class.phpmailer.php");
$email = $_POST['email_address'];
$username = 'username@gmail.com'; //your gmail address
$password = 'password'; //password
send_mail_to_subscriber();
function send_mail_to_subscriber()
{
global $username,$password,$email;
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'ssl://smtp.gmail.com:465';
$mailer->SMTPAuth = TRUE;
$mailer->Username = $username;
$mailer->Password = $password;
$mailer->From = $username;
$mailer->FromName = $username;
$mailer->Body = 'this is a message';
$mailer->Subject = 'this is a subject';
$mailer->AddAddress($email);
if(!$mailer->Send())
{
echo "Message was not sent<br/ >";
echo "Mailer Error: " . $mailer->ErrorInfo;
}
else
{
echo "Download link has been sent to your email address";
}
}
?>
推荐答案
更改主机并添加以下内容:
Change your Host and add the following:
$mailer->SMTPSecure = 'ssl';
$mailer->Host = 'smtp.gmail.com';
$mailer->Port = 465;
这篇关于phpmailer SMTP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文