【问题标题】:Installing PHPMailer with Composer [duplicate]使用 Composer 安装 PHPMailer [重复]
【发布时间】:2022-01-15 20:05:26
【问题描述】:

我觉得我快到了。 (虽然我可能是错的)

从我的 apache 服务器的根目录 (/usr/local/var/www)

我跑了

composer require phpmailer/phpmailer

我现在有了文件夹系统

/usr/local/var/www/vendor/phpmailer/phpmailer

在这个文件夹中,有一个src 文件夹,在那个文件夹中基本上是我认为我需要包含在我想使用PHPmailer 的php 页面上的所有文件。

在我想使用 PHPMailer 的 PHP 页面上,我在顶部有:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

在我正在调用的页面中

$mail = new PHPMailer(true); //Argument true in constructor enables exceptions

我收到一条错误消息

Error: Class "PHPMailer\PHPMailer\PHPMailer" not found in /usr/local/var/www/xxx.php

似乎有些东西连接不正确。

【问题讨论】:

  • 您需要获取 composer 的自动加载器,通常通过 require_once 'vendor/autoload.php'; 之类的方式。
  • 添加三行:require './Exception.php'; require './PHPMailer.php'; require './SMTP.php';之后use PHPMailer\PHPMailer\Exception;(请更改为3个文件的实际路径),重试看看会发生什么

标签: php apache composer-php phpmailer


【解决方案1】:

Alex Howansky 发布a comment

您需要获取 composer 的自动加载器,通常通过 require_once 'vendor/autoload.php'; 之类的方式获取。

Ken Leea comment:

use PHPMailer\PHPMailer\Exception;之后添加三行:require './Exception.php'; require './PHPMailer.php'; require './SMTP.php';(请改成3个文件的实际路径),重试看看会发生什么

这两个建议都解决了问题。我将使用 vendor/autoload.php 解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-24
    • 2018-07-30
    • 2015-09-26
    • 2020-07-27
    • 2014-10-24
    • 2013-07-16
    • 2023-03-15
    • 2021-06-05
    相关资源
    最近更新 更多