【问题标题】:about send mail symfony2, swiftmailer and ovh关于发送邮件 symfony2、swiftmailer 和 ovh
【发布时间】:2014-02-27 22:54:02
【问题描述】:

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

这是错误信息:

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 [] []

我的参数.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'));
}    

【问题讨论】:

  • 您可能需要添加检查以查看 $mailFrom 是否为空,这不太可能是问题,但仍然不是一个坏习惯。
  • 我确定 $mailFrom,但我不明白为什么邮件并不总是成功发送。

标签: symfony swiftmailer


【解决方案1】:

您在使用 ovh、siwftmailer 和 fosUserBundle 处理电子邮件和垃圾邮件时遇到问题,

请考虑将其添加到您的 config.yml

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

你的名字

如果您不这样做,fos 用户包将发送带有 noreply@exemple.com 的电子邮件,并且 OVH 将其标记为垃圾邮件。

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

【讨论】:

    猜你喜欢
    • 2017-07-07
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-22
    • 2015-05-05
    • 2015-04-16
    • 1970-01-01
    相关资源
    最近更新 更多