php - 包含类时未找到 PHPMailer 类
问题描述
我已经从 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$
我究竟做错了什么?
解决方案
PHPMailer 默认位于 PHPMailer\PHPMailer 命名空间中,您可以使用use
关键字将其带入全局命名空间。例如在他们的simple_contact_form示例中:
<?php
//Import the PHPMailer class into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
推荐阅读
- amazon-web-services - 在私有 VPC 中使用 EC2 实例配置内部网络负载均衡器
- javascript - 如何在 apache 服务器上部署没有 index.html 的 react 应用程序以进行生产
- java - Spring 4中如何处理多个ClientHttpRequestInterceptor
- docker - 使用 Docker Compose 的微服务:同一个容器,多个项目
- python-3.x - 在 python 中导入 open cv 的问题
- nativescript - 单击按钮时在 Nativescript + Angular 中获取 TimePicker 小部件中的小时和分钟
- grails - 如何在不连接到 Internet 的情况下运行 grails
- github - 一次将协作者添加到多个存储库
- css - 如何在没有很多类的情况下使页脚保持在每个页面的底部?
- python - 在 PySpark 中将 csv 加载到 DataFrame 时出现问题