PluginProbe
WP Mail Log / dev
WP Mail Log vdev
1.1.6 trunk 0.1 0.2 0.3 0.4 0.5 1.0 1.0.1 1.0.2 1.1.1 1.1.2 1.1.3 1.1.5 dev
wp-mail-log / classes / capture-mail.php

capture-mail.php in WP Mail Log dev, at classes/capture-mail.php

61 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WML\Classes;
4
5 /**
6 * Capture Mail
7 *
8 * This class is to manage capture mail & save to databse.
9 *
10 */
11 class Capture_Mail {
12
13 /**
14 * This function fire on wp_mail filter in bootstrap file.
15 *
16 * This function will save the email data to database table.
17 *
18 * @access public
19 * @since 0.3
20 * @param array @var $mail_info this info comes with filter.
21 * @return array unmodified $mail_info
22 */
23 public static function log_email( $mail_info ) {
24 global $wpdb;
25 $table_name = $wpdb->prefix . 'wml_entries';
26 $attachment_present = ( is_array( $mail_info['attachments'] ) && count( $mail_info['attachments'] ) > 0 ) ? 'true' : 'false';
27 if ( is_array( $mail_info['to'] ) ) {
28 $mail_to = implode( ', ', $mail_info['to'] );
29 } else {
30 $mail_to = $mail_info['to'];
31 $parts = explode( ',', $mail_to );
32 $mail_to = implode( ', ', $parts );
33 }
34 $attachedFiles = [];
35 if($attachment_present){
36 $files = $mail_info['attachments'];
37
38 foreach ($files as $key => $value) {
39 $attachedFiles[] = substr($value,strpos($value,'/uploads/') + strlen('/uploads/') - 1,strlen($value));
40 }
41 };
42 // Log into the database
43 $wpdb->insert(
44 $table_name,
45 [
46 'to_email' => $mail_to,
47 'subject' => $mail_info['subject'],
48 'message' => $mail_info['message'],
49 'headers' => $mail_info['headers'],
50 'attachments' => $attachment_present,
51 'sent_date' => current_time( 'mysql', $gmt = 0 ),
52 'captured_gmt' => current_time( 'mysql', $gmt = 1 ),
53 'attachments_file' => implode(',', $attachedFiles),
54 ]
55 );
56
57 // return unmodifiyed array
58 return $mail_info;
59 }
60 }
61