【发布时间】:2015-11-01 07:50:41
【问题描述】:
我正在尝试通过 php 发送邮件.. 我也尝试过 php 的 mail 函数和 phpmailer() 函数。 但我无法发送 我也尝试通过设置端口号来更改 php.ini 中的设置。到 465,25 以及通过网络获得帮助的更多设置,但我的邮件仍然无法正常工作,我的代码
<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>
<?php
date_default_timezone_set('asia/calcutta');
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$body = "testing message";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = $_POST["u"]; // GMAIL username
$mail->Password = $_POST["p"]; // GMAIL password
$mail->SetFrom($_POST["u"], 'First Last');
$mail->Subject = "hello";
$mail->MsgHTML($body);
$address = $_POST["to"];
$mail->AddAddress($address, "info");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
我有另一个页面获取用户名、密码、发件人的电子邮件并在 dis 页面上获取 dem。我得到的错误是这样的:
邮件程序错误:以下发件人地址失败:s********@g***l.com:邮件未接受来自服务器,530,5.5.1 需要身份验证。了解更多信息,请致电 530 5.5.1 https://support.google.com/mail/answer/14257 sa9sm15580073pbc.18 - gsmtp
SMTP 服务器错误:需要 5.5.1 身份验证。了解更多信息,请访问 530 5.5.1 https://support.google.com/mail/answer/14257 sa9sm15580073pbc.18 - gsmtp
SMTP 服务器错误:需要 5.5.1 身份验证。了解更多信息,请访问 530 5.5.1 https://support.google.com/mail/answer/14257 sa9sm15580073pbc.18 - gsmtp
有时我也会收到一条错误消息:
called mail() without being connected mailer error in php
请任何人帮助我.... 提前致谢
【问题讨论】:
-
您的代码基于一个旧示例,并且可能使用的是旧版本的 PHPMailer。 Get the latest。之后,read the troubleshooting docs.
-
试试
$mail->SMTPSecure = 'tls';,仔细检查用户名和密码。您可以查看 PHPMailer documentation for gmail.
标签: php email authentication phpmailer