PHP邮件程序在实时服务器上不起作用


PHP mailer not working on live server

我的PHP邮件程序有问题,PHP邮件程序在我的本地主机中工作,但它在实时服务器上不起作用

这是我的邮件.php

 <?php require("phpmailer/class.phpmailer.php"); // path to the PHPMailer class
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "user@gmail.com"; // SMTP username
$mail->Password = "pswd"; // SMTP password
$mail->From = "example@gmail.com";
$mail->AddAddress("user@gmail.com");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Youy payment received";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'message not send';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent.';
}
?>

当我在服务器上运行它时,它会显示此错误

SMTP Error: Could not authenticate. Message was not sent.Mailer error: SMTP Error: Could not authenticate.

请帮助我

谢谢

尝试查找$mail->IsSMTP();告诉类使用 SMTP 的行并将其删除或注释,如下所示:

//$mail->IsSMTP();

这样它就可以工作

@briosheje 是的,我确定我的用户名和密码是正确的,并且我的密码不包含任何特殊字符 – user2894216

可能,您还必须将用户名设置为from字段

$mail->Username = "user2894216"; // SMTP username
$mail->Password = "pswd"; // SMTP password
$mail->From = "user2894216";

顺便说一句,对于Gmail ssl://smtp 邮件服务不需要编写域。仅用户名