PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/dynamics/elasticemail/plugin.php +29 -28 10.1.4 → 11.1.0 View file →
@@ -1,6 +1,7 @@
1 1 <?php
2 2
3 +use AcyMailerPhp\Mailer;
3 4 use AcyMailing\Classes\CampaignClass;
4 5 use AcyMailing\Classes\MailClass;
5 6 use AcyMailing\Helpers\MailerHelper;
6 7 use AcyMailing\Core\AcymPlugin;
@@ -31,31 +32,29 @@
31 32 }
32 33
33 34 public function onAcymGetSendingMethodsHtmlSetting(&$data)
34 35 {
35 - ob_start();
36 36 ?>
37 - <div class="send_settings grid-x cell" id="<?php echo self::SENDING_METHOD_ID; ?>_settings">
37 + <div class="send_settings grid-x cell" id="<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_settings">
38 38 <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings">
39 - <label for="<?php echo self::SENDING_METHOD_ID; ?>_password" class="cell shrink margin-right-1">
40 - <?php echo acym_translation('ACYM_API_KEY'); ?>
39 + <label for="<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_password" class="cell shrink margin-right-1">
40 + <?php echo esc_html(acym_translation('ACYM_API_KEY')); ?>
41 41 </label>
42 42 <?php
43 - echo $this->getLinks(
43 + $this->getLinks(
44 44 'https://elasticemail.com/referral-reward?r=7b884a0b-b979-4473-8803-06ae39d76599',
45 45 'https://elasticemail.com/email-api-pricing?r=7b884a0b-b979-4473-8803-06ae39d76599'
46 46 );
47 47 ?>
48 - <input id="<?php echo self::SENDING_METHOD_ID; ?>_password"
49 - class="cell"
50 - type="text"
51 - name="config[<?php echo self::SENDING_METHOD_ID; ?>_password]"
52 - value="<?php echo str_repeat('*', strlen($this->config->get(self::SENDING_METHOD_ID.'_password'))); ?>">
53 - <?php echo $this->getTestCredentialsSendingMethodButton(self::SENDING_METHOD_ID); ?>
48 + <input id="<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_password"
49 + class="cell"
50 + type="text"
51 + name="config[<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_password]"
52 + value="<?php echo esc_attr(str_repeat('*', strlen($this->config->get(self::SENDING_METHOD_ID.'_password')))); ?>">
53 + <?php $this->getTestCredentialsSendingMethodButton(self::SENDING_METHOD_ID); ?>
54 54 </div>
55 55 </div>
56 56 <?php
57 - $data['sendingMethodsHtmlSettings'][self::SENDING_METHOD_ID] = ob_get_clean();
58 57 }
59 58
60 59 public function onAcymTestCredentialSendingMethod($sendingMethod, $credentials)
61 60 {
@@ -93,8 +92,9 @@
93 92 array $bcc = [],
94 93 array $attachments = [],
95 94 $sendingMethodListParams = []
96 95 ): void {
96 + // https://elasticemail.com/developers/api-documentation/rest-api#operation/emailsTransactionalPost
97 97 if ($mailerHelper->externalMailer !== self::SENDING_METHOD_ID) {
98 98 return;
99 99 }
100 100
@@ -102,11 +102,11 @@
102 102 'recipients' => new stdClass(),
103 103 'content' => new stdClass(),
104 104 ];
105 105
106 - $this->handleAddresses($data, $from, $reply_to, $to, $bcc);
106 + $this->handleAddresses($data, $mailerHelper, $from, $reply_to, $to, $bcc);
107 107 $this->handleEmailContent($data, $mailerHelper);
108 - $this->handleAttachments($data, $mailerHelper, $attachments);
108 + $this->handleAttachments($data, $attachments);
109 109 $this->handleHeaders($data, $mailerHelper);
110 110 $this->handleGA($data, $mailerHelper);
111 111
112 112 $responseMailer = $this->callApiSendingMethod(
@@ -128,9 +128,9 @@
128 128 {
129 129 $data['embedImage'][self::SENDING_METHOD_ID] = false;
130 130 }
131 131
132 - private function handleAddresses(array &$data, array $from, array $reply_to, array $to, array $bcc): void
132 + private function handleAddresses(array &$data, MailerHelper $mailerHelper, array $from, array $reply_to, array $to, array $bcc): void
133 133 {
134 134 $data['recipients']->to = [$to['email']];
135 135
136 136 if (!empty($bcc)) {
@@ -139,9 +139,9 @@
139 139
140 140 $data['content']->From = empty($from['name']) ? $from['email'] : $from['name'].' <'.$from['email'].'>';
141 141 $data['content']->ReplyTo = empty($reply_to['name']) ? $reply_to['email'] : $reply_to['name'].' <'.$reply_to['email'].'>';
142 142
143 - $bounceAddress = $this->config->get('bounce_email');
143 + $bounceAddress = $this->getBounceAddress($mailerHelper);
144 144 if (!empty($bounceAddress)) {
145 145 $data['content']->EnvelopeFrom = $bounceAddress;
146 146 }
147 147 }
@@ -165,9 +165,9 @@
165 165 ];
166 166 }
167 167 }
168 168
169 - private function handleAttachments(array &$data, MailerHelper $mailerHelper, array $attachments): void
169 + private function handleAttachments(array &$data, array $attachments): void
170 170 {
171 171 if (empty($attachments)) {
172 172 return;
173 173 }
@@ -174,8 +174,9 @@
174 174
175 175 if (!$this->attachmentsFetched) {
176 176 $this->attachmentsFetched = true;
177 177
178 + // Uploaded attachments expire after 35 days by default, so 1000 should be more than enough
178 179 $uploadedAttachments = $this->callApiSendingMethod(
179 180 self::SENDING_METHOD_API_URL.'files?limit=1000',
180 181 [],
181 182 $this->getAuthenticationHeaders()
@@ -216,13 +217,15 @@
216 217 }
217 218
218 219 private function handleHeaders(array &$data, MailerHelper $mailerHelper): void
219 220 {
221 + $data['content']->Headers = new stdClass();
222 + $data['content']->Headers->Date = Mailer::rfcDate();
223 +
220 224 if (empty($mailerHelper->CustomHeader)) {
221 225 return;
222 226 }
223 227
224 - $data['content']->Headers = new stdClass();
225 228 foreach ($mailerHelper->CustomHeader as $oneHeader) {
226 229 $data['content']->Headers->{$oneHeader[0]} = $oneHeader[1];
227 230 }
228 231 }
@@ -237,12 +240,8 @@
237 240 $data['content']->Utm->Source = 'newsletter';
238 241 $data['content']->Utm->Medium = 'email';
239 242 $data['content']->Utm->Campaign = acym_getAlias($data['content']->Subject);
240 243
241 - if (empty($mailerHelper->mailId)) {
242 - return;
243 - }
244 -
245 244 if (empty($this->mailClass)) {
246 245 $this->mailClass = new MailClass();
247 246 }
248 247 $campaignId = $this->mailClass->getCampaignIdByMailId($mailerHelper->mailId);
@@ -276,14 +275,15 @@
276 275 }
277 276
278 277 private function getAuthenticationHeaders(array $credentials = []): array
279 278 {
280 - if (!isset($credentials[self::SENDING_METHOD_ID.'_password']) || (!empty($credentials[self::SENDING_METHOD_ID.'_password']) && empty(
281 - trim(
282 - $credentials[self::SENDING_METHOD_ID.'_password'],
283 - '*'
284 - )
285 - ))) {
279 + if (
280 + !isset($credentials[self::SENDING_METHOD_ID.'_password'])
281 + || (
282 + !empty($credentials[self::SENDING_METHOD_ID.'_password'])
283 + && empty(trim($credentials[self::SENDING_METHOD_ID.'_password'], '*'))
284 + )
285 + ) {
286 286 return [
287 287 'X-ElasticEmail-ApiKey: '.$this->config->get(self::SENDING_METHOD_ID.'_password'),
288 288 'Content-Type: application/json',
289 289 ];
@@ -296,8 +296,9 @@
296 296 }
297 297
298 298 private function cleanFileName(string $fileName): string
299 299 {
300 + // Replace accents with their non-accented equivalent
300 301 if (function_exists('iconv')) {
301 302 $fileName = iconv('UTF-8', 'ASCII//TRANSLIT', $fileName);
302 303 }
303 304