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