Question

I'm developing a application in Symfony2 I have a command that will be run in a crontab

This is the command:

<?php
namespace project\projBundle\Service;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Templating\EngineInterface;
class Sender {
    protected $em;
    protected $templating;
    protected $mailer;
    public function __construct($em, $templating,\Swift_Mailer $mailer) {
        $this->em = $em;
        $this->templating = $templating;
        $this->mailer = $mailer; }

    public function runSender() {
        $proj = $this->em->createQuery("query")->setMaxResults(20)->getResult();
        $message = \Swift_Message::newInstance()
            ->setSubject('Contact enquiry from symblog')
            ->setFrom('...@gmail.com')
            ->setTo('...@gmail.com')
            ->setBody($this->templating->render('projectprojBundle:Others:emailNew.html.twig', array('proj' => $proj)));

        $this->mailer->send($message); } }

The parameters.yml:

parameters:
    mailer_transport: gmail
    mailer_host: ~
    mailer_user: ...@gmail.com
    mailer_password: ...

In config_test:

swiftmailer:
disable_delivery: false
spool: { type: memory }

This is sending me emails, but I'm receiving 2 emails: 1st:

Delivery to the following recipient failed permanently:

     ...@gmail

Technical details of permanent failure:
DNS Error: Domain name not found

and in the 2nd the twig code, not rendered.

What I'm doing wrong?

Was it helpful?

Solution

Did you add this is in config.yml:

swiftmailer:
    transport: %mailer_transport%
    host:      %mailer_host%
    username:  %mailer_user%
    password:  %mailer_password%

OTHER TIPS

I fix the twig with that:

protected $twig;
    protected $mailer;
    public function __construct(\Twig_Environment $twig,\Swift_Mailer $mailer) {
        $this->twig = $twig;
        $this->mailer = $mailer;
    }

But now the problem is that I still have the html tags.

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