Question

Using this code :

include('vendor/autoload.php');

use Zend\Mail\Message;
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;

$message = new Message();
$message->addTo('email to')
        ->addFrom('email from')
        ->setSubject('Greetings and Salutations!')
        ->setBody("Sorry, I'm going to be late today!");


$transport = new SmtpTransport();
$options   = new SmtpOptions(array(
    'name'              => 'gmail.com',
    'host'              => 'smtp.gmail.com',
    'port'              => 465, // Notice port change for TLS is 587
    'connection_class'  => 'smtp',
    'connection_config' => array(
        'username' => 'email from',
        'password' => 'pass',
        'ssl'      => 'tls'
    ),
));
$transport->setOptions($options);
$transport->send($message);

I got this error:

Fatal error: Class 'Zend\Validator\ValidatorChain' not found in PHP\vendor\zendframework\zend-mail\Zend\Mail\Protocol\AbstractProtocol.php on line 97

Here is full flow of error:

1   0.0003  252376  {main}( )   ..\sendEmail.php:0
2   0.0084  787416  Zend\Mail\Transport\Smtp->send( )   ..\sendEmail.php:31
3   0.0084  787688  Zend\Mail\Transport\Smtp->connect( )    ..\Smtp.php:205
4   0.0084  787856  Zend\Mail\Transport\Smtp->lazyLoadConnection( ) ..\Smtp.php:336
5   0.0084  788736  Zend\Mail\Transport\Smtp->plugin( ) ..\Smtp.php:322
6   0.0122  1104552 Zend\ServiceManager\AbstractPluginManager->get( )   ..\Smtp.php:137
7   0.0122  1105248 Zend\ServiceManager\ServiceManager->get( )  ..\AbstractPluginManager.php:103
8   0.0122  1106184 Zend\ServiceManager\ServiceManager->create( )   ..\ServiceManager.php:481
9   0.0122  1106392 Zend\ServiceManager\ServiceManager->doCreate( ) ..\ServiceManager.php:557
10  0.0122  1106664 Zend\ServiceManager\AbstractPluginManager->createFromInvokable( )   ..\ServiceManager.php:602
11  0.0140  1275976 Zend\Mail\Protocol\Smtp\Auth\Login->__construct( )  ..\AbstractPluginManager.php:172
12  0.0140  1276120 Zend\Mail\Protocol\Smtp->__construct( ) ..\Login.php:65
13  0.0140  1276264 Zend\Mail\Protocol\AbstractProtocol->__construct( ) ..\Smtp.php:14

5

I tried every example from documentation but none of them work and I got same error for all. I thought it is because I am testing it locally but it won't work when I upload it on server. I am testing this on wamp. Does anyone know what cause this error and how to fix it?

Was it helpful?

Solution

If you require zendframework/zend-mail via composer, there is a suggestion for zendframework/zend-validator. The validator is required if you want to send any emails.

So update your composer.json, add zend-validator as package and run composer update. This will load the Validator component so you can run your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top