简体   繁体   English

为什么我在 PHPMailer 的代码中出现错误?

[英]Why am I getting an error in the code from PHPMailer?

There is only one error (Undefined type 'PHPMailer\PHPMailer\PHPMailer').只有一个错误(未定义类型'PHPMailer\PHPMailer\PHPMailer')。 In this line: $mail = new PHPMailer(TRUE);.在这一行中:$mail = new PHPMailer(TRUE);。 I tried to install with composer and manually but nothing helped.我尝试使用作曲家手动安装,但没有任何帮助。

<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';

if (isset($_POST['password-reset-token']) && $_POST['email']) {

include "connect.php";

    require_once('phpmail/PHPMailerAutoload.php');

    $mail = new PHPMailer(TRUE);
    $mail->CharSet =  "utf-8";
    $mail->IsSMTP();

PHPMailerAutoload.php is a very old file that was dropped from PHPMailer years ago. PHPMailerAutoload.php是多年前从 PHPMailer 中删除的一个非常古老的文件。 You should not be using it, and it's very likely to be interfering with your code.您不应该使用它,它很可能会干扰您的代码。 Let composer deal with the class loading for you – it's what it's for.让 composer 为您处理 class 加载 - 这就是它的用途。 I recommend getting the latest version, and basing your code on the examples provided with PHPMailer, and read the docs on how to load it and create an instance .我建议获取最新版本,并将您的代码基于 PHPMailer 提供的示例,并阅读有关如何加载它和创建实例的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM