symfony smtp - 无法与主机建立连接

时间:2018-01-29 09:11:56

标签: php linux symfony smtp

我正在尝试通过symfony发送消息(smtp)。

$ transport = \ Swift_SmtpTransport ('my_host', 587, 'ssl')
-> SetUserName ('my_username')
-> SetPassword ('my_password');

我收到消息[无法与主机建立连接] 访问数据当然是正确的,例如在Thunderbird中提供相同的数据一切正常。

最初,我以为我在脚本中有错误,但脚本运行正常(给不同的服务器一切正常)。

服务器配置是否有问题? 谢谢。 马尔钦

1 个答案:

答案 0 :(得分:0)

好吧,你可以看到它找到了文档(我键入" symfony发送电子邮件"在谷歌;))https://symfony.com/doc/master/email.html

$message = (new \Swift_Message('Hello Email'))
    ->setFrom('send@example.com')
    ->setTo('recipient@example.com')
    ->setBody(
        $this->renderView(
            // templates/emails/registration.html.twig
            'emails/registration.html.twig',
            array('name' => $name)
        ),
        'text/html'
    )
;

//then use the mailer service to send it 
$this->get('mailer')->send($message);

swiftmailer的配置位于配置文件中,如下所述: https://symfony.com/doc/current/reference/configuration/swiftmailer.html