phpswiftmailer

SwiftMailer ReflectionException: Class Egulias\EmailValidator\EmailValidator does not exist


SwiftMailer: Reflection exception

I've been trying to figure out this error for a half a day and feel like I've tried everything. I literally copied the code from SwiftMailer's Website for the section I was having trouble with, but it is still getting the ReflectionException.

Some Background Details:

Php Version: 7

Swiftmailer Version: 6.0.0


PHP Code Using SwiftMailer

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(['john@doe.com' => 'John Doe'])
  ->setTo(['receiver@domain.org', 'other@domain.org' => 'A name'])
  ->setBody('Here is the message itself')

The Error I'm getting

[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

I'm itching to figure this out. Thanks in advance to anyone who comments or answers this


Solution

  • You're missing egulias/email-validator package.

    In composer.json of SwiftMailer you can see that it has this dependency.

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