techie-techie
techie-techie

Reputation: 19

set body of email as html format

I have following code to send the mail

use Ens\NewBundle\Controller\Services\MyMailers as MyMailers;

function NotificationOnSignUp($z)
{
    $x = new MyMailers;
    $x->setToloc($z['to']);
    $x->setFromloc('[email protected]');
    $x->setSubject('Wonderful world');
    $x->setBody('Hello world');

    $z = $x->mail();

    if($z==1) {
        $name = 'success';
    } else {
        $name = 'failed';
    }

    return $x->render('EnsNewBundle:Email:ind.html.twig', array('name' => $name));
    // return $z;  
}

I want to set the template file ind.html.twig as the body of the mail. This function is not in the controller and I dont want to use any service.

How can I do this ?

Upvotes: 0

Views: 963

Answers (2)

Vera
Vera

Reputation: 742

I guess my answer is 2-years delayed, but maybe for someone else this will be helpful: this is a special Sf2 bundle for sending mails from twig templates Symfony2-MailerBundle.
The bundle also allows to set up sending parameters in config file & you won't have to pass them every time you want to build & send email.

Upvotes: 2

AdrienBrault
AdrienBrault

Reputation: 7745

You can get the string resulting from rendering a template using:

$container->get('templating')->render('EnsNewBundle:Email:ind.html.twig', array('name' => $name))

Upvotes: 0

Related Questions