From: Steve Sutton Date: Tue, 16 Jan 2018 19:28:18 +0000 (-0500) Subject: Send html emails. X-Git-Tag: v1.0.0^2~54 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=f1fadeca31e935d08fa8322fe453f8884d973d3b;p=WP-Plugins%2Fglm-member-db-registrations.git Send html emails. Creating new method for sending html emails using wp_mail function. --- diff --git a/classes/regCartSupport.php b/classes/regCartSupport.php index 1bfad46..3b663be 100644 --- a/classes/regCartSupport.php +++ b/classes/regCartSupport.php @@ -272,9 +272,9 @@ class GlmRegCartSupport // See if there's a hold for this registrant - expired ones should $holds = $this->wpdb->get_results(" - SELECT * - FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time_pending - WHERE registrant = ".$registrant['id']." + SELECT * + FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time_pending + WHERE registrant = ".$registrant['id']." ;", ARRAY_A); if (count($holds) > 0) { @@ -1015,9 +1015,9 @@ class GlmRegCartSupport // Get all expired holds or holds without a matching registrant $expHolds = $this->wpdb->get_results(" - SELECT * - FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time_pending - WHERE expire_time < NOW() + SELECT * + FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time_pending + WHERE expire_time < NOW() OR registrant NOT IN ( SELECT DISTINCT(id) FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request_registrant @@ -1065,9 +1065,9 @@ class GlmRegCartSupport // Get the reg_time entry $timeData = $this->wpdb->get_row(" - SELECT T.reg_event, T.attendee_max, T.attendee_count, T.attendees_pending, T.attendees_available, E.reg_hold_minutes - FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time T, ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_event E - WHERE T.id = $timeId + SELECT T.reg_event, T.attendee_max, T.attendee_count, T.attendees_pending, T.attendees_available, E.reg_hold_minutes + FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time T, ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_event E + WHERE T.id = $timeId AND E.id = T.reg_event ;", ARRAY_A); @@ -1113,8 +1113,8 @@ class GlmRegCartSupport // SELECT * FROM `items` WHERE `id`= LAST_INSERT_ID() $regTimePending = $this->wpdb->get_row(" - SELECT * from ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time_pending - WHERE id = $rtpId + SELECT * from ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time_pending + WHERE id = $rtpId ;", ARRAY_A); // Update counts in reg_time record @@ -1201,9 +1201,9 @@ class GlmRegCartSupport // Get current time data $time = $this->wpdb->get_row(" - SELECT attendee_max, attendee_count, attendees_pending, attendees_available - FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time - WHERE id = $timeId + SELECT attendee_max, attendee_count, attendees_pending, attendees_available + FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time + WHERE id = $timeId ;", ARRAY_A); if ($time == null) { @@ -1256,6 +1256,39 @@ class GlmRegCartSupport } + public function sendHtmlEmail( $to, $subject, $htmlMessage ) + { + // change the default wordpress from name when sending mail + add_filter( + 'wp_mail_from_name', + function ( $name ) { + $siteName = get_bloginfo( 'name' ); + return $siteName; + } + ); + // Send confirmation email, set the content type to allow html by using this filter + add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) ); + + $message = $htmlMessage; + $header[] = 'From:' . $this->config['settings']['reg_org_from_email']; + $header[] = 'Reply-To:' . $this->config['settings']['reg_org_from_email']; + + wp_mail( $to, $subject, $message, $header ); + + // remove the filter to avoid conflicts + remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) ); + } + + /** + * Set content type of the email. + * + * Used as filter for the wp_mail_content_type + */ + function set_content_type() + { + return "text/html"; + } + /* * Update inventory and send notifications for a cart * Used after successful checkout to update inventory @@ -1266,7 +1299,7 @@ class GlmRegCartSupport * happen at the same time and they both require walking through the cart data. * * @param string $summary HTML Summary of checkout for sending to owner and requesting address - * @param integer $requestId Specify the request ID - not requeired if cart is already loaded + * @param integer $requestId Specify the request ID - not required if cart is already loaded * * @return null * @@ -1300,7 +1333,7 @@ class GlmRegCartSupport if (trim($emailAddr) != '' && trim($summary) != '') { $subjectLine = $this->generateHTML($viewData, $regMisc['notify_subject'], true); $emailMsg = $this->generateHTML($viewData, nl2br($regMisc['notify_text']), true)."\n\n".$summary; - mail($emailAddr, $regMisc['notify_subject'], $emailMsg); + $this->sendHtmlEmail($emailAddr, $regMisc['notify_subject'], $emailMsg); } /* @@ -1317,7 +1350,7 @@ class GlmRegCartSupport if ($emailAddr != '') { $subjectLine = $this->generateHTML($viewData, $regMisc['submission_notify_subject'], true); $emailMsg = $this->generateHTML($viewData, nl2br($regMisc['submission_notify_text']), true)."\n\n".$summary; - mail($emailAddr, $subjectLine, $emailMsg); + $this->sendHtmlEmail($emailAddr, $subjectLine, $emailMsg); } } @@ -1359,7 +1392,7 @@ class GlmRegCartSupport $viewData['registrant'] = $registrant; $subjectLine = $this->generateHTML($viewData, $regMisc['registrant_notify_subject'], true); $emailMsg = $this->generateHTML($viewData, nl2br($regMisc['registrant_notify_text']), true); - mail($emailAddr, $subjectLine, $emailMsg); + $this->sendHtmlEmail($emailAddr, $subjectLine, $emailMsg); } } @@ -1369,7 +1402,7 @@ class GlmRegCartSupport } /* - * Send notifications to contcts listed in event + * Send notifications to contacts listed in event */ $viewData['event'] = $event; $eventOther = $RegEvent->getRegEventSimplified($event['reg_event']); @@ -1378,7 +1411,7 @@ class GlmRegCartSupport $viewData['eventRegistrants'] = $eventRegistrants; $subjectLine = $this->generateHTML($viewData, $regMisc['instr_notify_subject'], true); $emailMsg = $this->generateHTML($viewData, nl2br($regMisc['instr_notify_text']), true); - mail($emailAddr, $subjectjectLine, $emailMsg); + $this->sendHtmlEmail($emailAddr, $subjectjectLine, $emailMsg); } }