【发布时间】:2016-09-28 04:50:10
【问题描述】:
当我尝试使用 PHP SMTP 电子邮件服务器发送电子邮件时,出现以下错误。
SMTP Error: Could not authenticate. Message could not be sent.
邮件程序错误:SMTP 错误:无法验证。
以下是我使用过的代码。
function supervisorMail(){
global $error;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = "***@gmail.com";
$mail->Password = "****";
$mail->SetFrom("***@gmail.com", "Employee Leave Management System");
$userID=$_SESSION['userID'];
$select_query = mysql_query("SELECT * FROM employee WHERE emp_id = '$userID'");
$select_sql = mysql_fetch_array($select_query);
$name=$select_sql['manager_name'];
var_dump($name);
$select_query1 = mysql_query("SELECT email FROM employee WHERE emp_id='$name'");
$select_sql1 = mysql_fetch_array($select_query1);
$email=$select_sql1['email'];
var_dump($email);
$mail->Subject = "subject ";
$mail->Body = "something.";
$mail_to = $email;
$mail->AddAddress($mail_to);
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
}
我该如何解决这个错误。
【问题讨论】:
-
在 $mail->Username 中输入有效的 gmail id,在 $mail->Password 中输入密码