how to configure SwiftMailer in symfony 2?

75 views Asked by At

please, I'm new to Symfony and I'm trying to configure mailer on Symfony 2 but I'm not finding any clear doc for this.

And I'm in need of a route example to send email from an address to another just from back to test this . thank you

I tried installing swift mailer and wrote some code


<?php

namespace MailManager\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

/**
* Email Sender Manager
* @Route("/service-mail/mail")
**/

Class MailManagerController extends AbstractController {

    /**
      * @Route("/send")
      */
      public function send(\Swift_Mailer $mailer){
          $message = \Swift_Message::newInstance()
          ->setsubject('Mail test')
          ->setFrom(['[email protected]'] => 'xxxxxx')
          ->setTo(['[email protected]'] => 'xxxxxx')
          ->setBcc(['[email protected]'] => 'vvvvv')
          ->setBody('Test Test');
          $this->get('mailer')
          ->send($message);
      }
}

I expect to send an email from my email address to another email address predefined, automatically when I enter the route in postman.

1

There are 1 answers

0
mcssym On

Can you change

->setFrom(['[email protected]'] => 'xxxxxx')
          ->setTo(['[email protected]'] => 'xxxxxx')
          ->setBcc(['[email protected]'] => 'vvvvv')

By

->setFrom(['[email protected]' => 'xxxxxx'])
          ->setTo(['[email protected]' => 'xxxxxx'])
          ->setBcc(['[email protected]' => 'vvvvv'])