- //Get contact name
- $contactName = $this->config['contact_name'];
-
- //Get contact mail
- $contactMail = $this->config['contact_mail'];
-
- //Get logo
- $logo = $this->config['logo'];
-
- //Get title
- $title = $this->translator->trans($this->config['title']);
-
- //Get subtitle
- $subtitle = $this->translator->trans('Hi,').' '.$contactName;
-
- //Create sendmail transport
- $transport = new \Swift_SendmailTransport();
-
- //Create mailer using transport
- $mailer = new \Swift_Mailer($transport);
-
- //Create the message
- ($message = new \Swift_Message($data['subject']))
- #->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']),
+ ]