我已经从github安装了PHPMailer作为master.zip下载文件。
当我在下面使用它
<?php
require "PHPMailer.php"; //include phpmailer class
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "ssl"; // Connect using a TLS connection
$mail->Host = "smtp.gmail.com"; //Gmail SMTP server address
$mail->Port = 465; //Gmail SMTP port
$mail->Encoding = '7bit';
我得到以下
ubuntu@ip-172-31-35-156:/opt/PHPMailer-master/src$ php test.php
PHP Fatal error: Uncaught Error: Class 'PHPMailer' not found in /opt/PHPMailer-master/src/test.php:6
Stack trace:
#0 {main}
thrown in /opt/PHPMailer-master/src/test.php on line 6
ubuntu@ip-172-31-35-156:/opt/PHPMailer-master/src$
我在做什么错了?
答案 0 :(得分:4)
PHPMailer默认情况下位于PHPMailer \ PHPMailer命名空间中,您可以使用use
关键字将其引入全局命名空间。例如,在他们的simple_contact_form示例中:
<?php
//Import the PHPMailer class into the global namespace
use PHPMailer\PHPMailer\PHPMailer;