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
|
|
|
use Yii; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* This component allow user to send an email |
26
|
|
|
* |
27
|
|
|
* @author Philippe Gaultier <[email protected]> |
28
|
|
|
* @copyright 2010-2016 Philippe Gaultier |
29
|
|
|
* @license http://www.sweelix.net/license license |
30
|
|
|
* @version XXX |
31
|
|
|
* @link http://www.sweelix.net |
32
|
|
|
* @package sweelix\postmark |
33
|
|
|
* @since XXX |
34
|
|
|
* @todo implement batch messages using API |
35
|
|
|
*/ |
36
|
|
|
class Mailer extends BaseMailer |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
public $token; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
public $apiUri; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var boolean |
50
|
|
|
*/ |
51
|
|
|
public $verifySsl; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var int |
55
|
|
|
*/ |
56
|
|
|
public $timeOut = 30; |
57
|
|
|
/** |
58
|
|
|
* @inheritdoc |
59
|
|
|
*/ |
60
|
|
|
public $messageClass = 'sweelix\postmark\Message'; |
61
|
|
|
/** |
62
|
|
|
* @param Message $message |
63
|
|
|
* @since XXX |
64
|
|
|
* @throws InvalidConfigException |
65
|
|
|
*/ |
66
|
2 |
|
public function sendMessage($message) |
67
|
|
|
{ |
68
|
|
|
try { |
69
|
2 |
|
if ($this->token === null) { |
70
|
2 |
|
throw new InvalidConfigException('Token is missing'); |
71
|
|
|
} |
72
|
|
|
if ($this->apiUri !== null) { |
73
|
|
|
PostmarkClient::$BASE_URL = $this->apiUri; |
74
|
|
|
} |
75
|
|
|
if ($this->verifySsl !== null) { |
76
|
|
|
PostmarkClient::$VERIFY_SSL = $this->verifySsl; |
77
|
|
|
} |
78
|
|
|
$client = new PostmarkClient($this->token, $this->timeOut); |
79
|
|
|
$templateId = $message->getTemplateId(); |
80
|
|
|
if ($templateId === null) { |
81
|
|
|
$sendResult = $client->sendEmail($message->getFrom(), $message->getTo(), |
82
|
|
|
$message->getSubject(), |
83
|
|
|
$message->getHtmlBody(), $message->getTextBody(), |
84
|
|
|
$message->getTag(), |
85
|
|
|
$message->getTrackOpens(), |
86
|
|
|
$message->getReplyTo(), |
87
|
|
|
$message->getCc(), |
88
|
|
|
$message->getBcc(), |
89
|
|
|
$message->getHeaders(), |
90
|
|
|
$message->getAttachments() |
91
|
|
|
); |
92
|
|
|
} else { |
93
|
|
|
$sendResult = $client->sendEmailWithTemplate($message->getFrom(), $message->getTo(), |
94
|
|
|
$message->getTemplateId(), $message->getTemplateModel(), |
|
|
|
|
95
|
|
|
$message->getInlineCss(), |
96
|
|
|
$message->getTag(), |
97
|
|
|
$message->getTrackOpens(), |
98
|
|
|
$message->getReplyTo(), |
99
|
|
|
$message->getCc(), |
100
|
|
|
$message->getBcc(), |
101
|
|
|
$message->getHeaders(), |
102
|
|
|
$message->getAttachments() |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
//TODO: handle error codes and log stuff |
106
|
|
|
return isset($sendResult['ErrorCode']) ? ($sendResult['ErrorCode'] == 0) : false; |
107
|
2 |
|
} catch (PostmarkException $e) { |
108
|
|
|
throw $e; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
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: