douzhi4830 2015-09-07 16:29
浏览 48

symfony swiftmaile奇怪的行为

I got a strange behavior when sending email using Swiftmailer
here is the paramaters:

#Swiftmailer parameters @ app/config/parameters.yml
parameters:
        mailer_transport: smtp
        mailer_host: ssl0.ovh.net
        mailer_user: my_account@my_domain.com
        mailer_password: my_account_password
        mailer_port: 465
        auth_mode: plain
        encryption: ssl

the config

# Swiftmailer Configuration @ app/config/config.yml
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    port:      "%mailer_port%"
    encryption: "%encryption%"
    auth_mode: "%auth_mode%"

Now the controller and the action

class MailTestController extends Controller
{

    public function SymfonyParamatersAction()
    {

        $message=\Swift_Message::newInstance()
        ->setSubject('smtp test with sm params')
        ->setFrom('my_account@my_domain.com')
        ->setTo('my_account@gmail.com')
        ->setBody('this is a test')
        ;
        $result =$this->get('mailer')->send($message);
        dump($this->get('mailer')->getTransport());die;
        //return $this->render('...');;
    }

}

So in the profiler I got one email sent but I dont receive any mail
I added this action to my controller

public function DirectParamatersAction()
        {
            $transport = \Swift_SmtpTransport::newInstance('ssl0.ovh.net', 465,'ssl')
                  ->setUsername('my_account@my_domain.com')
                  ->setPassword('my_account_password')
                  ;
            $transport->start();
            $mailer = \Swift_Mailer::newInstance($transport);
            $message=\Swift_Message::newInstance()
            ->setSubject('smtp test with direct params')
            ->setFrom('my_account@my_domain.com')
            ->setTo('my_account@gmail.com')
            ->setBody('this is a test')
            ;
            $result =$mailer->send($message);
            dump($transport);die;
            return $this->render('.........');
        }

with this action I received the message
the funny part (strange behavior) is when running these actions, I get different result:
1=> message is sent
2=> Expected response code 250 but got code "235", with message "235 ok, go ahead (#2.0.0)
3=>Connection could not be established with host ssl0.ovh.net [Connection timed out #110]
I clean the cache every time I change the config
I have to reload the page again and again to send the message
my question is what is wrong with the parameters and the first action? secondly how to avoid this strange behavior?

  • 写回答

1条回答 默认 最新

  • dou11655853 2015-09-08 09:14
    关注

    the problem was in old configuration in app/conf/config_dev.yml

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看