1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Mail.php |
4
|
|
|
* |
5
|
|
|
* PHP version 5.6+ |
6
|
|
|
* |
7
|
|
|
* @author Philippe Gaultier <[email protected]> |
8
|
|
|
* @copyright 2010-2016 Philippe Gaultier |
9
|
|
|
* @license http://www.sweelix.net/license license |
10
|
|
|
* @version XXX |
11
|
|
|
* @link http://www.sweelix.net |
12
|
|
|
* @package sweelix\postmark |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace sweelix\postmark; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
use Postmark\Models\PostmarkException; |
19
|
|
|
use Postmark\PostmarkClient; |
20
|
|
|
use yii\base\InvalidConfigException; |
21
|
|
|
use yii\mail\BaseMailer; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* This component allow user to send an email |
25
|
|
|
* |
26
|
|
|
* @author Philippe Gaultier <[email protected]> |
27
|
|
|
* @copyright 2010-2016 Philippe Gaultier |
28
|
|
|
* @license http://www.sweelix.net/license license |
29
|
|
|
* @version XXX |
30
|
|
|
* @link http://www.sweelix.net |
31
|
|
|
* @package sweelix\postmark |
32
|
|
|
* @since XXX |
33
|
|
|
* @todo implement batch messages using API |
34
|
|
|
*/ |
35
|
|
|
class Mailer extends BaseMailer |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
public $token; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
public $apiUri; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var boolean |
49
|
|
|
*/ |
50
|
|
|
public $verifySsl; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var int |
54
|
|
|
*/ |
55
|
|
|
public $timeOut = 30; |
56
|
|
|
/** |
57
|
|
|
* @inheritdoc |
58
|
|
|
*/ |
59
|
|
|
public $messageClass = 'sweelix\postmark\Message'; |
60
|
|
|
/** |
61
|
|
|
* @param Message $message |
62
|
|
|
* @since XXX |
63
|
|
|
* @throws InvalidConfigException |
64
|
|
|
*/ |
65
|
2 |
|
public function sendMessage($message) |
66
|
|
|
{ |
67
|
|
|
try { |
68
|
2 |
|
if ($this->token === null) { |
69
|
2 |
|
throw new InvalidConfigException('Token is missing'); |
70
|
|
|
} |
71
|
|
|
if ($this->apiUri !== null) { |
72
|
|
|
PostmarkClient::$BASE_URL = $this->apiUri; |
73
|
|
|
} |
74
|
|
|
if ($this->verifySsl !== null) { |
75
|
|
|
PostmarkClient::$VERIFY_SSL = $this->verifySsl; |
76
|
|
|
} |
77
|
|
|
$client = new PostmarkClient($this->token, $this->timeOut); |
78
|
|
|
$templateId = $message->getTemplateId(); |
79
|
|
|
if ($templateId === null) { |
80
|
|
|
$sendResult = $client->sendEmail( |
81
|
|
|
$message->getFrom(), |
82
|
|
|
Message::stringifyEmails($message->getTo()), |
83
|
|
|
$message->getSubject(), |
84
|
|
|
$message->getHtmlBody(), $message->getTextBody(), |
85
|
|
|
$message->getTag(), |
86
|
|
|
$message->getTrackOpens(), |
87
|
|
|
$message->getReplyTo(), |
88
|
|
|
Message::stringifyEmails($message->getCc()), |
89
|
|
|
Message::stringifyEmails($message->getBcc()), |
90
|
|
|
$message->getHeaders(), |
91
|
|
|
$message->getAttachments() |
92
|
|
|
); |
93
|
|
|
} else { |
94
|
|
|
$sendResult = $client->sendEmailWithTemplate( |
95
|
|
|
$message->getFrom(), |
96
|
|
|
Message::stringifyEmails($message->getTo()), |
97
|
|
|
$message->getTemplateId(), $message->getTemplateModel(), |
|
|
|
|
98
|
|
|
$message->getInlineCss(), |
99
|
|
|
$message->getTag(), |
100
|
|
|
$message->getTrackOpens(), |
101
|
|
|
$message->getReplyTo(), |
102
|
|
|
Message::stringifyEmails($message->getCc()), |
103
|
|
|
Message::stringifyEmails($message->getBcc()), |
104
|
|
|
$message->getHeaders(), |
105
|
|
|
$message->getAttachments() |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
//TODO: handle error codes and log stuff |
109
|
|
|
return isset($sendResult['ErrorCode']) ? ($sendResult['ErrorCode'] == 0) : false; |
110
|
2 |
|
} catch (PostmarkException $e) { |
111
|
|
|
throw $e; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: