【发布时间】:2015-08-21 03:55:07
【问题描述】:
我正在使用 PHP 邮件程序通过 gmail 从本地主机发送电子邮件,这是我的代码,但主要问题是,当我运行脚本时,没有显示任何错误,并且我没有收到任何 gmail id 的电子邮件
include("email/class.phpmailer.php");
$mail = new PHPMailer();
$body = "This is just a Test Email";
$mail->IsSMTP();
// enable SMTP authentication
$mail->SMTPAuth = true;
// sets GMAIL as the SMTP server
$mail->Host = "smtp.gmail.com";
// set the SMTP port for the GMAIL server
$mail->Port = 465;
// GMAIL username
$mail->Username = "Mygmail id";
// GMAIL password
$mail->Password = "password";
$mail->From = "Mygmail id";
$mail->FromName = "My Name";
$mail->Subject = "Testing Message";
$mail->AltBody = "To view the message, please use an HTML compatible
email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddAddress("Receiver Gmail Id");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
请不要重复我的问题,因为我尝试了所有其他答案,但没有找到任何解决方案
【问题讨论】:
-
它是重复的,这被广泛覆盖in the docs,您使用的是旧版本的 PHPMailer,并且未能使用the gmail example provided。一般来说,看起来你并没有很努力。
标签: email smtp gmail phpmailer