diff options
Diffstat (limited to 'src/AppBundle/Controller/EmailController.php')
-rw-r--r-- | src/AppBundle/Controller/EmailController.php | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/src/AppBundle/Controller/EmailController.php b/src/AppBundle/Controller/EmailController.php index 7b6e864..982234e 100644 --- a/src/AppBundle/Controller/EmailController.php +++ b/src/AppBundle/Controller/EmailController.php @@ -9,8 +9,10 @@ namespace AppBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use Symfony\Component\HttpFoundation\Response; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Swift_SmtpTransport; +use Swift_Mailer; +use Swift_Message; class EmailController extends Controller { @@ -19,31 +21,31 @@ class EmailController extends Controller */ public function sendEmail() { - $message = (new \Swift_Message('Hello Email')) - ->setFrom('***REMOVED***') - ->setTo('***REMOVED***@edu.easj.dk') - ->setBody( - $this->renderView( -// app/Resources/views/Emails/registration.html.twig - 'emails/registration.html.twig', - array('name' => "Test") - ), - 'text/html' - )/* -* If you also want to include a plaintext version of the message -->addPart( -$this->renderView( -'Emails/registration.txt.twig', -array('name' => $name) -), -'text/plain' -) -*/ +// Create the Transport + $transport = (new Swift_SmtpTransport('mail.cock.li', 465, 'ssl')) + ->setUsername('***REMOVED***') + ->setPassword('***REMOVED***') ; -//$mailer->send($message); +// Create the Mailer using your created Transport + $mailer = new Swift_Mailer($transport); -// or, you can also fetch the mailer service this way - $this->get('mailer')->send($message); +// 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( + // templates/emails/warning.html.twig + 'warning.html.twig', + array('name' => 'Test') + ), + 'text/html') + ; + +// Send the message + $result = $mailer->send($message); + + return $this->render('warning.html.twig', array('name' => 'Test')); } + } |