1
votes

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('[email protected]')
                ->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
Looks to me like the swiftmailer library issue is resolved now, but I guess you still have some configuration issues with your server if sendmail and mail transports are either raising errors or not sending emails. response code 220 is service ready... so it's not really. pity there's no actual response code! can you tell me more about the environment you are using? - Darragh Enright
I found an [intriguing SO answer - might be worth a look? It suggesting that blank lines might be the issue - I have no idea, but you can use the Symfony web profiler to view the format of the mail you sent. stackoverflow.com/questions/4940698/… - Darragh Enright
alternatively if you are having ongoing issues with your environment, have a look at using SMTP via gmail or even Mandrill, the latter of which is a transactional email service (from MailChimp) that gives you 13,000 free mails a month. - Darragh Enright
@Darragh my dev env is ubuntu server 13.04 with php 5.4.9. I tried gmail transport, but i have "Cannot send message without a sender address 500 Internal Server Error - Swift_TransportException" error. - MeursaultF
Maybe my setTo is false ? in don't know... - MeursaultF

2 Answers

1
votes

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.

0
votes

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"