使用此代码:
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
我尝试了documentation的每一个例子,但是没有一个能够工作,我得到了同样的错误。 我认为这是因为我在本地测试它,但是当我在服务器上传它时它将无法工作。我在wamp上测试这个。 有谁知道导致此错误的原因以及如何修复它?
答案 0 :(得分:3)
如果您需要zendframework/zend-mail
通过作曲家,则有zendframework/zend-validator
的建议。如果您想发送任何电子邮件,则需要验证器。
因此,请更新您的composer.json,将zend-validator添加为包并运行composer update
。这将加载Validator组件,以便您可以运行代码。