【问题标题】:PHPMailer doesnt give error messages or send emails just a white screenPHPMailer 不给出错误消息或发送电子邮件只是一个白屏
【发布时间】:2015-03-17 14:54:49
【问题描述】:

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

【问题讨论】:

  • 黑屏 (又名死机白屏):在打开 PHP 标记后立即将错误报告添加到文件顶部,例如 &lt;?php error_reporting(E_ALL); ini_set('display_errors', 1); 然后其余的代码,看看它是否产生任何东西。
  • 如果你使用最新的 PHPMailer,只加载主类而不是自动加载器,然后尝试使用 SMTP,它将无法工作。阅读文档,这在自述文件示例中。
  • @Fred 我添加了代码,但仍然出现白屏。 @Synchro 我也尝试过自动加载器,我也尝试过将 class.smtp.php 放在一起,这三个都没有区别...
  • 在脚本开头添加echo 'hello';,然后逐渐向下移动,直到看不到它。这会告诉你脚本哪里出错了。

标签: php email phpmailer


【解决方案1】:

这个

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

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

应该是这样的;

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

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

您尚未在代码中初始化 $mail 变量,但您正尝试在不存在的对象上设置 $mail-&gt;SMTPDebug = 3;

编辑

代码中的另一个错字。 if (!mail-&gt;send()){ 行缺少 $ 变量声明。确保它显示为if (!$mail-&gt;send()){

【讨论】:

  • 是的,你是对的。我也改变了它,但仍然没有。感谢您指出这一点。
  • 查看我的编辑。您还缺少来自$mail-&gt;send()$。那应该修复你的WSOD。但是,如果还有更多错误,那么按照其他 cmets 中的建议打开错误报告应该会有所帮助。
  • 就是这样。工作正常。谢谢你们。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-30
  • 1970-01-01
相关资源
最近更新 更多