Symfony2 SwiftMailer sendmail transport error

2019-08-04 17:27发布

I wish implementer a contact form on my website. i followed the symfony2 documentation : http://symfony.com/fr/doc/current/cookbook/email/email.html

i use symfony 2.3.3.

So that is my config_dev.yml:

swiftmailer:
    transport: sendmail

My contactAction controller:

 public function contactAction(Request $request)
    {
        $this->focus = "contact";

        $form = $this->createFormBuilder()
            ->add('Sujet:', 'text')
            ->add('Service:', 'choice',
                array(
                    'choices' =>
                        array(
                            'all' => 'Communication multi-canaux (plusieurs services liés)',
                            'web' => 'Développement Web',
                            'webMarketing' => 'Web Marketing',
                            'mobile' => 'Développement mobile / tablette',
                            'brand' => 'Brand design',
                            'event' => 'Evènementiel',
                            'print' => 'Campagne print',
                        ),

                    'preferred_choices' => array('all'),
                )
            )
            ->add('Nom:', 'text')
            ->add('Societe:', 'text')
            ->add('Courriel:', 'email')
            ->add('message:', 'textarea')
            ->getForm();

        $form->handleRequest($request);

        if ($form->isValid()) {
            // Les données sont un tableau avec les clés "name", "email", et "message"
            $data = $form->getData();
            $message = \Swift_Message::newInstance()
                ->setSubject($data['Sujet'] . $data['Société'])
                ->setFrom($data['Courriel'])
                ->setTo('contact@visual-immersion.com')
                ->setBody($this->renderView('text à placer par la suite'))
            ;
            $this->get('mailer')->send($message);
        }

        $this->get('mailer')->send($message);
        return $this->render('VisualImmersionSiteBundle:Site:contact.html.twig',
            array(
                'focus' => $this->focus,
                'form'   => $form->createView(),
            ));
    }

i have this error:

Catchable Fatal Error: Argument 2 passed to Swift_Transport_SendmailTransport::__construct() must implement interface Swift_Events_EventDispatcher, instance of Swift_Transport_StreamBuffer given, called in /var/www/visual-immersion/app/cache/dev/appDevDebugProjectContainer.php on line 2129 and defined in /var/www/visual-immersion/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/SendmailTransport.php line 42

and I absolutely can not find where the problem is. Do you have any ideas, or have you experienced this error?

Thank you for your help

UPDATE:

i downgraded SwiftMailer package to 2.3.2 version in composer. The problem was solved, but now, i have this error message;

Expected response code 220 but got code "", with message ""

any idea ?

2条回答
你好瞎i
2楼-- · 2019-08-04 17:38

It appears to be a bug with 2.3.3. Here's a GitHub issue discussing the matter.

The solution here appears to be to change your swiftmailer-bundle dependency in composer.json from 2.3.3 to 2.3.2:

"symfony/swiftmailer-bundle": "2.3.2"
查看更多
Lonely孤独者°
3楼-- · 2019-08-04 17:50

The reason is the sendmail function in your server is not correct.

You can test with command: telnet localhost 25

If you are using Linux server. You should install Postfix, because SSMTP does not support telnet, while SwitfMailer always check telnet before sending email.

查看更多
登录 后发表回答