关于发送邮件symfony2,swiftmailer和ovh

时间:2014-02-27 22:54:03

标签: symfony swiftmailer

我遇到发送邮件的问题,邮件并不总是发送: 有时回复成功发送(我在邮箱中找到它) 有时回复失败的发送

这是错误消息:

Expected response code 250 but got code "", with message «  »

这是日志文件的内容:

[2014-02-27 23:13:43] request.INFO: Matched route "ws_front_message_send" (parameters: "_controller": "Ws\Bundle\MailerBundle\Controller\SendController::messageAction", "domain": "saci.com.tn", "_route": "ws_front_message_send") [] []
[2014-02-27 23:13:43] security.INFO: Populated SecurityContext with an anonymous Token [] []
[2014-02-27 23:13:44] request.CRITICAL: Uncaught PHP Exception Swift_TransportException: "Expected response code 250 but got code "", with message """ at /homez.755/sacinrgm/www/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php line 386 {"exception":"[object] (Swift_TransportException: Expected response code 250 but got code \"\", with message \"\" at /homez.755/sacinrgm/www/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:386)"} []
[2014-02-27 23:13:44] security.DEBUG: Write SecurityContext in the session [] []

my parameters.yml:

parameters:
     # smtp ovh parametres
     mailer_transport: smtp
     mailer_port: 465
     mailer_encryption: ssl
     mailer_auth_mode: login
     mailer_host: ssl0.ovh.net
     mailer_user: **************
     mailer_password: **************

我在控制器中的行动:

public function messageAction(Request $request) {
    $message = new Message();
    $mailer = $this->get('mailer');

    $form = $this->createForm(new MessageCreate(), $message, array(
        'action' => $this->generateUrl('ws_front_message_send'),
        'method' => 'POST',
        'attr' => array('id' => 'form')
    ));
    $form->handleRequest($request);

    $mailFrom = $message->getEmail();
    $mailTo = $this->container->getParameter('mailer_customer');

    $mail = \Swift_Message::newInstance()
            ->setSubject('Contact ' . $message->getCountry() . ' from Saci')
            ->setFrom($mailFrom)
            ->setTo($mailTo)
            ->setBody($this->renderView('WsMailerBundle:Email:message.html.twig', array('message' => $message)), 'text/html');

    $mailer->send($mail);

    $this->get('session')->getFlashBag()->set(
            'succes', 'contact.msg_after_send');


    return $this->redirect($this->getRequest()->headers->get('referer'));
}    

1 个答案:

答案 0 :(得分:0)

我在使用ovh,siwftmailer和fosUserBundle时遇到电子邮件和垃圾邮件问题,

请考虑在config.yml中添加此内容

fos_user:
    from_email:
            address:        noreply@yourdomain.com
            sender_name:  

提供yourname

如果您不这样做,fos用户捆绑包将发送电子邮件至noreply@exemple.com,OVH将此标记为垃圾邮件。

来源:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/emails.md