首页  >  问答  >  正文

遇到PHPMailer未定义类型错误(尝试使用Composer也无效)

我不知道为什么会收到此“PHPMailer 未定义类型”错误。首先,我尝试直接下载zip并从github复制代码,同样的问题出现,然后我下载了我不想下载的composer,但下载后仍然显示相同的错误。

请问我可以对此有什么想法吗? (以下截图)

作曲家 img 错误

没有作曲家img时出现同样的错误

目录图片

这是代码

session_start();

// Import PHPMailer classes into the global namespace 
use PHPMailerPHPMailerPHPMailer; 
use PHPMailerPHPMailerException; 
 
require 'PHPMailer/src/Exception.php'; 
require 'PHPMailer/src/PHPMailer.php'; 
require 'PHPMailer/src/SMTP.php'; 
 
$mail = new PHPMailer(true);   // error coming here
 
$mail->isSMTP();                      // Set mailer to use SMTP 
$mail->Host = 'smtp.gmail.com';       // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;               // Enable SMTP authentication 
$mail->Username = 'user@gmail.com';   // SMTP username 
$mail->Password = 'gmail_password';   // SMTP password 
$mail->SMTPSecure = 'tls';            // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587;                    // TCP port to connect to 
 
// Sender info

谢谢

P粉921165181P粉921165181316 天前600

全部回复(1)我来回复

  • P粉734486718

    P粉7344867182023-11-13 16:24:48

    当您使用作曲家时,只需要自动加载(它完成所有“需要”工作)

    include_once 'vendor/autoload.php'
    use PHPMailer\PHPMailer\PHPMailer; 
    use PHPMailer\PHPMailer\Exception;
    
    // require 'PHPMailer/src/Exception.php'; < -- this is no longer used

    回复
    0
  • 取消回复