【发布时间】:2020-06-11 15:43:57
【问题描述】:
我不确定我做错了什么。我已逐行遵循教程,但不确定我为什么会收到此错误。我的php邮件代码如下。
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require dirname($_SERVER['DOCUMENT_ROOT'])."/private/PHPMailer-master/src/Exception.php";
require dirname($_SERVER['DOCUMENT_ROOT'])."/private/PHPMailer-master/src/PHPMailer.php";
require dirname($_SERVER['DOCUMENT_ROOT'])."/private/PHPMailer-master/src/SMTP.php";
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'a2plcp473.prod.iad.secureserver.net';
$mail->SMTPAuth = true;
$mail->Username = 'ew@myemail.com';
$mail->Password = 'xxx';
$mail->SMTPSecure = 'tls' ;
$mail->Port = 465;
//Recipients
$mail->setFrom('ew@mymail.com', 'Name');
$mail->addAddress('ew@othermail.com', 'Name');
$mail->addReplyTo('ew@othermail.com', 'Name');
// 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}";
}
我知道我的文件路径是正确的,因为我在每个文件中都放了一个回显“This”,它回显到屏幕上。所以路径是正确的。
我得到的错误是:
Fatal error: Uncaught Error: Class 'SMTP' not found in
/home/xxx/public_html/public/internal/mail.php:23 Stack trace: #0 {main} thrown in
/home/xxx/public_html/public/internal/mail.php on line 23
第 23 行是:
$mail->isSMTP();
我被困在这里。这两天我一直在网上寻找解决方案。任何帮助,将不胜感激。谢谢。我也知道堆栈上还有其他类似的帖子,但我已经尝试了所有这些但无法让它工作。同样,它们中的大多数是为使用作曲家的人准备的,而我没有使用作曲家,我只包括文件路径。他们中的大多数也使用最近被弃用的自动加载器。请帮忙。谢谢。
【问题讨论】:
-
我的建议:学习使用composer。它会让你的生活更轻松。旧的 PHPMailer 自动加载器在 3 年前被弃用,而不是最近。