| @@ -25,9 +25,11 @@ | ||
| 25 | 25 | |
| 26 | 26 | // Let's send welcome email to customer if enabled |
| 27 | 27 | $emailSettings = (new Settings())->getBoxEmailSettings($mailbox, 'ticket_created_email_to_customer'); |
| 28 | 28 | |
| 29 | - if ($this->shouldSendEmail($emailSettings, 'ticket_created_email_to_customer', $ticket, $customer)) { | |
| 29 | + // Blocked customers get no email; the admin copy below still goes out. | |
| 30 | + if ($customer && $customer->canReceiveNotifications() | |
| 31 | + && $this->shouldSendEmail($emailSettings, 'ticket_created_email_to_customer', $ticket, $customer)) { | |
| 30 | 32 | $subject = apply_filters('fluent_support/parse_smartcode_data', $emailSettings['email_subject'], [ |
| 31 | 33 | 'customer' => $customer, |
| 32 | 34 | 'business' => $mailbox, |
| 33 | 35 | 'ticket' => $ticket |
| @@ -41,13 +43,14 @@ | ||
| 41 | 43 | 'ticket' => $ticket, |
| 42 | 44 | 'email_type' => 'ticket_created_email_to_customer' |
| 43 | 45 | ]); |
| 44 | 46 | |
| 45 | - $headers = $mailbox->getMailerHeader(); | |
| 47 | + $headers = self::automatedHeaders($mailbox->getMailerHeader()); | |
| 46 | 48 | |
| 47 | 49 | $headers = apply_filters('fluent_support/mail_to_customer_header', $headers, [ |
| 48 | 50 | 'cc_email' => $ticket->getSettingsValue('cc_email', []), |
| 49 | - 'hook_type' => 'ticket_created_email_to_customer' | |
| 51 | + 'hook_type' => 'ticket_created_email_to_customer', | |
| 52 | + 'ticket' => $ticket | |
| 50 | 53 | ]); |
| 51 | 54 | |
| 52 | 55 | $attachments = []; |
| 53 | 56 | |
| @@ -93,9 +96,9 @@ | ||
| 93 | 96 | 'ticket' => $ticket, |
| 94 | 97 | 'email_type' => 'ticket_created_email_to_admin' |
| 95 | 98 | ]); |
| 96 | 99 | |
| 97 | - $headers = $mailbox->getMailerHeader(); | |
| 100 | + $headers = self::automatedHeaders($mailbox->getMailerHeader()); | |
| 98 | 101 | |
| 99 | 102 | $attachments = []; |
| 100 | 103 | |
| 101 | 104 | if ($emailSettings['send_attachments'] == 'yes' && ($files = $ticket->attachments)) { |
| @@ -134,9 +137,9 @@ | ||
| 134 | 137 | |
| 135 | 138 | $ticket->load('customer'); |
| 136 | 139 | $customer = $ticket->customer; |
| 137 | 140 | |
| 138 | - if ($customer->status == 'inactive') { | |
| 141 | + if (!$customer->canReceiveNotifications()) { | |
| 139 | 142 | return false; |
| 140 | 143 | } |
| 141 | 144 | |
| 142 | 145 | if (!$this->shouldSendEmail($emailSettings, 'ticket_replied_by_agent_email_to_customer', $ticket, $customer)) { |
| @@ -162,12 +165,14 @@ | ||
| 162 | 165 | 'email_type' => 'ticket_replied_by_agent_email_to_customer' |
| 163 | 166 | ]); |
| 164 | 167 | |
| 165 | 168 | |
| 166 | - $headers = $mailbox->getMailerHeader(); | |
| 169 | + // Written by the agent, so the From name follows the inbox's From name setting. | |
| 170 | + $headers = $mailbox->getMailerHeader($agent); | |
| 167 | 171 | $headers = apply_filters('fluent_support/mail_to_customer_header', $headers, [ |
| 168 | 172 | 'cc_email' => $response->getSettingsValue('cc_email', []), |
| 169 | - 'hook_type' => 'ticket_replied_by_agent_email_to_customer' | |
| 173 | + 'hook_type' => 'ticket_replied_by_agent_email_to_customer', | |
| 174 | + 'ticket' => $ticket | |
| 170 | 175 | ]); |
| 171 | 176 | $attachments = []; |
| 172 | 177 | |
| 173 | 178 | if ($emailSettings['send_attachments'] == 'yes' && ($files = $response->attachments)) { |
| @@ -200,9 +205,9 @@ | ||
| 200 | 205 | |
| 201 | 206 | $ticket->load('customer'); |
| 202 | 207 | $customer = $ticket->customer; |
| 203 | 208 | |
| 204 | - if ($customer->status == 'inactive') { | |
| 209 | + if (!$customer->canReceiveNotifications()) { | |
| 205 | 210 | return false; |
| 206 | 211 | } |
| 207 | 212 | |
| 208 | 213 | if (!$this->shouldSendEmail($emailSettings, 'ticket_closed_by_agent_email_to_customer', $ticket, $customer)) { |
| @@ -225,12 +230,13 @@ | ||
| 225 | 230 | 'agent' => $agent, |
| 226 | 231 | 'email_type' => 'ticket_closed_by_agent_email_to_customer' |
| 227 | 232 | ]); |
| 228 | 233 | |
| 229 | - $headers = $mailbox->getMailerHeader(); | |
| 234 | + $headers = self::automatedHeaders($mailbox->getMailerHeader()); | |
| 230 | 235 | $headers = apply_filters('fluent_support/mail_to_customer_header', $headers, [ |
| 231 | 236 | 'cc_email' => $ticket->getSettingsValue('cc_email', []), |
| 232 | - 'hook_type' => 'ticket_closed_by_agent_email_to_customer' | |
| 237 | + 'hook_type' => 'ticket_closed_by_agent_email_to_customer', | |
| 238 | + 'ticket' => $ticket | |
| 233 | 239 | ]); |
| 234 | 240 | Mailer::send($customer->email, $subject, $emailBody, $headers); |
| 235 | 241 | } |
| 236 | 242 | } |
| @@ -276,9 +282,9 @@ | ||
| 276 | 282 | 'agent' => $agent, |
| 277 | 283 | 'email_type' => 'ticket_replied_by_customer_email_to_admin' |
| 278 | 284 | ]); |
| 279 | 285 | |
| 280 | - $headers = $mailbox->getMailerHeader(); | |
| 286 | + $headers = self::automatedHeaders($mailbox->getMailerHeader()); | |
| 281 | 287 | $attachments = []; |
| 282 | 288 | |
| 283 | 289 | if ($emailSettings['send_attachments'] == 'yes' && ($files = $response->attachments)) { |
| 284 | 290 | foreach ($files as $file) { |
| @@ -348,9 +354,9 @@ | ||
| 348 | 354 | 'assigner' => $assigner, |
| 349 | 355 | 'email_type' => 'ticket_agent_on_change' |
| 350 | 356 | ]); |
| 351 | 357 | |
| 352 | - $headers = $mailbox->getMailerHeader(); | |
| 358 | + $headers = self::automatedHeaders($mailbox->getMailerHeader()); | |
| 353 | 359 | |
| 354 | 360 | Mailer::send($emailTo, $subject, $emailBody, $headers); |
| 355 | 361 | } |
| 356 | 362 | } |
| @@ -358,9 +364,9 @@ | ||
| 358 | 364 | public function ticketCreatedByAgent($ticket, $customer, $agent) |
| 359 | 365 | { |
| 360 | 366 | $mailbox = $ticket->mailbox; |
| 361 | 367 | |
| 362 | - if (!$mailbox) { | |
| 368 | + if (!$mailbox || !$customer || !$customer->canReceiveNotifications()) { | |
| 363 | 369 | return; |
| 364 | 370 | } |
| 365 | 371 | |
| 366 | 372 | // Let's send welcome email to customer if enabled |
| @@ -382,9 +388,13 @@ | ||
| 382 | 388 | 'ticket' => $ticket, |
| 383 | 389 | 'email_type' => 'ticket_created_by_agent_email_to_customer' |
| 384 | 390 | ]); |
| 385 | 391 | |
| 386 | - $headers = $mailbox->getMailerHeader(); | |
| 392 | + $headers = apply_filters('fluent_support/mail_to_customer_header', self::automatedHeaders($mailbox->getMailerHeader()), [ | |
| 393 | + 'hook_type' => 'ticket_created_by_agent_email_to_customer', | |
| 394 | + 'cc_email' => [], | |
| 395 | + 'ticket' => $ticket | |
| 396 | + ]); | |
| 387 | 397 | |
| 388 | 398 | $attachments = []; |
| 389 | 399 | |
| 390 | 400 | if ($emailSettings['send_attachments'] == 'yes' && ($files = $ticket->attachments)) { |
| @@ -417,9 +427,9 @@ | ||
| 417 | 427 | |
| 418 | 428 | $ticket->load('customer'); |
| 419 | 429 | $customer = $ticket->customer; |
| 420 | 430 | |
| 421 | - if ($customer->status == 'inactive') { | |
| 431 | + if (!$customer->canReceiveNotifications()) { | |
| 422 | 432 | return false; |
| 423 | 433 | } |
| 424 | 434 | |
| 425 | 435 | $subject = apply_filters('fluent_support/parse_smartcode_data', $emailSettings['email_subject'], [ |
| @@ -440,9 +450,13 @@ | ||
| 440 | 450 | 'response' => $response, |
| 441 | 451 | 'email_type' => 'ticket_created_by_agent_on_behalf_email_to_customer' |
| 442 | 452 | ]); |
| 443 | 453 | |
| 444 | - $headers = $mailbox->getMailerHeader(); | |
| 454 | + $headers = apply_filters('fluent_support/mail_to_customer_header', $mailbox->getMailerHeader($agent), [ | |
| 455 | + 'hook_type' => 'ticket_created_by_agent_on_behalf_email_to_customer', | |
| 456 | + 'cc_email' => [], | |
| 457 | + 'ticket' => $ticket | |
| 458 | + ]); | |
| 445 | 459 | |
| 446 | 460 | $attachments = []; |
| 447 | 461 | |
| 448 | 462 | if ($emailSettings['send_attachments'] == 'yes') { |
| @@ -492,9 +506,9 @@ | ||
| 492 | 506 | $footerText = apply_filters('fluent_support/email_footer_credit', 'This email is a service from ' . $businessName . '. Support Plugin is Powered by <a href="' . esc_url($footerCreditUrl) . '" style="color:#9e9e9e;" target="_new">FluentSupport</a>.'); |
| 493 | 507 | |
| 494 | 508 | $data['email_footer'] = $footerText; |
| 495 | 509 | |
| 496 | - $emailTypeForCustomerFooter = ['ticket_created_email_to_customer', 'ticket_replied_by_agent_email_to_customer', 'ticket_closed_by_agent_email_to_customer']; | |
| 510 | + $emailTypeForCustomerFooter = ['ticket_created_email_to_customer', 'ticket_replied_by_agent_email_to_customer', 'ticket_closed_by_agent_email_to_customer', 'ticket_created_by_agent_on_behalf_email_to_customer']; | |
| 497 | 511 | |
| 498 | 512 | if (defined('FLUENTSUPPORTPRO') && in_array($data['email_type'], $emailTypeForCustomerFooter) |
| 499 | 513 | && !is_null($data['business']->email_footer)) { |
| 500 | 514 | $data['email_footer'] = apply_filters('fluent_support/parse_smartcode_data', $data['business']->email_footer, $data); |
| @@ -512,8 +526,29 @@ | ||
| 512 | 526 | return false; |
| 513 | 527 | } |
| 514 | 528 | |
| 515 | 529 | return apply_filters('fluent_support/should_send_notification', true, 'email', $emailType, $ticket, $person); |
| 530 | + } | |
| 531 | + | |
| 532 | + /** | |
| 533 | + * Mark a system-generated email (confirmations, closed notices, agent alerts) so | |
| 534 | + * autoresponders don't answer it (RFC 3834 Auto-Submitted, and Outlook's | |
| 535 | + * X-Auto-Response-Suppress). An answer would come back through email piping and | |
| 536 | + * could start a mail loop. Replies an agent writes are not marked. | |
| 537 | + * | |
| 538 | + * @param array $headers | |
| 539 | + * @return array | |
| 540 | + */ | |
| 541 | + public static function automatedHeaders($headers) | |
| 542 | + { | |
| 543 | + if (!apply_filters('fluent_support/mark_automated_emails', true)) { | |
| 544 | + return $headers; | |
| 545 | + } | |
| 546 | + | |
| 547 | + $headers[] = 'Auto-Submitted: auto-generated'; | |
| 548 | + $headers[] = 'X-Auto-Response-Suppress: All'; | |
| 549 | + | |
| 550 | + return $headers; | |
| 516 | 551 | } |
| 517 | 552 | |
| 518 | 553 | public function getMailerHeaderWithCc($headers, $info) |
| 519 | 554 | { |