简体   繁体   中英

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

There is only one error (Undefined type 'PHPMailer\PHPMailer\PHPMailer'). In this line: $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. 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. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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