我正在尝试使用phpmailer发送邮件。mail->Send返回true,但邮件未送达
<?php
try {
require_once('include/class.phpmailer.php');
$mail = new PHPMailer(true);
$mail->MailerDebug = true;
$mail->IsSendmail();
$mail->From = "library@capitalvia.com";
$mail->FromName = "Library | CapitalVia";
$mail->AddAddress("kanhaiya.lal@capitalvia.com", "Kanhaiyalal");
$mail->AddReplyTo("library@capitalvia.com", "Library | CapitalVia");
$mail->IsHTML(true);
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if ($mail->Send())
echo "Message has been sent";
} catch (phpmailerException $e) {
echo $e->errorMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
?>发布于 2015-09-07 18:01:12
我的第一个猜测是您忘记了配置smtp服务器。如果没有提供smtp服务器,PHPMailer类将无法发送电子邮件。尝试添加如下所示的内容:
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
// OR this if authentication is needed
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "yourname@yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password此信息可在电子邮件应用程序(Outlook、Mail、Thunderbird等)中电子邮件帐户的配置/属性中找到。
This是Gmail的一个例子。
https://stackoverflow.com/questions/32435190
复制相似问题