PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.3
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Util / MailNotifier.php

MailNotifier.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 1.3, at includes/Core/Util/MailNotifier.php

102 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace BitCode\BitForm\Core\Util;
3
4 use BitCode\BitForm\Core\Util\MailConfig;
5 use BitCode\BitForm\Core\Util\FieldValueHandler;
6 use BitCode\BitForm\Core\Messages\EmailTemplateHandler;
7
8 final class MailNotifier
9 {
10 public static function notify($notifyDetails, $formID, $fieldValue, $entryID)
11 {
12 $emailTemplateHandler = new EmailTemplateHandler($formID);
13 if (is_string($notifyDetails->id)) {
14 $mailTemplateID = json_decode($notifyDetails->id)->id;
15 $mailTemplate = $emailTemplateHandler->getATemplate($mailTemplateID);
16 if (!is_wp_error($mailTemplate)) {
17 $mailTo = FieldValueHandler::validateMailArry($notifyDetails->to, $fieldValue);
18 if (!empty($mailTo)) {
19 (new MailConfig())->sendMail();
20 $mailSubject = FieldValueHandler::replaceFieldWithValue($mailTemplate[0]->sub, $fieldValue);
21 $mailBody = FieldValueHandler::replaceFieldWithValue($mailTemplate[0]->body, $fieldValue);
22
23 $mailHeaders = array(
24 // "Content-Type: text/html; charset=UTF-8",
25 );
26 if (!empty($notifyDetails->replyto)) {
27 $mailReplyto = FieldValueHandler::validateMailArry($notifyDetails->replyto, $fieldValue);
28 if (is_array($mailReplyto)) {
29 foreach ($mailReplyto as $key => $emailAddress) {
30 $mailHeaders[] = "Reply-To: " . trim($emailAddress);
31 }
32 } else {
33 $mailHeaders[] = "Reply-To: " . trim($mailReplyto);
34 }
35 }
36 if (!empty($notifyDetails->bcc)) {
37 $mailBCC = FieldValueHandler::validateMailArry($notifyDetails->bcc, $fieldValue);
38 if (is_array($mailBCC)) {
39 foreach ($mailBCC as $key => $emailAddress) {
40 $mailHeaders[] = "Bcc: " . trim($emailAddress);
41 }
42 } else {
43 $mailHeaders[] = "Bcc: " . trim($mailBCC);
44 }
45 }
46 if (!empty($notifyDetails->cc)) {
47 $mailCC = FieldValueHandler::validateMailArry($notifyDetails->cc, $fieldValue);
48 if (is_array($mailCC)) {
49 foreach ($mailCC as $key => $emailAddress) {
50 $mailHeaders[] = "Cc: " . trim($emailAddress);
51 }
52 } else {
53 $mailHeaders[] = "Cc: " . trim($mailCC);
54 }
55 }
56 $attachments = [];
57 if (!empty($notifyDetails->attachment)) {
58 $files = $notifyDetails->attachment;
59 $fileBasePath = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID . DIRECTORY_SEPARATOR;
60 if (is_array($files)) {
61 foreach ($files as $file) {
62 if (isset($fieldValue[$file])) {
63 if (is_array($fieldValue[$file])) {
64 foreach ($fieldValue[$file] as $singleFile) {
65 if (\is_readable("{$fileBasePath}{$singleFile}")) {
66 $attachments[] = "{$fileBasePath}{$singleFile}";
67 }
68 }
69 } elseif (\is_readable("{$fileBasePath}{$fieldValue[$file]}")) {
70 $attachments[] = "{$fileBasePath}{$fieldValue[$file]}";
71 }
72 }
73 }
74 } else if (isset($fieldValue[$files])) {
75 if (is_array($fieldValue[$files])) {
76 foreach ($fieldValue[$files] as $singleFile) {
77 if (\is_readable("{$fileBasePath}{$singleFile}")) {
78 $attachments[] = "{$fileBasePath}{$singleFile}";
79 }
80 }
81 } elseif (\is_readable("{$fileBasePath}{$fieldValue[$files]}")) {
82 $attachments[] = "{$fileBasePath}{$fieldValue[$files]}";
83 }
84 }
85 }
86 add_filter('wp_mail_content_type', [self::class, 'filterMailContentType']);
87 $status = wp_mail($mailTo, $mailSubject, $mailBody, $mailHeaders, $attachments);
88 if (!$status) {
89 wp_mail($mailTo, $mailSubject, $mailBody, $mailHeaders);
90 }
91 remove_filter('wp_mail_content_type', [self::class, 'filterMailContentType']);
92 }
93 }
94 }
95 }
96
97 public static function filterMailContentType()
98 {
99 return 'text/html; charset=UTF-8';
100 }
101 }
102