Question

It is just simple quesion for PHP or it might be for symfony2.

I am using Swift_Message for sending emails.

I send two emails then show the twig file.

However sending emails take too much time.

Consequently,user has to wait for long time to see the html page.

Could I send emails and show the html at the same time?

    $messaggio = \Swift_Message::newInstance()
            ->setSubject('confirm')
            ->setContentType("text/html")
            ->setFrom('email@gmail.com')
            ->setTo($this->user->getEmail())
            ->setBody($this->renderView('AcmeMemberBundle:Default:customer.txt.twig');

            //

    $messaggio = \Swift_Message::newInstance()
            ->setSubject('confirm email')
            ->setContentType("text/html")
            ->setFrom('email@gmail.com')
            ->setTo($this->user->getEmail())
            ->setBody($this->renderView('AcmeMemberBundle:Default:staff.txt.twig');

            //


    return $this->render('AcmeMemberBundle:Default:form.html.twig');   

thank you in advance

Was it helpful?

Solution

I'm guessing you use the mailer service to send the emails? If not, you have to.

this->get('mailer')->send($messaggio);

To send the emails not immediately you can configure a spool. Two spools are supported. The memory spool, which holds the messages in memory and sends them after the kernel has terminated, which means everything got rendered and sent to the client. Or the file spool. With it, the messages got saved into a file, and you have to issue a console command from a cronjob periodically to send the mails.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top