aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcinzelent <zelent.marcin@gmail.com>2017-12-01 11:06:29 +0100
committermarcinzelent <zelent.marcin@gmail.com>2017-12-01 11:06:29 +0100
commit7d09b3a6201a175128421d117d4c63495813fa05 (patch)
treee014a83d47801ea13ce5ee9259082dde0fe43ce0 /src/AppBundle/Utils/EmailSender.php
parent491eb42cd125b76f96d4f906c3822202d55395a1 (diff)
Refactored sending of e-mails and made it work.
Diffstat (limited to 'src/AppBundle/Utils/EmailSender.php')
-rw-r--r--src/AppBundle/Utils/EmailSender.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/AppBundle/Utils/EmailSender.php b/src/AppBundle/Utils/EmailSender.php
new file mode 100644
index 0000000..e6f74c2
--- /dev/null
+++ b/src/AppBundle/Utils/EmailSender.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: marcin
+ * Date: 01/12/17
+ * Time: 10:47
+ */
+
+namespace AppBundle\Utils;
+
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Swift_SmtpTransport;
+use Swift_Mailer;
+use Swift_Message;
+
+class EmailSender extends Controller
+{
+ public function sendEmail(array $data)
+ {
+// Create the Transport
+ $transport = (new Swift_SmtpTransport('mail.cock.li', 465, 'ssl'))
+ ->setUsername('***REMOVED***')
+ ->setPassword('***REMOVED***')
+ ;
+
+// Create the Mailer using your created Transport
+ $mailer = new Swift_Mailer($transport);
+
+// Create a message
+ $message = (new Swift_Message('Pollutometer warning ' . date('d/m/Y h:i:s')))
+ ->setFrom(['***REMOVED***' => 'Pollutometer'])
+ ->setTo(['***REMOVED***@edu.easj.dk' => 'A name'])
+ ->setBody($this->renderView(
+ 'emails/warning.html.twig', $data),
+ 'text/html')
+ ;
+
+// Send the message
+ $result = $mailer->send($message);
+ }
+} \ No newline at end of file