我不知道为什么会收到此“PHPMailer 未定义类型”错误。首先,我尝试直接下载zip并从github复制代码,同样的问题出现,然后我下载了我不想下载的composer,但下载后仍然显示相同的错误。
请问我可以对此有什么想法吗? (以下截图)
这是代码
session_start();
// Import PHPMailer classes into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
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 = '[email protected]'; // 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
谢谢
当你使用 Composer 时,只需要自动加载(它完成所有“需要”的工作)
include_once 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// require 'PHPMailer/src/Exception.php'; < -- this is no longer used