2

我有下面的课。它可以很好地独立运行(没有 zend 骨架),但是当我尝试将它放在 zend 骨架的控制器中时,我得到了一个错误。在同一台服务器上,它在没有 zend MVC 的情况下运行良好,因此似乎没有 ssl 或 tsl 配置。在 Zend 骨架环境中似乎有些。

抱歉英语不好。

谢谢!

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

class SendMail
{
    public function send()
    {
        $message = new Message();
        $message->addTo('raoniforapp@gmail.com');
        $message->addFrom('raoniforapp@gmail.com');
        $message->setSubject('Greetings and Salutations!');
        $message->setBody("Sorry, I'm going to be late today!");

        $transport = new Smtp();
        $options = new SmtpOptions([
            'name' => 'smtp.gmail.com',
            'host' => 'smtp.gmail.com',
            'connection_class' => 'login',
            'port' => 587,
            'connection_config' => [
                'username' => 'my@gmail.com',
                'password' => 'mypass',
                'ssl' => 'tls'
            ],
        ]);
        $transport->setOptions($options);

        var_dump($transport);
        $transport->send($message);
    }
}

控制器:

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class ContactFormController extends AbstractActionController
{
    protected $sendMail;
    public function __construct($sendMail)
    {
        $this->sendMail = $sendMail;
    }

    public function indexAction()
    {
        $this->sendMail->send();

        return new ViewModel();
    }
}

我得到错误:

An error occurred
An error occurred during execution; please try again later.
Additional information:

Zend\Mail\Protocol\Exception\RuntimeException

File:

/var/www/ContactForm/vendor/zendframework/zend-mail/src/Protocol/AbstractProtocol.php:215

Message:

Could not open socket

Stack trace:

#0 /var/www/ContactForm/vendor/zendframework/zend-mail/src/Protocol/Smtp.php(149): Zend\Mail\Protocol\AbstractProtocol->_connect('tcp://smtp.gmai...')
#1 /var/www/ContactForm/vendor/zendframework/zend-mail/src/Transport/Smtp.php(376): Zend\Mail\Protocol\Smtp->connect()
#2 /var/www/ContactForm/vendor/zendframework/zend-mail/src/Transport/Smtp.php(362): Zend\Mail\Transport\Smtp->connect()
#3 /var/www/ContactForm/vendor/zendframework/zend-mail/src/Transport/Smtp.php(373): Zend\Mail\Transport\Smtp->lazyLoadConnection()
#4 /var/www/ContactForm/vendor/zendframework/zend-mail/src/Transport/Smtp.php(230): Zend\Mail\Transport\Smtp->connect()
#5 /var/www/ContactForm/module/ContactForm/src/Mail/SendMail.php(34): Zend\Mail\Transport\Smtp->send(Object(Zend\Mail\Message))
#6 /var/www/ContactForm/module/ContactForm/src/Controller/ContactFormController.php(32): ContactForm\Mail\SendMail->send()
#7 /var/www/ContactForm/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php(78): ContactForm\Controller\ContactFormController->indexAction()
#8 /var/www/ContactForm/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#9 /var/www/ContactForm/vendor/zendframework/zend-eventmanager/src/EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#10 /var/www/ContactForm/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(105): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#11 /var/www/ContactForm/vendor/zendframework/zend-mvc/src/DispatchListener.php(119): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#12 /var/www/ContactForm/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#13 /var/www/ContactForm/vendor/zendframework/zend-eventmanager/src/EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#14 /var/www/ContactForm/vendor/zendframework/zend-mvc/src/Application.php(332): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#15 /var/www/ContactForm/public/index.php(48): Zend\Mvc\Application->run()
#16 {main}
4

0 回答 0