PHPMailer不会发出错误信息或发送电子邮件,只是一个白色屏幕


PHPMailer doesnt give error messages or send emails just a white screen

我正在尝试使用PHP mailer发送电子邮件。什么都没发生,我得到的只是网络浏览器中的一个白色屏幕。我使用了不同的代码示例,将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!';
}
?>

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()){