SwiftMailer ReflectionException:类 Egulias\EmailValidator\EmailValidator 不存在

问题描述 投票:0回答:3

SwiftMailer:反射异常

我花了半天时间试图找出这个错误,感觉我已经尝试了一切。我从 SwiftMailer 的网站复制了我遇到问题的部分的代码,但它仍然收到 ReflectionException。

一些背景细节:

PHP 版本:7

Swiftmailer 版本:6.0.0


使用 SwiftMailer 的 PHP 代码

require_once 'swiftmailer-master/lib/swift_required.php';

$transport = (new Swift_SmtpTransport('smtp.gmail.com', 465, "ssl"))
  ->setUsername('my_gmail_username')
  ->setPassword('my_gmail_password');

$mailer = new Swift_Mailer($transport);

$message = (new Swift_Message())
  ->setSubject('Your subject')
  ->setFrom(['[email protected]' => 'John Doe'])
  ->setTo(['[email protected]', '[email protected]' => 'A name'])
  ->setBody('Here is the message itself')

我遇到的错误

[07-Jun-2017 17:31:28 America/New_York] PHP Fatal error:  Uncaught 
ReflectionException: Class Egulias\EmailValidator\EmailValidator does not 
exist in /home/johnjpra/public_html/php/swiftmailer-
master/lib/classes/Swift/DependencyContainer.php:309
Stack trace:
#0 /home/johnjpra/public_html/php/swiftmailer-
master/lib/classes/Swift/DependencyContainer.php(309): ReflectionClass-
>__construct('Egulias\\EmailVa...')
#1 /home/johnjpra/public_html/php/swiftmailer-
master/lib/classes/Swift/DependencyContainer.php(323): 
Swift_DependencyContainer->createNewInstance('email.validator')
#2 /home/johnjpra/public_html/php/swiftmailer-
master/lib/classes/Swift/DependencyContainer.php(114): 
Swift_DependencyContainer->createSharedInstance('email.validator')
#3 /home/johnjpra/public_html/php/swiftmailer-
master/lib/classes/Swift/DependencyContainer.php(371): 
Swift_DependencyContainer->lookup('email.validator')
#4 /home/johnjpra/public_html/php/swiftmailer-
master/lib/classes/Swift/DependencyContainer.php(348): 
Swift_DependencyContainer->lookupRecursive('email.validator')
#5 /home/johnjpra/pu in /home/johnjpra/public_html/php/swiftmailer-
master/lib/classes/Swift/DependencyContainer.php on line 309

我很想弄清楚这一点。预先感谢任何评论或回答此问题的人

php swiftmailer
3个回答
2
投票

您缺少

egulias/email-validator
包裹。

在 SwiftMailer 的

composer.json
中你可以看到它有这个依赖。

"require": {
    "php": ">=7.0.0",
    "egulias/email-validator": "~2.0"
},

0
投票

我知道这是一个两年前的问题,但我最近遇到了这个问题。

问题似乎在于包中的某个位置被设置为绝对路径而不是相对路径。

我通过将所需的composer.json复制到我正在工作的文件夹中解决了这个问题。然后我进行了composer安装。不久之后我就有了一个可以工作的 swiftmailer。


-1
投票

@user2365531 你好,我有验证器的文件,但仍然有错误; 类 Egulias\EmailValidator\EmailValidator 不存在 你还有改变什么吗?

© www.soinside.com 2019 - 2024. All rights reserved.