Plugin Directory

Changeset 2700416


Ignore:
Timestamp:
03/28/2022 05:23:13 AM (4 years ago)
Author:
mailazy
Message:
  • Added test email functionality
Location:
mailazy
Files:
20 added
5 edited

Legend:

Unmodified
Added
Removed
  • mailazy/trunk/admin/assets/css/style.css

    r2651280 r2700416  
    1 #toplevel_page_mailazy img{
    2     width: 28px;
    3     height: 28px;
    4 }
    51#mailazy_admin {
    62    margin-top: 20px;
  • mailazy/trunk/admin/index.php

    r2651280 r2700416  
    11<?php
     2
    23// Exit if called directly
    34if (!defined('ABSPATH')) {
     
    1011     * The main class and initialization point of the plugin.
    1112     */
    12     class mailazy_Admin
    13     {
     13    class mailazy_Admin {
    1414
    1515        /**
    1616         * Constructor
    1717         */
    18         public function __construct()
    19         {
     18        public function __construct() {
    2019            if (is_admin()) {
    2120                add_action('admin_init', array($this, 'register_mailazy_plugin_settings'));
     21                add_action('admin_init', array($this, 'register_mailazy_plugin_test_mail'));
    2222            }
    2323            add_action('admin_menu', array($this, 'create_mailazy_menu'));
     
    2626            add_action('admin_enqueue_scripts', array($this, 'add_stylesheet_to_admin'));
    2727        }
     28
    2829        /**
    2930         * Save Plugin option on option table
    3031         */
    31         public function register_mailazy_plugin_settings()
    32         {
    33             register_setting('mailazy_option', 'mailazy_option', array($this,'mailazy_settings_validation'));
     32        public function register_mailazy_plugin_settings() {
     33            register_setting('mailazy_option', 'mailazy_option', array($this, 'mailazy_settings_validation'));
    3434        }
     35
     36        /**
     37         * test email after save setting
     38         */
     39        public function register_mailazy_plugin_test_mail() {
     40            register_setting('mailazy_test_mail', 'mailazy_test_mail', array($this, 'mailazy_test_mail_validation'));
     41        }
     42
     43        public function mailazy_test_mail_validation($input) {
     44            $message = __('There was a problem.');
     45            $type = 'error';
     46            if (isset($input['test_to']) && !empty($input['test_to'])) {
     47                $subject = 'Test email from ' . get_bloginfo('name') . ' via Mailazy Plugin';
     48                $mailBody = 'Hi test,' . "<br/><br/>";
     49                $mailBody .= wp_title() . ' Mailazy test email received.' . "<br/>";
     50
     51                $res = json_decode(wp_mail($input['test_to'], $subject, $mailBody));
     52                if (isset($res->error) && !empty($res->error)) {
     53                    $message = __("<b>" . $res->error . "</b>: " . $res->message);
     54                } else {
     55                    $message = __('Mail Sent!');
     56                    $type = 'updated';
     57                }
     58            }
     59            add_settings_error('mailazy_test_mail_notice', 'mailazy_test_mail', $message, $type);
     60        }
     61
    3562        /**
    3663         * Mailazy Validation
    3764         */
    38         public function mailazy_settings_validation($input)
    39         {
     65        public function mailazy_settings_validation($input) {
    4066            $message = null;
    4167            $type = null;
     
    6490                $type = 'error';
    6591            }
    66            
     92
    6793            add_settings_error('mailazy_option_notice', 'mailazy_option', $message, $type);
    6894            return $input;
    6995        }
     96
    7097        /**
    7198         *
     
    73100         * @param type $settings
    74101         */
    75         public static function reset_settings_action($option, $settings)
    76         {
     102        public static function reset_settings_action($option, $settings) {
    77103            if (current_user_can('manage_options')) {
    78104                update_option($option, $settings);
    79105            }
    80106        }
     107
    81108        /**
    82109         * Create menu.
    83110         */
    84         public function create_mailazy_menu()
    85         {
    86             add_menu_page('mailazy', 'Mailazy', 'manage_options', 'mailazy', array('mailazy_Admin', 'options_page'), MAILAZY_ROOT_URL . 'admin/assets/images/favicon.ico');
     111        public function create_mailazy_menu() {
     112            add_menu_page('mailazy', 'Mailazy', 'manage_options', 'mailazy', array('mailazy_Admin', 'setting_page'), MAILAZY_ROOT_URL . 'admin/assets/images/favicon.png');
     113            $mailazy_option = get_option('mailazy_option');
     114            if (isset($mailazy_option['enable']) && $mailazy_option['enable'] == "1") {
     115                add_submenu_page('mailazy', 'Mailazy', 'Test Mail', 'manage_options', 'mailazy-test-mail', array('mailazy_Admin', 'test_mail_page'));
     116            }
    87117        }
     118
    88119        /**
    89120         * Add a settings link to the Plugins page,
    90121         * so people can go straight from the plugin page to the settings page.
    91122         */
    92         public function mailazy_setting_links($links, $file)
    93         {
     123        public function mailazy_setting_links($links, $file) {
    94124            static $thisPlugin = '';
    95125            if (empty($thisPlugin)) {
     
    103133            return $links;
    104134        }
     135
    105136        /**
    106137         * Added Style and Script file on plguin Admin Page
    107138         */
    108         public function add_stylesheet_to_admin()
    109         {
     139        public function add_stylesheet_to_admin() {
    110140            wp_enqueue_style('mailazy-admin-style', MAILAZY_ROOT_URL . 'admin/assets/css/style.css', false, MAILAZY_PLUGIN_VERSION);
    111141        }
     
    115145         * This is the first function which is called while plugin admin page is requested
    116146         */
    117         public static function options_page()
    118         {
     147
     148        public static function setting_page() {
    119149            require_once(MAILAZY_ROOT_DIR . "admin/views/settings.php");
    120150        }
     151
     152        /*
     153         * Callback for add_menu_page,
     154         * This is the first function which is called while plugin admin page is requested
     155         */
     156
     157        public static function test_mail_page() {
     158            require_once(MAILAZY_ROOT_DIR . "admin/views/test_mail.php");
     159        }
     160
    121161    }
     162
    122163    new mailazy_Admin();
    123164}
  • mailazy/trunk/mailazy.php

    r2693410 r2700416  
    55 * Plugin URI: https://github.com/mailazy/wordpress
    66 * Description: Mailazy provides a secure and delightful experience to your customer with Email API.
    7  * Version: 1.3
     7 * Version: 1.4
    88 * Author: Mailazy Team
    99 * Author URI: https://mailazy.com
     
    1616define('MAILAZY_ROOT_DIR', plugin_dir_path(__FILE__));
    1717define('MAILAZY_ROOT_URL', plugin_dir_url(__FILE__));
    18 define('MAILAZY_PLUGIN_VERSION', '1.3');
     18define('MAILAZY_PLUGIN_VERSION', '1.4');
    1919define('MAILAZY_ROOT_SETTING_LINK', plugin_basename(__FILE__));
    2020
     
    2424     * The main class and initialization point of the plugin.
    2525     */
    26     class mailazyPlugin
    27     {
     26    class mailazyPlugin {
    2827
    2928        /**
    3029         * Constructor
    3130         */
    32         public function __construct()
    33         {
     31        public function __construct() {
    3432            $this->define_constants();
    35             //add_action( 'phpmailer_init', array($this,'mailazy_phpmailer_init') );
    36             $mailazy_option = get_option('mailazy_option');
    37             if(!function_exists('wp_mail') && isset($mailazy_option['enable']) && $mailazy_option['enable']=="1"){
    38                 /**
    39                  * Sends an email, similar to PHP's mail function.
    40                  *
    41                  * A true return value does not automatically mean that the user received the
    42                  * email successfully. It just only means that the method used was able to
    43                  * process the request without any errors.
    44                  *
    45                  * The default content type is `text/plain` which does not allow using HTML.
    46                  * However, you can set the content type of the email by using the
    47                  * {@see 'wp_mail_content_type'} filter.
    48                  *
    49                  * The default charset is based on the charset used on the blog. The charset can
    50                  * be set using the {@see 'wp_mail_charset'} filter.
    51                  *
    52                  * @since 1.2.1
    53                  * @since 5.5.0 is_email() is used for email validation,
    54                  *              instead of emailService's default validator.
    55                  *
    56                  * @global emailService\emailService\emailService $emailService
    57                  *
    58                  * @param string|string[] $to          Array or comma-separated list of email addresses to send message.
    59                  * @param string          $subject     Email subject.
    60                  * @param string          $message     Message contents.
    61                  * @param string|string[] $headers     Optional. Additional headers.
    62                  * @param string|string[] $attachments Optional. Paths to files to attach.
    63                  * @return bool Whether the email was sent successfully.
    64                  */
    65                 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
    66                     $mailazy_option = get_option('mailazy_option');
    67                     // Compact the input, apply the filters, and extract them back out.
    68                     /**
    69                      * Filters the wp_mail() arguments.
    70                      *
    71                      * @since 2.2.0
    72                      *
    73                      * @param array $args {
    74                      *     Array of the `wp_mail()` arguments.
    75                      *
    76                      *     @type string|string[] $to          Array or comma-separated list of email addresses to send message.
    77                      *     @type string          $subject     Email subject.
    78                      *     @type string          $message     Message contents.
    79                      *     @type string|string[] $headers     Additional headers.
    80                      *     @type string|string[] $attachments Paths to files to attach.
    81                      * }
    82                      */
    83                     $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );
    84 
    85                     /**
    86                      * Filters whether to preempt sending an email.
    87                      *
    88                      * Returning a non-null value will short-circuit {@see wp_mail()}, returning
    89                      * that value instead. A boolean return value should be used to indicate whether
    90                      * the email was successfully sent.
    91                      *
    92                      * @since 5.7.0
    93                      *
    94                      * @param null|bool $return Short-circuit return value.
    95                      * @param array     $atts {
    96                      *     Array of the `wp_mail()` arguments.
    97                      *
    98                      *     @type string|string[] $to          Array or comma-separated list of email addresses to send message.
    99                      *     @type string          $subject     Email subject.
    100                      *     @type string          $message     Message contents.
    101                      *     @type string|string[] $headers     Additional headers.
    102                      *     @type string|string[] $attachments Paths to files to attach.
    103                      * }
    104                      */
    105                     $pre_wp_mail = apply_filters( 'pre_wp_mail', null, $atts );
    106 
    107                     if ( null !== $pre_wp_mail ) {
    108                         return $pre_wp_mail;
    109                     }
    110 
    111                     if ( isset( $atts['to'] ) ) {
    112                         $to = $atts['to'];
    113                     }
    114 
    115                     if ( ! is_array( $to ) ) {
    116                         $to = explode( ',', $to );
    117                     }
    118 
    119                     if ( isset( $atts['subject'] ) ) {
    120                         $subject = $atts['subject'];
    121                     }
    122 
    123                     if ( isset( $atts['message'] ) ) {
    124                         $message = $atts['message'];
    125                     }
    126 
    127                     if ( isset( $atts['headers'] ) ) {
    128                         $headers = $atts['headers'];
    129                     }
    130 
    131                     if ( isset( $atts['attachments'] ) ) {
    132                         $attachments = $atts['attachments'];
    133                     }
    134 
    135                     if ( ! is_array( $attachments ) ) {
    136                         $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
    137                     }
    138                     global $emailService;
    139 
    140                     // (Re)create it, if it's gone missing.
    141                     if ( ! ( $emailService instanceof mailazyWPClient ) ) {
    142                         require_once(MAILAZY_ROOT_DIR."mailazyWPClient.php");
    143                         $emailService = new mailazyWPClient();
    144                         $emailService->setApikey($mailazy_option['apikey']);
    145                         $emailService->setApisecret($mailazy_option['apisecretkey']);
    146                     }
    147 
    148                     // Headers.
    149                     $cc       = array();
    150                     $bcc      = array();
    151                     $reply_to = array();
    152 
    153                     if ( empty( $headers ) ) {
    154                         $headers = array();
    155                     } else {
    156                         if ( ! is_array( $headers ) ) {
    157                             // Explode the headers out, so this function can take
    158                             // both string headers and an array of headers.
    159                             $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
    160                         } else {
    161                             $tempheaders = $headers;
    162                         }
    163                         $headers = array();
    164 
    165                         // If it's actually got contents.
    166                         if ( ! empty( $tempheaders ) ) {
    167                             // Iterate through the raw headers.
    168                             foreach ( (array) $tempheaders as $header ) {
    169                                 if ( strpos( $header, ':' ) === false ) {
    170                                     if ( false !== stripos( $header, 'boundary=' ) ) {
    171                                         $parts    = preg_split( '/boundary=/i', trim( $header ) );
    172                                         $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
    173                                     }
    174                                     continue;
    175                                 }
    176                                 // Explode them out.
    177                                 list( $name, $content ) = explode( ':', trim( $header ), 2 );
    178 
    179                                 // Cleanup crew.
    180                                 $name    = trim( $name );
    181                                 $content = trim( $content );
    182 
    183                                 switch ( strtolower( $name ) ) {
    184                                     // Mainly for legacy -- process a "From:" header if it's there.
    185                                     case 'content-type':
    186                                         if ( strpos( $content, ';' ) !== false ) {
    187                                             list( $type, $charset_content ) = explode( ';', $content );
    188                                             $content_type                   = trim( $type );
    189                                             if ( false !== stripos( $charset_content, 'charset=' ) ) {
    190                                                 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset_content ) );
    191                                             } elseif ( false !== stripos( $charset_content, 'boundary=' ) ) {
    192                                                 $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) );
    193                                                 $charset  = '';
    194                                             }
    195 
    196                                             // Avoid setting an empty $content_type.
    197                                         } elseif ( '' !== trim( $content ) ) {
    198                                             $content_type = trim( $content );
    199                                         }
    200                                         break;
    201                                     case 'cc':
    202                                         $cc = array_merge( (array) $cc, explode( ',', $content ) );
    203                                         break;
    204                                     case 'bcc':
    205                                         $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
    206                                         break;
    207                                     case 'reply-to':
    208                                         $reply_to = array_merge( (array) $reply_to, explode( ',', $content ) );
    209                                         break;
    210                                     default:
    211                                         // Add it to our grand headers array.
    212                                         $headers[ trim( $name ) ] = trim( $content );
    213                                         break;
    214                                 }
    215                             }
    216                         }
    217                     }
    218                    
    219                     try {
    220                         $emailService->setFrom( $mailazy_option['fromemail'] );
    221                     } catch ( Exception $e ) {
    222                         $mail_error_data                             = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
    223                         $mail_error_data['phpmailer_exception_code'] = $e->getCode();
    224 
    225                         /** This filter is documented in wp-includes/pluggable.php */
    226                         do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
    227 
    228                         return false;
    229                     }
    230 
    231                     // Set mail's subject and body.
    232                     $emailService->setSubject($subject);
    233                     $emailService->setBody($message);
    234 
    235                     // Set destination addresses, using appropriate methods for handling addresses.
    236                     $address_headers = compact( 'to', 'cc', 'bcc', 'reply_to' );
    237 
    238                     foreach ( $address_headers as $address_header => $addresses ) {
    239                         if ( empty( $addresses ) ) {
    240                             continue;
    241                         }
    242 
    243                         foreach ( (array) $addresses as $address ) {
    244                             try {
    245                                 // Break $recipient into name and address parts if in the format "Foo <[email protected]>".
    246                                 $recipient_name = '';
    247 
    248                                 if ( preg_match( '/(.*)<(.+)>/', $address, $matches ) ) {
    249                                     if ( count( $matches ) == 3 ) {
    250                                         $recipient_name = $matches[1];
    251                                         $address        = $matches[2];
    252                                     }
    253                                 }
    254 
    255                                 switch ( $address_header ) {
    256                                     case 'to':
    257                                         $emailService->addAddress( $address, $recipient_name );
    258                                         break;
    259                                     case 'cc':
    260                                         $emailService->addCC( $address, $recipient_name );
    261                                         break;
    262                                     case 'bcc':
    263                                         $emailService->addBCC( $address, $recipient_name );
    264                                         break;
    265                                     case 'reply_to':
    266                                         $emailService->addReplyTo( $address, $recipient_name );
    267                                         break;
    268                                 }
    269                             } catch ( Exception $e ) {
    270                                 continue;
    271                             }
    272                         }
    273                     }
    274 
    275                     // Set Content-Type and charset.
    276 
    277                     // If we don't have a content-type from the input headers.
    278                     if ( ! isset( $content_type ) ) {
    279                         $content_type = 'text/plain';
    280                     }
    281 
    282                     /**
    283                      * Filters the wp_mail() content type.
    284                      *
    285                      * @since 2.3.0
    286                      *
    287                      * @param string $content_type Default wp_mail() content type.
    288                      */
    289                     $content_type = apply_filters( 'wp_mail_content_type', $content_type );
    290 
    291                     $emailService->ContentType = $content_type;
    292 
    293                     // Set whether it's plaintext, depending on $content_type.
    294                     if ( 'text/html' === $content_type ) {
    295                         $emailService->isHTML( true );
    296                     }
    297 
    298                     // If we don't have a charset from the input headers.
    299                     if ( ! isset( $charset ) ) {
    300                         $charset = get_bloginfo( 'charset' );
    301                     }
    302 
    303                     /**
    304                      * Filters the default wp_mail() charset.
    305                      *
    306                      * @since 2.3.0
    307                      *
    308                      * @param string $charset Default email charset.
    309                      */
    310                     $emailService->CharSet = apply_filters( 'wp_mail_charset', $charset );
    311 
    312                     if ( ! empty( $attachments ) ) {
    313                         foreach ( $attachments as $attachment ) {
    314                             try {
    315                                 $emailService->addAttachment( $attachment );
    316                             } catch ( Exception $e ) {
    317                                 continue;
    318                             }
    319                         }
    320                     }
    321 
    322                     /**
    323                      * Fires after emailService is initialized.
    324                      *
    325                      * @since 2.2.0
    326                      *
    327                      * @param emailService $emailService The emailService instance (passed by reference).
    328                      */
    329                     do_action_ref_array( 'phpmailer_init', array( &$emailService ) );
    330 
    331                     // Send!
    332                     try {
    333                         return $emailService->send();
    334                     } catch ( Exception $e ) {
    335 
    336                         $mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
    337                         $mail_error_data['phpmailer_exception_code'] = $e->getCode();
    338 
    339                         /**
    340                          * Fires after a Exception is caught.
    341                          *
    342                          * @since 4.4.0
    343                          *
    344                          * @param WP_Error $error A WP_Error object with the Exception message, and an array
    345                          *                        containing the mail recipient, subject, message, headers, and attachments.
    346                          */
    347                         do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
    348 
    349                         return false;
    350                     }
    351                 }
    352             }
     33            //add_action( 'phpmailer_init', array($this,'mailazy_phpmailer_init') );
     34            $mailazy_option = get_option('mailazy_option');
     35            if (!function_exists('wp_mail') && isset($mailazy_option['enable']) && $mailazy_option['enable'] == "1") {
     36
     37                /**
     38                 * Sends an email, similar to PHP's mail function.
     39                 *
     40                 * A true return value does not automatically mean that the user received the
     41                 * email successfully. It just only means that the method used was able to
     42                 * process the request without any errors.
     43                 *
     44                 * The default content type is `text/plain` which does not allow using HTML.
     45                 * However, you can set the content type of the email by using the
     46                 * {@see 'wp_mail_content_type'} filter.
     47                 *
     48                 * The default charset is based on the charset used on the blog. The charset can
     49                 * be set using the {@see 'wp_mail_charset'} filter.
     50                 *
     51                 * @since 1.2.1
     52                 * @since 5.5.0 is_email() is used for email validation,
     53                 *              instead of emailService's default validator.
     54                 *
     55                 * @global emailService\emailService\emailService $emailService
     56                 *
     57                 * @param string|string[] $to          Array or comma-separated list of email addresses to send message.
     58                 * @param string          $subject     Email subject.
     59                 * @param string          $message     Message contents.
     60                 * @param string|string[] $headers     Optional. Additional headers.
     61                 * @param string|string[] $attachments Optional. Paths to files to attach.
     62                 * @return bool Whether the email was sent successfully.
     63                 */
     64                function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) {
     65                    $mailazy_option = get_option('mailazy_option');
     66                    // Compact the input, apply the filters, and extract them back out.
     67                    /**
     68                     * Filters the wp_mail() arguments.
     69                     *
     70                     * @since 2.2.0
     71                     *
     72                     * @param array $args {
     73                     *     Array of the `wp_mail()` arguments.
     74                     *
     75                     *     @type string|string[] $to          Array or comma-separated list of email addresses to send message.
     76                     *     @type string          $subject     Email subject.
     77                     *     @type string          $message     Message contents.
     78                     *     @type string|string[] $headers     Additional headers.
     79                     *     @type string|string[] $attachments Paths to files to attach.
     80                     * }
     81                     */
     82                    $atts = apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments'));
     83
     84                    /**
     85                     * Filters whether to preempt sending an email.
     86                     *
     87                     * Returning a non-null value will short-circuit {@see wp_mail()}, returning
     88                     * that value instead. A boolean return value should be used to indicate whether
     89                     * the email was successfully sent.
     90                     *
     91                     * @since 5.7.0
     92                     *
     93                     * @param null|bool $return Short-circuit return value.
     94                     * @param array     $atts {
     95                     *     Array of the `wp_mail()` arguments.
     96                     *
     97                     *     @type string|string[] $to          Array or comma-separated list of email addresses to send message.
     98                     *     @type string          $subject     Email subject.
     99                     *     @type string          $message     Message contents.
     100                     *     @type string|string[] $headers     Additional headers.
     101                     *     @type string|string[] $attachments Paths to files to attach.
     102                     * }
     103                     */
     104                    $pre_wp_mail = apply_filters('pre_wp_mail', null, $atts);
     105
     106                    if (null !== $pre_wp_mail) {
     107                        return $pre_wp_mail;
     108                    }
     109
     110                    if (isset($atts['to'])) {
     111                        $to = $atts['to'];
     112                    }
     113
     114                    if (!is_array($to)) {
     115                        $to = explode(',', $to);
     116                    }
     117
     118                    if (isset($atts['subject'])) {
     119                        $subject = $atts['subject'];
     120                    }
     121
     122                    if (isset($atts['message'])) {
     123                        $message = $atts['message'];
     124                    }
     125
     126                    if (isset($atts['headers'])) {
     127                        $headers = $atts['headers'];
     128                    }
     129
     130                    if (isset($atts['attachments'])) {
     131                        $attachments = $atts['attachments'];
     132                    }
     133
     134                    if (!is_array($attachments)) {
     135                        $attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
     136                    }
     137                    global $emailService;
     138
     139                    // (Re)create it, if it's gone missing.
     140                    if (!( $emailService instanceof mailazyWPClient )) {
     141                        require_once(MAILAZY_ROOT_DIR . "mailazyWPClient.php");
     142                        $emailService = new mailazyWPClient();
     143                        $emailService->setApikey($mailazy_option['apikey']);
     144                        $emailService->setApisecret($mailazy_option['apisecretkey']);
     145                    }
     146
     147                    // Headers.
     148                    $cc = array();
     149                    $bcc = array();
     150                    $reply_to = array();
     151
     152                    if (empty($headers)) {
     153                        $headers = array();
     154                    } else {
     155                        if (!is_array($headers)) {
     156                            // Explode the headers out, so this function can take
     157                            // both string headers and an array of headers.
     158                            $tempheaders = explode("\n", str_replace("\r\n", "\n", $headers));
     159                        } else {
     160                            $tempheaders = $headers;
     161                        }
     162                        $headers = array();
     163
     164                        // If it's actually got contents.
     165                        if (!empty($tempheaders)) {
     166                            // Iterate through the raw headers.
     167                            foreach ((array) $tempheaders as $header) {
     168                                if (strpos($header, ':') === false) {
     169                                    if (false !== stripos($header, 'boundary=')) {
     170                                        $parts = preg_split('/boundary=/i', trim($header));
     171                                        $boundary = trim(str_replace(array("'", '"'), '', $parts[1]));
     172                                    }
     173                                    continue;
     174                                }
     175                                // Explode them out.
     176                                list( $name, $content ) = explode(':', trim($header), 2);
     177
     178                                // Cleanup crew.
     179                                $name = trim($name);
     180                                $content = trim($content);
     181
     182                                switch (strtolower($name)) {
     183                                    // Mainly for legacy -- process a "From:" header if it's there.
     184                                    case 'content-type':
     185                                        if (strpos($content, ';') !== false) {
     186                                            list( $type, $charset_content ) = explode(';', $content);
     187                                            $content_type = trim($type);
     188                                            if (false !== stripos($charset_content, 'charset=')) {
     189                                                $charset = trim(str_replace(array('charset=', '"'), '', $charset_content));
     190                                            } elseif (false !== stripos($charset_content, 'boundary=')) {
     191                                                $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset_content));
     192                                                $charset = '';
     193                                            }
     194
     195                                            // Avoid setting an empty $content_type.
     196                                        } elseif ('' !== trim($content)) {
     197                                            $content_type = trim($content);
     198                                        }
     199                                        break;
     200                                    case 'cc':
     201                                        $cc = array_merge((array) $cc, explode(',', $content));
     202                                        break;
     203                                    case 'bcc':
     204                                        $bcc = array_merge((array) $bcc, explode(',', $content));
     205                                        break;
     206                                    case 'reply-to':
     207                                        $reply_to = array_merge((array) $reply_to, explode(',', $content));
     208                                        break;
     209                                    default:
     210                                        // Add it to our grand headers array.
     211                                        $headers[trim($name)] = trim($content);
     212                                        break;
     213                                }
     214                            }
     215                        }
     216                    }
     217
     218                    try {
     219                        $emailService->setFrom($mailazy_option['fromemail']);
     220                    } catch (Exception $e) {
     221                        $mail_error_data = compact('to', 'subject', 'message', 'headers', 'attachments');
     222                        $mail_error_data['phpmailer_exception_code'] = $e->getCode();
     223
     224                        /** This filter is documented in wp-includes/pluggable.php */
     225                        do_action('wp_mail_failed', new WP_Error('wp_mail_failed', $e->getMessage(), $mail_error_data));
     226
     227                        return false;
     228                    }
     229
     230                    // Set mail's subject and body.
     231                    $emailService->setSubject($subject);
     232                    $emailService->setBody($message);
     233
     234                    // Set destination addresses, using appropriate methods for handling addresses.
     235                    $address_headers = compact('to', 'cc', 'bcc', 'reply_to');
     236
     237                    foreach ($address_headers as $address_header => $addresses) {
     238                        if (empty($addresses)) {
     239                            continue;
     240                        }
     241
     242                        foreach ((array) $addresses as $address) {
     243                            try {
     244                                // Break $recipient into name and address parts if in the format "Foo <[email protected]>".
     245                                $recipient_name = '';
     246
     247                                if (preg_match('/(.*)<(.+)>/', $address, $matches)) {
     248                                    if (count($matches) == 3) {
     249                                        $recipient_name = $matches[1];
     250                                        $address = $matches[2];
     251                                    }
     252                                }
     253
     254                                switch ($address_header) {
     255                                    case 'to':
     256                                        $emailService->addAddress($address, $recipient_name);
     257                                        break;
     258                                    case 'cc':
     259                                        $emailService->addCC($address, $recipient_name);
     260                                        break;
     261                                    case 'bcc':
     262                                        $emailService->addBCC($address, $recipient_name);
     263                                        break;
     264                                    case 'reply_to':
     265                                        $emailService->addReplyTo($address, $recipient_name);
     266                                        break;
     267                                }
     268                            } catch (Exception $e) {
     269                                continue;
     270                            }
     271                        }
     272                    }
     273
     274                    // Set Content-Type and charset.
     275                    // If we don't have a content-type from the input headers.
     276                    if (!isset($content_type)) {
     277                        $content_type = 'text/plain';
     278                    }
     279
     280                    /**
     281                     * Filters the wp_mail() content type.
     282                     *
     283                     * @since 2.3.0
     284                     *
     285                     * @param string $content_type Default wp_mail() content type.
     286                     */
     287                    $content_type = apply_filters('wp_mail_content_type', $content_type);
     288
     289                    $emailService->ContentType = $content_type;
     290
     291                    // Set whether it's plaintext, depending on $content_type.
     292                    if ('text/html' === $content_type) {
     293                        $emailService->isHTML(true);
     294                    }
     295
     296                    // If we don't have a charset from the input headers.
     297                    if (!isset($charset)) {
     298                        $charset = get_bloginfo('charset');
     299                    }
     300
     301                    /**
     302                     * Filters the default wp_mail() charset.
     303                     *
     304                     * @since 2.3.0
     305                     *
     306                     * @param string $charset Default email charset.
     307                     */
     308                    $emailService->CharSet = apply_filters('wp_mail_charset', $charset);
     309
     310                    if (!empty($attachments)) {
     311                        foreach ($attachments as $attachment) {
     312                            try {
     313                                $emailService->addAttachment($attachment);
     314                            } catch (Exception $e) {
     315                                continue;
     316                            }
     317                        }
     318                    }
     319
     320                    /**
     321                     * Fires after emailService is initialized.
     322                     *
     323                     * @since 2.2.0
     324                     *
     325                     * @param emailService $emailService The emailService instance (passed by reference).
     326                     */
     327                    do_action_ref_array('phpmailer_init', array(&$emailService));
     328
     329                    // Send!
     330                    try {
     331                        return $emailService->send();
     332                    } catch (Exception $e) {
     333
     334                        $mail_error_data = compact('to', 'subject', 'message', 'headers', 'attachments');
     335                        $mail_error_data['phpmailer_exception_code'] = $e->getCode();
     336
     337                        /**
     338                         * Fires after a Exception is caught.
     339                         *
     340                         * @since 4.4.0
     341                         *
     342                         * @param WP_Error $error A WP_Error object with the Exception message, and an array
     343                         *                        containing the mail recipient, subject, message, headers, and attachments.
     344                         */
     345                        do_action('wp_mail_failed', new WP_Error('wp_mail_failed', $e->getMessage(), $mail_error_data));
     346
     347                        return false;
     348                    }
     349                }
     350
     351            }
    353352        }
    354353
     
    356355         * Define constants needed across the plug-in.
    357356         */
    358         public function define_constants()
    359         {
    360             require_once(MAILAZY_ROOT_DIR."admin/index.php");
     357        public function define_constants() {
     358            require_once(MAILAZY_ROOT_DIR . "admin/index.php");
    361359        }
    362360
     
    364362         * Reset Sharing Settings.
    365363         */
    366         public static function reset_share_options()
    367         {
     364        public static function reset_share_options() {
    368365            update_option('mailazy_option', '');
    369366        }
     367
    370368        /**
    371369         * Post Data validation
    372370         */
    373         public static function data_validation($key, $post){
     371        public static function data_validation($key, $post) {
    374372            return isset($post[$key]) && !empty($post[$key]) ? sanitize_text_field(esc_html(wp_kses(trim($post[$key])))) : false;
    375373        }
     374
    376375    }
    377376
  • mailazy/trunk/mailazyWPClient.php

    r2679790 r2700416  
    11<?php
     2
    23if (!defined('ABSPATH')) {
    34    exit();
    45}
    5 require_once(MAILAZY_ROOT_DIR."sdk/mailazyAPI.php");
     6require_once(MAILAZY_ROOT_DIR . "sdk/mailazyAPI.php");
     7
    68/**
    79 * OverWrite mailazyWPClient Class with mailazyAPI
    810 */
    9 class mailazyWPClient extends mailazyAPI
    10 {   
     11class mailazyWPClient extends mailazyAPI {
     12
    1113    /**
    1214     * OverWrite Request function of mailazy API request
    1315     */
    14     public function request($endPointPath, $args = array()){
    15         $output = array();
     16    public function request($endPointPath, $args = array()) {
    1617        $request = wp_remote_request($this->getApiurl() . $endPointPath, $args);
    17         $output['response'] = wp_remote_retrieve_body($request);
    18         $output['status_code'] = $request["response"]["code"];
    19         return $output;
     18        return wp_remote_retrieve_body($request);
    2019    }
    21     public function getCustomHeaders(){
    22         return array();
    23     }
    24     public function clearCustomHeaders(){
    25         return array();
    26     }
     20
     21    public function getCustomHeaders() {
     22        return array();
     23    }
     24
     25    public function clearCustomHeaders() {
     26        return array();
     27    }
     28
    2729}
  • mailazy/trunk/readme.txt

    r2693410 r2700416  
    22Contributors: mailazy
    33Donate link: https://mailazy.com/
    4 Tags: WordPress plugin, Email API, SMTP, Send Mail, Woocommerce Mail, contact form 7
     4Tags: WordPress plugin, Email API, SMTP, Send Mail, Woocommerce Mail
    55Requires at least: 3.4
    66Tested up to: 5.9
    7 Stable tag: 1.3
     7Stable tag: 1.4
    88Requires PHP: 5.6
    99License: GPLv2 or later
     
    6565
    6666== Changelog ==
     67= 1.4 =
     68* Add test email option in admin side
    6769
    6870= 1.2 =
     
    7779== Upgrade Notice ==
    7880
    79 = 1.0 =
     81= 1.4 =
     82* Add test email option in admin side
     83
     84= 1.2 =
    8085* Bug fix Contact form 7 compatibility
    8186
Note: See TracChangeset for help on using the changeset viewer.