我的PHP邮件程序有问题,PHP邮件程序在我的localhost中运行,但它不能在实时服务器上运行
这是我的mailer.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.
请帮帮我
由于
答案 0 :(得分:0)
@briosheje是的我确定我的用户名和密码是正确的,我的密码不包含任何特殊字符 - user2894216
可能您也要从字段
设置用户名$mail->Username = "user2894216"; // SMTP username
$mail->Password = "pswd"; // SMTP password
$mail->From = "user2894216";
btw,对于gmail ssl:// smtp邮件服务不需要写域。只有用户名
答案 1 :(得分:0)
尝试查找行$mail->IsSMTP();
,告诉班级使用SMTP并将其删除或注释如下:
//$mail->IsSMTP();
它会起作用