I am trying to send emails using Swiftmailer using Symfony 2.
This is a simple function in the controller.
public function sendEmailAction() {
$name = 'Test';
$mailer = $this->get('mailer');
$message = $mailer->createMessage()
->setSubject('Ciao')
->setFrom('send@example.com')
->setTo('recipient@example.com')
->setBody($this->renderView('dashboard/email.html.twig',array('name' => $name)), 'text/html');
$mailer->send($message);
return $this->redirectToRoute('dashboard');
In the .yml options I have the following configuration
parameters:
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: e23a8d7b075fa3c7e56b10186a24cf2790a3169a
And this is config.yml one
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
Sorry, I cannot send emails ...
source
share