PluginProbe ʕ •ᴥ•ʔ
Easy HTTPS Redirection (SSL) / 2.0.1
Easy HTTPS Redirection (SSL) v2.0.1
trunk 1.5 1.6 1.8 1.9.1 1.9.2 2.0.0 2.0.1
https-redirection / classes / ehssl-email-handler.php
https-redirection / classes Last commit date
utilities 1 day ago ehssl-config.php 1 year ago ehssl-cronjob.php 1 year ago ehssl-custom-post-types.php 1 year ago ehssl-debug-logger.php 1 year ago ehssl-email-handler.php 1 year ago ehssl-init-time-tasks.php 1 day ago ehssl-installation.php 1 day ago ehssl-non-https-resources-scan-result-table.php 1 day ago ehssl-non-https-resources-scan-update.php 1 day ago ehssl-rules-helper.php 1 day ago ehssl-ssl-certificate.php 1 year ago index.php 1 year ago
ehssl-email-handler.php
121 lines
1 <?php
2
3 class EHSSL_Email_handler {
4
5 public static function send_expiry_notification_email( $cert_data ) {
6 $settings = get_option( 'httpsrdrctn_options', array() );
7
8 $content_type = isset( $settings['ehssl_expiry_notification_email_content_type'] ) ? sanitize_text_field( $settings['ehssl_expiry_notification_email_content_type'] ) : '';
9 $from = isset( $settings['ehssl_expiry_notification_email_from'] ) ? sanitize_text_field( $settings['ehssl_expiry_notification_email_from'] ) : '';
10 $to = isset( $settings['ehssl_expiry_notification_email_to'] ) ? sanitize_email( $settings['ehssl_expiry_notification_email_to'] ) : '';
11
12 if ( empty( $to ) ) {
13 EHSSL_Logger::log( 'Recipient email address could not be found to send expiry notification email.', 4 );
14
15 return false;
16 }
17
18 $subj = isset( $settings['ehssl_expiry_notification_email_subject'] ) ? sanitize_text_field( $settings['ehssl_expiry_notification_email_subject'] ) : '';
19
20 $body = isset( $settings['ehssl_expiry_notification_email_body'] ) ? sanitize_textarea_field( $settings['ehssl_expiry_notification_email_body'] ) : '';
21 $body = self::apply_dynamic_tags( $body, $cert_data );
22
23 $headers = array();
24 if ( ! empty( $content_type ) && $content_type === 'html' ) {
25 $headers[] = 'Content-Type: text/html; charset=UTF-8';
26 $body = nl2br( $body );
27 }
28 $headers[] = 'From: ' . $from;
29
30 try {
31 wp_mail( $to, $subj, $body, $headers );
32 EHSSL_Logger::log( 'SSL certificate expiry notification email sent to : ' . $to . ', From email address used: ' . $from );
33
34 return true;
35 } catch ( \Exception $e ) {
36 EHSSL_Logger::log( 'SSL certificate expiry notification email couldn\'t be sent to : ' . $to . ', From email address used: ' . $from, 4 );
37 }
38
39 return false;
40 }
41
42 public static function apply_dynamic_tags( $body, $data ) {
43 $tags = array(
44 '{label}',
45 '{issuer}',
46 '{issue_date}',
47 '{issue_time}',
48 '{issue_datetime}',
49 '{expiry_date}',
50 '{expiry_time}',
51 '{expiry_datetime}',
52 '{status}',
53 );
54
55 $values = array(
56 $data['label'],
57 $data['issuer'],
58 EHSSL_Utils::parse_date( $data['issued_on'] ),
59 EHSSL_Utils::parse_time( $data['issued_on'] ),
60 EHSSL_Utils::parse_timestamp( $data['issued_on'] ),
61 EHSSL_Utils::parse_date( $data['expires_on'] ),
62 EHSSL_Utils::parse_time( $data['expires_on'] ),
63 EHSSL_Utils::parse_timestamp( $data['expires_on'] ),
64 ucfirst( EHSSL_SSL_Utils::get_certificate_status( $data['expires_on'] ) ),
65 );
66
67 return stripslashes( str_replace( $tags, $values, $body ) );
68 }
69
70 public static function get_merge_tags_hints() {
71 ob_start()
72 ?>
73 <div class="ehssl-settings-field-cat-3">
74 <a href="#" class="ehssl-toggle toggled-off"> <?php _e( 'Click here to toggle email merge tag hints', 'https-redirection' ) ?></a>
75 <div class="ehssl-tags-table-cont hidden">
76 <table class="ehssl-tags-hint widefat striped">
77 <tbody>
78 <tr>
79 <td class="ehssl-tag-name"><b>{label}</b></td>
80 <td class="ehssl-tag-descr"><?php _e('The SSL certificate label', 'https-redirection') ?></td>
81 </tr>
82 <tr>
83 <td class="ehssl-tag-name"><b>{issuer}</b></td>
84 <td class="ehssl-tag-descr"><?php _e('The issuer of SSL certificate', 'https-redirection') ?></td>
85 </tr>
86 <tr>
87 <td class="ehssl-tag-name"><b>{issue_date}</b></td>
88 <td class="ehssl-tag-descr"><?php _e('The issuing date of SSL certificate.', 'https-redirection') ?></td>
89 </tr>
90 <tr>
91 <td class="ehssl-tag-name"><b>{issue_time}</b></td>
92 <td class="ehssl-tag-descr"><?php _e('The issuing time of SSL certificate.', 'https-redirection') ?></td>
93 </tr>
94 <tr>
95 <td class="ehssl-tag-name"><b>{issue_datetime}</b></td>
96 <td class="ehssl-tag-descr"><?php _e('The issuing datetime of SSL certificate.', 'https-redirection') ?></td>
97 </tr>
98 <tr>
99 <td class="ehssl-tag-name"><b>{expiry_date}</b></td>
100 <td class="ehssl-tag-descr"><?php _e('The expiry date of SSL certificate.', 'https-redirection') ?></td>
101 </tr>
102 <tr>
103 <td class="ehssl-tag-name"><b>{expiry_time}</b></td>
104 <td class="ehssl-tag-descr"><?php _e('The expiry time of SSL certificate.', 'https-redirection') ?></td>
105 </tr>
106 <tr>
107 <td class="ehssl-tag-name"><b>{expiry_datetime}</b></td>
108 <td class="ehssl-tag-descr"><?php _e('The expiry datetime of SSL certificate.', 'https-redirection') ?></td>
109 </tr>
110 <tr>
111 <td class="ehssl-tag-name"><b>{status}</b></td>
112 <td class="ehssl-tag-descr"><?php _e('The current status of SSL certificate.', 'https-redirection') ?></td>
113 </tr>
114 </tbody>
115 </table>
116 </div>
117 </div>
118 <?php
119 return ob_get_clean();
120 }
121 }