【问题标题】:PHPMailer: Classname not found when trying to use Gmail's SMTPPHPMailer:尝试使用 Gmail 的 SMTP 时找不到类名
【发布时间】:2017-08-19 01:31:45
【问题描述】:

我已经尝试让 PHPMailer 工作大约一周了。起初我没有使用 SMTP,但由于 PHP 权限,我不得不更改它。

由于使用的电子邮件地址似乎是通过 Gmail 购买的(它具有不同的域,而不是 @gmail.com),我认为最好使用 Google 的 Gmail SMTP 服务。 (这里解释https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2

由于缺乏经验并且缺乏通过命令行访问我的主机的任何方法,我使用本地安装的 composer 版本获得了所有必要的软件包,并通过 FTP 将所有依赖项复制到我的主机。我当前的文件夹结构现在是这样的:

/phpmailer
/phpmailer/extras/
/phpmailer/language/
/phpmailer/vendor/
/phpmailer/vendor/composer/
/phpmailer/vendor/eloquent/
/phpmailer/vendor/guzzlehttp/
/phpmailer/vendor/league/
/phpmailer/vendor/paragonie/
/phpmailer/vendor/phpmailer/
/phpmailer/vendor/psr/
/phpmailer/vendor/autoload.php

但是,我不断收到以下错误:

致命错误:在第 55 行的 /domain/phpmailer/class.phpmaileroauthgoogle.php 中找不到类“League\OAuth2\Client\Provider\Google”

它看起来好像在某处缺少包含或要求,所以我尝试添加 require('vendor/autoload.php');在我处理应该启动邮件过程的表单的 PHP 中,但它似乎没有解决任何问题。而且我也不认为有必要在 /phpmailer/ 中的文件中添加类似的内容。

我返回的其余日志如下所示:

2017-03-26 10:23:52 服务器 -> 客户端:220 smtp.gmail.com ESMTP e16sm10314377wra.62 - gsmtp 2017-03-26 10:23:52 客户端 -> 服务器:EHLO www.domain。 com 2017-03-26 10:23:53 服务器-> 客户端:250-smtp.gmail.com 为您服务,[2a0b:7280:100:0:447:56ff:fe00:207b] 250-SIZE 35882577 250- 8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-流水线 250-CHUNKING 250 SMTPUTF8 2017-03-26 10:23:53 客户端 -> 服务器:STARTTLS 2017-03-26 10:23:53 服务器 -> 客户端:220 2.0.0准备启动 TLS 2017-03-26 10:23:53 CLIENT -> SERVER: EHLO www.domain.com 2017-03-26 10:23:53 SERVER -> CLIENT: 250-smtp.gmail.com 为您服务, [2a0b:7280:100:0:447:56ff:fe00:207b] 250-SIZE 35882577 250-8BITMIME 250-AUTH 登录 PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-SMTP UTF8-250- >

这似乎不是身份验证的问题。

这是 composer.json 中的内容:

{
"name": "phpmailer/phpmailer",
"type": "library",
"description": "PHPMailer is a full-featured email creation and transfer class for PHP",
"authors": [
    {
        "name": "Marcus Bointon",
        "email": "phpmailer@synchromedia.co.uk"
    },
    {
        "name": "Jim Jagielski",
        "email": "jimjag@gmail.com"
    },
    {
        "name": "Andy Prevost",
        "email": "codeworxtech@users.sourceforge.net"
    },
    {
        "name": "Brent R. Matzelle"
    }
],
"require": {
    "php": ">=5.0.0",
    "phpmailer/phpmailer": "^5.2",
    "league/oauth2-client": "^2.2",
    "league/oauth2-google": "^2.0"
},
"require-dev": {
    "doctrine/annotations": "1.2.*",
    "jms/serializer": "0.16.*",
    "phpdocumentor/phpdocumentor": "2.*",
    "phpunit/phpunit": "4.8.*",
    "symfony/debug": "2.8.*",
    "symfony/filesystem": "2.8.*",
    "symfony/translation": "2.8.*",
    "symfony/yaml": "2.8.*",
    "zendframework/zend-cache": "2.5.1",
    "zendframework/zend-config": "2.5.1",
    "zendframework/zend-eventmanager": "2.5.1",
    "zendframework/zend-filter": "2.5.1",
    "zendframework/zend-i18n": "2.5.1",
    "zendframework/zend-json": "2.5.1",
    "zendframework/zend-math": "2.5.1",
    "zendframework/zend-serializer": "2.5.*",
    "zendframework/zend-servicemanager": "2.5.*",
    "zendframework/zend-stdlib": "2.5.1"
},
"suggest": {
    "league/oauth2-google": "Needed for Google XOAUTH2 authentication"
},
"autoload": {
    "classmap": [
        "class.phpmailer.php",
        "class.phpmaileroauth.php",
        "class.phpmaileroauthgoogle.php",
        "class.smtp.php",
        "class.pop3.php",
        "extras/EasyPeasyICS.php",
        "extras/ntlm_sasl_client.php"
    ]
},
"license": "LGPL-2.1"
}

我错过了什么吗?

【问题讨论】:

  • 你能发布你的作曲家json文件的内容吗?因为它控制哪些模块和类被添加到你的 php 的类路径中。
  • 嗨,我在最初的帖子中添加了 composer.json 的内容
  • 我认为您的问题与这篇文章有关:stackoverflow.com/a/69487739/5810125

标签: php email phpmailer


【解决方案1】:

(编辑:抱歉,我没有看到您已经将依赖项添加到您的 composer.json)

这个额外的依赖确实应该在您自己的应用程序的composer.json(不是 PHPMailer 的)中,因为您永远不需要编辑通过 composer 加载的包。您可能只需要运行composer update(不仅仅是composer install)。否则它只会加载最新的composer.lock 文件中的包,而不是您添加的额外包。

【讨论】:

  • 您好,非常感谢您的回复。我确实运行了composer update 并将结果更新传输到我的主机,但它仍然显示Fatal error: Class 'League\OAuth2\Client\Provider\Google' not found in /phpmailer/class.phpmaileroauthgoogle.php on line 55。您指的是什么依赖项应该在我自己的应用程序的 json 文件中?据我所知,我只有一个composer.json,它位于/phpmailer/。
  • 如果我更新作曲家,我会得到一个内容少得多的composer.json。它只包含“require: { ... }”
猜你喜欢
  • 2022-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多