|
1
|
|
|
<?php |
|
2
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */ |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Mailer component handling sending of report notification mails |
|
6
|
|
|
* |
|
7
|
|
|
* phpMyAdmin Error reporting server |
|
8
|
|
|
* Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
|
9
|
|
|
* |
|
10
|
|
|
* Licensed under The MIT License |
|
11
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
12
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
13
|
|
|
* |
|
14
|
|
|
* @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
|
15
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
|
16
|
|
|
* |
|
17
|
|
|
* @see https://www.phpmyadmin.net/ |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace App\Controller\Component; |
|
21
|
|
|
|
|
22
|
|
|
use Cake\Controller\Component; |
|
23
|
|
|
use Cake\ORM\TableRegistry; |
|
24
|
|
|
use Cake\Mailer\Email; |
|
25
|
|
|
use Cake\Core\Configure; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Mailer component handling report notification emails. |
|
29
|
|
|
*/ |
|
30
|
|
|
class MailerComponent extends Component |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Send an email about the report to configured Email |
|
34
|
|
|
* |
|
35
|
|
|
* @param array $viewVars Array of View Variables |
|
36
|
|
|
* |
|
37
|
|
|
* @return boolean if Email was sent |
|
38
|
|
|
*/ |
|
39
|
|
|
public function sendReportMail($viewVars) |
|
40
|
|
|
{ |
|
41
|
|
|
$email = new Email('default'); |
|
42
|
|
|
$emailTo = Configure::read('NotificationEmailsTo'); |
|
43
|
|
|
$emailFrom = Configure::read('NotificationEmailsFrom'); |
|
44
|
|
|
$emailTransport = Configure::read('NotificationEmailsTransport'); |
|
45
|
|
|
|
|
46
|
|
|
if (! $emailTo || $emailTo === '' |
|
47
|
|
|
|| ! $emailFrom || $emailFrom === '' |
|
48
|
|
|
) { |
|
49
|
|
|
return false; |
|
50
|
|
|
} |
|
51
|
|
|
$email->viewBuilder()->setLayout('default'); |
|
52
|
|
|
$email->viewBuilder()->setTemplate('report'); |
|
53
|
|
|
|
|
54
|
|
|
$email->setTransport($emailTransport) |
|
55
|
|
|
->setViewVars($viewVars) |
|
56
|
|
|
->setSubject( |
|
57
|
|
|
sprintf( |
|
58
|
|
|
'A new report has been submitted on the Error Reporting Server: %s', |
|
59
|
|
|
$viewVars['report']['id'] |
|
60
|
|
|
) |
|
61
|
|
|
) |
|
62
|
|
|
->setEmailFormat('html') |
|
63
|
|
|
->setTo($emailTo) |
|
64
|
|
|
->setFrom($emailFrom) |
|
65
|
|
|
->send(); |
|
66
|
|
|
|
|
67
|
|
|
return true; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|