aboutsummaryrefslogtreecommitdiff
blob: e6f74c270963697495ff1239d2ac5ff4c52940cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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);
    }
}