- //Get contact name
- $contactName = $this->getParameter('rapsys_air.contact_name');
-
- //Get contact mail
- $contactMail = $this->getParameter('rapsys_air.contact_mail');
-
- //Get logo
- $logo = $this->getParameter('rapsys_air.logo');
-
- //Get title
- $title = $trans->trans($this->getParameter('rapsys_air.title'));
-
- //Get subtitle
- $subtitle = $trans->trans('Hi,').' '.$contactName;
-
- $message = \Swift_Message::newInstance()
- ->setSubject($data['subject'])
- ->setFrom([$data['mail'] => $data['name']])
- ->setTo([$contactMail => $contactName])
- ->setBody($data['message'])
- ->addPart(
- $this->renderView(
- '@RapsysAir/mail/generic.html.twig',
- [
- 'logo' => $logo,
- 'title' => $title,
- 'subtitle' => $subtitle,
- 'home' => $this->get('router')->generate('rapsys_air_homepage', [], UrlGeneratorInterface::ABSOLUTE_URL),
- 'subject' => $data['subject'],
- 'contact_name' => $contactName,
- 'message' => strip_tags($data['message'])
- ]
- ),
- 'text/html'
+ //Create message
+ $message = (new TemplatedEmail())
+ //Set sender
+ ->from(new NamedAddress($data['mail'], $data['name']))
+ //Set recipient
+ //XXX: remove the debug set in vendor/symfony/mime/Address.php +46
+ ->to(new NamedAddress($this->config['contact']['mail'], $this->config['contact']['name']))
+ //Set subject
+ ->subject($data['subject'])
+
+ //Set path to twig templates
+ ->htmlTemplate('@RapsysAir/mail/contact.html.twig')
+ ->textTemplate('@RapsysAir/mail/contact.text.twig')
+
+ //Set context
+ ->context(
+ [
+ 'site_logo' => $this->config['site']['logo'],
+ 'site_title' => $this->config['site']['title'],
+ 'site_url' => $this->get('router')->generate('rapsys_air_homepage', [], UrlGeneratorInterface::ABSOLUTE_URL),
+ 'copy_long' => $this->config['copy']['long'],
+ 'copy_short' => $this->config['copy']['short'],
+ 'subject' => $data['subject'],
+ 'message' => strip_tags($data['message']),
+ ]