使用此代码:
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);
我收到了这个错误:
Fatal error: Class 'Zend\Validator\ValidatorChain' not found in PHP\vendor\zendframework\zend-mail\Zend\Mail\Protocol\AbstractProtocol.php on line 97
这是错误的完整流程:
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
我尝试了文档中的每个示例,但它们都不起作用,并且我得到了同样的错误。我以为是因为我在本地测试它,但是当我将它上传到服务器上时它不起作用。我正在 wamp 上测试这个。有谁知道导致此错误的原因以及如何解决?