PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.15.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.15.3
3.3.1 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 All 138 releases
← All changes | includes/Core/Util/MailNotifier.php +52 -6 2.02.15.3 View file →
@@ -3,12 +3,48 @@
3 3 namespace BitCode\BitForm\Core\Util;
4 4
5 5 use BitCode\BitForm\Core\Database\FormEntryMetaModel;
6 6 use BitCode\BitForm\Core\Messages\EmailTemplateHandler;
7 +use BitCode\BitForm\Core\Messages\PdfTemplateHandler;
8 +use BitCode\BitFormPro\Admin\AppSetting\Pdf;
7 9
8 -final class MailNotifier {
9 - public static function notify($notifyDetails, $formID, $fieldValue, $entryID, $isDblOptin = false, $logId = '') {
10 +final class MailNotifier
11 +{
12 + public static function notify($notifyDetails, $formID, $fieldValue, $entryID, $isDblOptin = false, $logId = '')
13 + {
10 14 $emailTemplateHandler = new EmailTemplateHandler($formID);
15 + $attachments = [];
16 + $tempPdfLink = '';
17 + if (!empty($notifyDetails->pdfId) && is_string($notifyDetails->pdfId)) {
18 + $pdfTemplateID = json_decode($notifyDetails->pdfId)->id;
19 + $pdfTemplateHandler = new PdfTemplateHandler($formID);
20 +
21 + $pdfTemplate = $pdfTemplateHandler->getById($pdfTemplateID);
22 + $pdfBody = FieldValueHandler::replaceFieldWithValue($pdfTemplate[0]->body, $fieldValue);
23 +
24 + $pdfSetting = json_decode($pdfTemplate[0]->setting);
25 +
26 + $path = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'pdf';
27 + $fileName = 'bit-form-pdf-' . $formID . '-' . $entryID;
28 +
29 + if (!is_dir($path)) {
30 + mkdir($path, 0777, true);
31 + }
32 +
33 + if (class_exists('\BitCode\BitFormPro\Admin\AppSetting\Pdf')) {
34 + $generatedPdf = Pdf::getInstance()->generator($pdfSetting, $pdfBody, $path, $entryID, 'F');
35 +
36 + // $pdfFile = $path . DIRECTORY_SEPARATOR . $fileName . '.pdf';
37 +
38 + if (!is_wp_error($generatedPdf) && file_exists($generatedPdf)) {
39 + $attachments[] = $generatedPdf;
40 + $tempPdfLink = $generatedPdf;
41 + } else {
42 + Log::debug_log('Error in generating PDF: ' . $generatedPdf->get_error_message());
43 + }
44 + }
45 + }
46 +
11 47 if (is_string($notifyDetails->id)) {
12 48 $mailTemplateID = json_decode($notifyDetails->id)->id;
13 49 $mailTemplate = $emailTemplateHandler->getATemplate($mailTemplateID);
14 50 if (!is_wp_error($mailTemplate)) {
@@ -13,9 +49,13 @@
13 49 $mailTemplate = $emailTemplateHandler->getATemplate($mailTemplateID);
14 50 if (!is_wp_error($mailTemplate)) {
15 51 $mailTo = FieldValueHandler::validateMailArry($notifyDetails->to, $fieldValue);
16 52 if (!empty($mailTo)) {
17 - (new MailConfig())->sendMail();
53 + $from_name = '';
54 + if (isset($notifyDetails->from_name) && !empty($notifyDetails->from_name)) {
55 + $from_name = $notifyDetails->from_name;
56 + }
57 + (new MailConfig())->sendMail(['from_name' => $from_name]);
18 58 $mailSubject = FieldValueHandler::replaceFieldWithValue($mailTemplate[0]->sub, $fieldValue);
19 59 $mailBody = FieldValueHandler::replaceFieldWithValue($mailTemplate[0]->body, $fieldValue);
20 60
21 61 $mailHeaders = [
@@ -63,9 +103,9 @@
63 103 $mailFrom = FieldValueHandler::validateMailArry($notifyDetails->from, $fieldValue);
64 104 $fromName = !empty($notifyDetails->fromName) ? $notifyDetails->fromName : explode('@', $mailFrom[0])[0];
65 105 $mailHeaders[] = "FROM: $fromName " . '<' . sanitize_email($mailFrom[0]) . '>';
66 106 }
67 - $attachments = [];
107 +
68 108 if (!empty($notifyDetails->attachment)) {
69 109 $files = $notifyDetails->attachment;
70 110 $fileBasePath = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID . DIRECTORY_SEPARATOR;
71 111 if (is_array($files)) {
@@ -107,9 +147,10 @@
107 147 $entryMeta->insert(
108 148 [
109 149 'bitforms_form_entry_id' => $entryID,
110 150 'meta_key' => 'entry_confirm_activation',
111 - 'meta_value' => $data['token']]
151 + 'meta_value' => $data['token']
152 + ]
112 153 );
113 154 }
114 155 remove_filter('wp_mail_content_type', [self::class, 'filterMailContentType']);
115 156 }
@@ -114,10 +155,15 @@
114 155 remove_filter('wp_mail_content_type', [self::class, 'filterMailContentType']);
115 156 }
116 157 }
117 158 }
159 +
160 + if (!empty($tempPdfLink)) {
161 + wp_delete_file($tempPdfLink);
162 + }
118 163 }
119 164
120 - public static function filterMailContentType() {
165 + public static function filterMailContentType()
166 + {
121 167 return 'text/html; charset=UTF-8';
122 168 }
123 169 }