emailManager factory service is available to send emails from your application.
It’s already configured to use simple CSS styles and you can use an HTML and plain-text
templates.

$request=$this->get('request');$receiver='[email protected]';$origin=$this->get('settingsBag')->get('email_sender');$emailManager=$this->get('emailManager');$title=$this->getTranslator()->trans('hello_world');$emailManager->setEmailTitle($title);$emailManager->setSubject($title);$emailManager->setReceiver($receiver);$emailManager->setOrigin($origin);$emailManager->setAssignation(['content'=>'Bla bla bla','title'=>$title,'head'=>['absoluteResourcesUrl'=>$request->getSchemeAndHttpHost().$request->getBasePath().'/themes/MySuperTheme/static/',],'site'=>$this->get('settingsBag')->get('site_name'),'disclaimer'=>'You are receiving this email because you rocks!',]);$emailManager->setEmailTemplate('@MySuperTheme/emails/email.html.twig');$emailManager->setEmailPlainTextTemplate('@MySuperTheme/emails/email.txt.twig');$emailManager->send();

Assignation works the same way as HTML template for your website, you must assign every
content and informations you’ll need to print in your emails.

Note

Be careful, every image path or links must be an absolute URL, not a path as your
receivers won’t be able to resolve your full domain name. Make sure you are using url()
instead of path() for links and add head.absoluteResourcesUrl prefix for your static
assets (like in the example before).