aboutsummaryrefslogtreecommitdiff
blob: 982234ee0cc091cfc5271a8f2981b834471243fe (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
43
44
45
46
47
48
49
50
51
<?php
/**
 * Created by PhpStorm.
 * User: marcin
 * Date: 11/23/17
 * Time: 10:21 AM
 */

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Swift_SmtpTransport;
use Swift_Mailer;
use Swift_Message;

class EmailController extends Controller
{
    /**
     * @Route("/email")
     */
    public function sendEmail()
    {
// 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(
            // 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'));
    }

}