[英]PHPMailler error (The page cannot be displayed because an internal server error has occurred.)
I am trying to develop a form and send to email using phpmailer. 我正在尝试开发一种形式,并使用phpmailer发送到电子邮件。 sender email is Gmail. 发件人电子邮件是Gmail。 Below are my php code: 以下是我的PHP代码:
<?php
use PHPMailer\PHPMailer;
use PHPMailer\Exception;
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 4;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'thisismy@gmail.com';
$mail->Password = 'xxxxxxxx';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
//Recipients
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('receiver@gmail.com');
//Content
$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';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
I get this error The page cannot be displayed because an internal server error has occurred. 我收到此错误,因为发生了内部服务器错误,所以无法显示该页面。 *not using localhost *不使用本地主机
Read the PHPMailer readme that tells you how to load PHPMailer, and base your code on the examples provided. 阅读PHPMailer自述文件,该自述文件告诉您如何加载PHPMailer,并将代码基于提供的示例。 You are using PHPMailer 6 syntax, but trying to load it like PHPMailer 5, and the old autoloader does not exist, and trying to require it is a fatal error. 您正在使用PHPMailer 6语法,但尝试像PHPMailer 5一样加载它,并且旧的自动加载器不存在,并且尝试要求它是一个致命错误。
You would have found this out if you had read the most basic PHP debugging guide that would have told you to enable display of error messages, or to check your web server logs. 如果您已经阅读了最基本的PHP调试指南,该指南将告诉您启用错误消息显示或检查Web服务器日志,那么您将发现这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.