PHPMailer不提供错误消息或仅发送白色屏幕的电子邮件

时间:2015-03-17 14:54:49

标签: php email phpmailer

我正在尝试使用PHP邮件发送电子邮件。我得到的一切都是网页浏览器中的白屏。我已经使用了不同的代码更改ssl的示例到tls端口587到465使用需要autoload.php phpmailer.php smtp.php我能找到的任何东西,以获得问题所在的指示。代码与https://subinsb.com/send-mails-via-smtp-server-gmail-outlook-php上的代码完全相同,除了电子邮件凭据等。您可能拥有的任何想法或者如果您看到我不感兴趣的内容,我们将不胜感激。

<?php
$account = "xxxxxxxxx@gmail.com";
$password = 'xxxxxx';
$from = 'xxxxxxxx@gmail.com';
$from_name = 'Adam Johnson';
$subject = 'Test';
$msg = 'This is a test';
$to = "xxxxxxxxx@hotmail.com";

require ('/PHPMailer/class.phpmailer.php');

$mail->SMTPDebug = 3;
$mail = new PHPMailer();
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Port = 587;
$mail->Username = $account;
$mail->Password = $password;
$mail->SMTPSecure = 'tls';
$mail->From = $from;
$mail->FromName = $from_name;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->addAddress($to);

if (!mail->send()){
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else {
echo 'Message sent!';
}
?>

1 个答案:

答案 0 :(得分:0)

require ('/PHPMailer/class.phpmailer.php');

$mail->SMTPDebug = 3;
$mail = new PHPMailer();

应该是这样的;

require ('/PHPMailer/class.phpmailer.php');

$mail = new PHPMailer();
$mail->SMTPDebug = 3;

您尚未在代码中草拟$mail变量,但您尝试在不存在的对象上设置$mail->SMTPDebug = 3;

修改

代码中还有一个拼写错误。第if (!mail->send()){行缺少$变量声明。确保它显示为if (!$mail->send()){