-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMailer.php
executable file
·100 lines (85 loc) · 2.86 KB
/
Mailer.php
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*
START LICENSE AND COPYRIGHT
This file is part of ZfExtended library
Copyright (c) 2013 - 2021 Marc Mittag; MittagQI - Quality Informatics; All rights reserved.
Contact: http://www.MittagQI.com/ / service (ATT) MittagQI.com
This file may be used under the terms of the GNU LESSER GENERAL PUBLIC LICENSE version 3
as published by the Free Software Foundation and appearing in the file lgpl3-license.txt
included in the packaging of this file. Please review the following information
to ensure the GNU LESSER GENERAL PUBLIC LICENSE version 3.0 requirements will be met:
https://www.gnu.org/licenses/lgpl-3.0.txt
@copyright Marc Mittag, MittagQI - Quality Informatics
@author MittagQI - Quality Informatics
@license GNU LESSER GENERAL PUBLIC LICENSE version 3
https://www.gnu.org/licenses/lgpl-3.0.txt
END LICENSE AND COPYRIGHT
*/
class ZfExtended_Mailer extends Zend_Mail
{
/**
* disable sending E-Mails completly
* @var boolean
*/
protected static $sendingDisabled = false;
/**
* @var Zend_Config
*/
protected $config;
/**
* @var Throwable
*/
protected $lastError = null;
/**
* Public constructor
*
* @param string $charset
*/
public function __construct($charset = null)
{
$this->config = Zend_Registry::get('config');
if (! self::$sendingDisabled) {
self::$sendingDisabled = $this->config->runtimeOptions->sendMailDisabled;
}
parent::__construct($charset);
}
/**
* Sends this email using the given transport or a previously
* set DefaultTransport or the internal mail function if no
* default transport had been set.
*
* @param Zend_Mail_Transport_Abstract $transport
* @return ZfExtended_Mailer Provides fluent interface
*/
public function send($transport = null)
{
if (self::$sendingDisabled) {
if (ZfExtended_Debug::hasLevel('core', 'mailing')) {
error_log('translate5 disabled mail: ' . $this->getSubject() . ' <' . implode(',', $this->getRecipients()) . '>');
}
return null;
}
try {
return parent::send($transport);
} catch (Throwable $e) {
$this->lastError = $e;
//disable mail sending, so it not end up in endles loop
self::$sendingDisabled = true;
if (Zend_Registry::isRegistered('logger')) {
Zend_Registry::get('logger')->exception($e, [
'level' => ZfExtended_Logger::LEVEL_WARN,
]);
} else {
error_log($e);
}
}
return null;
}
/**
* Returns the last email error or null if no error
*/
public function getLastError(): ?Throwable
{
return $this->lastError;
}
}