【发布时间】:2020-06-03 06:45:35
【问题描述】:
我有 sendnewmail 功能使用它发送邮件,在邮件消息中发送消息显示但在 gmail 中它不来,这是代码
function sendnewmail($msgnew,$emailidnew,$subjectnew){
require_once("class.phpmailer.php");
require_once("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "mail.domain.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username ="user"; // SMTP username
$mail->Password ="password"; // SMTP password
$mail->From = "abcds@gmail.com";
$mail->FromName = "name";
$mail->AddAddress($emailidnew,"sudeshna");
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $subjectnew;
$mail->Body = $msgnew;
if(!$mail->Send()) {
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}else{
echo 'Message send ok';
}
}
$htmldetails ="Welcome to World";
$email = "abc@gmail.com";
$subject = "Sample welcome message";
sendnewmail($htmldetails,$email,$subject);
【问题讨论】:
-
在 gmail 中它不来 你是否使用 gmail 作为 smtp 服务器?话虽这么说,为了测试,最好使用本地服务器(例如fakesmtp),这样您就可以确定应用程序实际上首先发送电子邮件,然后您可以担心 smtp 服务器稍后丢弃您的邮件(由于原因,例如垃圾邮件)。 .
-
邮件发送到 gmail (abc@gmail.com) 账户
-
您使用的是旧版本的 PHPMailer。 Get the latest。如果您通过 gmail 发送,请将您的代码基于the gmail example provided,并阅读the troubleshooting guide。