Plugin Directory

Changeset 2721141


Ignore:
Timestamp:
05/10/2022 10:17:21 AM (4 years ago)
Author:
mailazy
Message:

Added SMTP functionality

Location:
mailazy
Files:
18 added
8 edited

Legend:

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

    r2700416 r2721141  
    1212}
    1313.mailazy_red{
    14     color:red;
     14    color:red;
    1515}
    1616#mailazy_admin label {
     
    2020    font-weight: bold;
    2121}
    22 #mailazy_admin input[type=text],#mailazy_admin input[type=password]{
     22#mailazy_admin #mailazy_enable_type{
     23    min-width: 79%;
     24    display: inline;
     25}
     26#mailazy_admin input[type=text],#mailazy_admin input[type=password],#mailazy_admin input[type="email"]{
    2327    width: 79%;
    2428    display: inline;
  • mailazy/trunk/admin/index.php

    r2700416 r2721141  
    66}
    77
    8 if (!class_exists('mailazy_Admin')) {
     8if (!class_exists('mailazyAdmin')) {
    99
    1010    /**
    1111     * The main class and initialization point of the plugin.
    1212     */
    13     class mailazy_Admin {
     13    class mailazyAdmin {
    1414
    1515        /**
     
    1818        public function __construct() {
    1919            if (is_admin()) {
    20                 add_action('admin_init', array($this, 'register_mailazy_plugin_settings'));
    21                 add_action('admin_init', array($this, 'register_mailazy_plugin_test_mail'));
     20                add_action('admin_init', array($this, 'register_settings'));
     21                add_action('admin_init', array($this, 'register_test_mail'));
    2222            }
    23             add_action('admin_menu', array($this, 'create_mailazy_menu'));
    24             add_filter('plugin_action_links', array($this, 'mailazy_setting_links'), 10, 2);
    25             add_action('mailazy_reset_admin_action', array($this, 'reset_settings_action'), 10, 2);
     23            add_action('admin_menu', array($this, 'admin_menu'));
     24            add_filter('plugin_action_links', array($this, 'setting_links'), 10, 2);
    2625            add_action('admin_enqueue_scripts', array($this, 'add_stylesheet_to_admin'));
    2726        }
     
    3029         * Save Plugin option on option table
    3130         */
    32         public function register_mailazy_plugin_settings() {
    33             register_setting('mailazy_option', 'mailazy_option', array($this, 'mailazy_settings_validation'));
     31        public function register_settings() {
     32            register_setting('mailazy_option', 'mailazy_option', array($this, 'settings_validation'));
    3433        }
    3534
     
    3736         * test email after save setting
    3837         */
    39         public function register_mailazy_plugin_test_mail() {
    40             register_setting('mailazy_test_mail', 'mailazy_test_mail', array($this, 'mailazy_test_mail_validation'));
     38        public function register_test_mail() {
     39            register_setting('mailazy_test_mail', 'mailazy_test_mail', array($this, 'test_mail_validation'));
    4140        }
    4241
    43         public function mailazy_test_mail_validation($input) {
    44             $message = __('There was a problem.');
     42        /**
     43         * debug test email
     44         *
     45         * @global type $ts_mail_errors
     46         * @global type $phpmailer
     47         * @param type $result
     48         * @return type
     49         */
     50        function debug_wpmail($result = false) {
     51
     52            if ($result)
     53                return;
     54
     55            global $ts_mail_errors, $phpmailer;
     56
     57            if (!isset($ts_mail_errors))
     58                $ts_mail_errors = array();
     59
     60            if (isset($phpmailer))
     61                $ts_mail_errors[] = $phpmailer->ErrorInfo;
     62
     63            return $ts_mail_errors;
     64        }
     65
     66        /**
     67         * Send test email
     68         * @param type $input
     69         */
     70        public function test_mail_validation($input) {
     71            $message = __('There was a problem in configuration.');
    4572            $type = 'error';
    46             if (isset($input['test_to']) && !empty($input['test_to'])) {
     73            $mailazy_option = get_option('mailazy_option');
     74            if (isset($mailazy_option['enable_type']) && isset($input['test_to']) && !empty($input['test_to'])) {
    4775                $subject = 'Test email from ' . get_bloginfo('name') . ' via Mailazy Plugin';
    4876                $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);
     77                $mailBody .= wp_title() . ' Mailazy test email received. with Mail Send Type ' . $mailazy_option['enable_type'] . "<br/>";
     78                $res = wp_mail($input['test_to'], $subject, $mailBody);
     79                if ($mailazy_option['enable_type'] == 'api') {
     80                    $res = json_decode($res);
     81                    if (isset($res->error) && !empty($res->error)) {
     82                        $message = __("<b>" . $res->error . "</b>: " . $res->message, 'mailazy');
     83                    } else {
     84                        $message = __('Mail Sent!', 'mailazy');
     85                        $type = 'updated';
     86                    }
    5487                } else {
    55                     $message = __('Mail Sent!');
    56                     $type = 'updated';
     88                    $result = $this->debug_wpmail($res);
     89                    if (count($result) > 0) {
     90                        $message = '';
     91                        for ($i = 0; $i < count($result); $i++) {
     92                            $message .= __("<b>Error</b>: " . $result[$i], 'mailazy');
     93                        }
     94                    } else {
     95                        $message = __('Mail Sent!', 'mailazy');
     96                        $type = 'updated';
     97                    }
    5798                }
    5899            }
     
    63104         * Mailazy Validation
    64105         */
    65         public function mailazy_settings_validation($input) {
     106        public function settings_validation($input) {
    66107            $message = null;
    67108            $type = null;
     
    71112            if (null != $input) {
    72113                if (!isset($input['apikey']) || empty($input['apikey'])) {
    73                     $message = __('Mailazy Required APIkey.');
     114                    $message = __('Mailazy Required APIkey.', 'mailazy');
    74115                    $type = 'error';
    75116                } elseif (!isset($input['apisecretkey']) || empty($input['apisecretkey'])) {
    76                     $message = __('Mailazy Required API Secret Key.');
     117                    $message = __('Mailazy Required API Secret Key.', 'mailazy');
    77118                    $type = 'error';
    78119                } elseif (!isset($input['fromemail']) || empty($input['fromemail'])) {
    79                     $message = __('Mailazy Required From Email.');
     120                    $message = __('Mailazy Required From Email.', 'mailazy');
     121                    $type = 'error';
     122                } elseif (!is_email($input['fromemail'])) {
     123                    $message = __('From Email is not valid.', 'mailazy');
    80124                    $type = 'error';
    81125                } elseif (get_option('mailazy_option')) {
    82                     $message = __('Option updated!');
     126                    $message = __('Option updated!', 'mailazy');
    83127                    $type = 'updated';
    84128                } else {
    85                     $message = __('Option added!');
     129                    $message = __('Option added!', 'mailazy');
    86130                    $type = 'updated';
    87131                }
    88132            } else {
    89                 $message = __('There was a problem.');
     133                $message = __('There was a problem.', 'mailazy');
    90134                $type = 'error';
    91135            }
     
    96140
    97141        /**
    98          *
    99          * @param type $option
    100          * @param type $settings
    101          */
    102         public static function reset_settings_action($option, $settings) {
    103             if (current_user_can('manage_options')) {
    104                 update_option($option, $settings);
    105             }
    106         }
    107 
    108         /**
    109142         * Create menu.
    110143         */
    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');
     144        public function admin_menu() {
     145            add_menu_page('mailazy', 'Mailazy', 'manage_options', 'mailazy', array('mailazyAdmin', 'setting_page'), MAILAZY_ROOT_URL . 'admin/assets/images/favicon.png');
    113146            $mailazy_option = get_option('mailazy_option');
    114147            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'));
     148                add_submenu_page('mailazy', 'Mailazy', 'Test Mail', 'manage_options', 'mailazy-test-mail', array('mailazyAdmin', 'test_mail_page'));
    116149            }
    117150        }
     
    121154         * so people can go straight from the plugin page to the settings page.
    122155         */
    123         public function mailazy_setting_links($links, $file) {
     156        public function setting_links($links, $file) {
    124157            static $thisPlugin = '';
    125158            if (empty($thisPlugin)) {
     
    161194    }
    162195
    163     new mailazy_Admin();
     196    new mailazyAdmin();
    164197}
  • mailazy/trunk/admin/views/settings.php

    r2706842 r2721141  
    77<div id="mailazy_admin">
    88    <div class="mailazy_logo">
    9         <img src="<?php echo MAILAZY_ROOT_URL . 'admin/assets/images/logo.svg'?>" alt="Mailazy" title="Mailazy">
     9        <img src="<?php echo MAILAZY_ROOT_URL . 'admin/assets/images/logo.svg' ?>" alt="Mailazy" title="Mailazy">
    1010    </div>
    1111    <br/>
     
    1818            $mailazy_option = get_option('mailazy_option');
    1919            settings_fields('mailazy_option');
    20             ?>
     20            ?>
    2121            <div class="mailazy_field">
    2222                <label for="mailazy_enable">
    23                 <?php _e('Enable <span class="mailazy_red">*</span> :','mailazy');?>
     23                    <?php _e('Enable <span class="mailazy_red">*</span> :', 'mailazy'); ?>
    2424                </label>
    25                 <input type="checkbox" id="mailazy_enable" name="mailazy_option[enable]" value="1" <?php echo (isset($mailazy_option['enable']) && $mailazy_option['enable'] == "1") ? "checked='checked'" : "" ;?>>
     25                <input type="checkbox" id="mailazy_enable" name="mailazy_option[enable]" value="1" <?php echo (isset($mailazy_option['enable']) && $mailazy_option['enable'] == "1") ? "checked='checked'" : ""; ?>>
    2626            </div>
    27             <div class="mailazy_field">
     27            <div class="mailazy_field">
     28                <label for="mailazy_enable_type">
     29                    <?php _e('Send Type <span class="mailazy_red">*</span> :', 'mailazy'); ?>
     30                </label>
     31                <select id="mailazy_enable_type" name="mailazy_option[enable_type]">
     32                    <option value="api" <?php echo(isset($mailazy_option['enable_type']) && $mailazy_option['enable_type']=='api'?" selected='selected'":"");?>><?php _e('API', 'mailazy'); ?></option>
     33                    <option value="smtp" <?php echo(isset($mailazy_option['enable_type']) && $mailazy_option['enable_type']=='smtp'?" selected='selected'":"");?>><?php _e('SMTP', 'mailazy'); ?></option>
     34                </select>
     35            </div>
     36            <div class="mailazy_field">
    2837                <label for="mailazy_apikey">
    29                 <?php _e('APIkey <span class="mailazy_red">*</span> :','mailazy');?>
     38                    <?php _e('APIkey <span class="mailazy_red">*</span> :', 'mailazy'); ?>
    3039                </label>
    31                 <input type="text" id="mailazy_apikey" name="mailazy_option[apikey]" value="<?php echo isset($mailazy_option['apikey'])?esc_attr($mailazy_option['apikey']):"";?>" placeholder="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx">
    32                 <div class="mailazy_message">Go to the <a href="https://app.mailazy.com/access-keys" target="_blank">API Details</a> screen from your Website Dashboard to findyour API Key.</div>
     40                <input type="text" id="mailazy_apikey" name="mailazy_option[apikey]" value="<?php echo isset($mailazy_option['apikey']) ? esc_attr($mailazy_option['apikey']) : ""; ?>" placeholder="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx">
     41                <div class="mailazy_message">Go to the <a href="https://app.mailazy.com/access-keys" target="_blank">API Details</a> screen from your Website Dashboard to find your API Key.</div>
    3342            </div>
    34             <div class="mailazy_field">
     43            <div class="mailazy_field">
    3544                <label for="mailazy_apisecretkey">
    36                 <?php _e('API Secret key <span class="mailazy_red">*</span> :','mailazy');?>
     45                    <?php _e('API Secret key <span class="mailazy_red">*</span> :', 'mailazy'); ?>
    3746                </label>
    38                 <input type="password" id="mailazy_apisecretkey" name="mailazy_option[apisecretkey]" value="<?php echo isset($mailazy_option['apisecretkey'])?esc_attr($mailazy_option['apisecretkey']):"";?>" placeholder="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx">
    39                 <div class="mailazy_message">Go to the <a href="https://app.mailazy.com/access-keys" target="_blank">API Details</a> screen from your Website Dashboard to findyour API Secret Key.</div>
     47                <input type="password" id="mailazy_apisecretkey" name="mailazy_option[apisecretkey]" value="<?php echo isset($mailazy_option['apisecretkey']) ? esc_attr($mailazy_option['apisecretkey']) : ""; ?>" placeholder="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx">
     48                <div class="mailazy_message">Go to the <a href="https://app.mailazy.com/access-keys" target="_blank">API Details</a> screen from your Website Dashboard to find your API Secret Key.</div>
    4049            </div>
    41             <div class="mailazy_field">
     50            <div class="mailazy_field">
    4251                <label for="mailazy_fromemail">
    43                 <?php _e('From Email <span class="mailazy_red">*</span> :','mailazy');?>
     52                    <?php _e('From Email <span class="mailazy_red">*</span> :', 'mailazy'); ?>
    4453                </label>
    45                 <input type="text" id="mailazy_fromemail" name="mailazy_option[fromemail]" value="<?php echo isset($mailazy_option['fromemail'])?esc_attr($mailazy_option['fromemail']):"";?>" placeholder="From Email">
     54                <input type="email" id="mailazy_fromemail" name="mailazy_option[fromemail]" value="<?php echo isset($mailazy_option['fromemail']) ? esc_attr($mailazy_option['fromemail']) : ""; ?>" placeholder="From Email">
    4655                <div class="mailazy_message">From Email! We recommend using the same email that is configured on mailazy as sender mail. Example: info@your_domain.com</div>
    4756            </div>
     
    5463</div>
    5564<script>
    56 (function(){
    57     if(document.getElementById('mailazy_fromemail').value == ''){
    58         document.getElementById('mailazy_fromemail').value = 'info@'+window.location.hostname;
    59     }
    60 })();
     65    (function () {
     66        if (document.getElementById('mailazy_fromemail').value == '') {
     67            document.getElementById('mailazy_fromemail').value = 'username@' + window.location.hostname;
     68        }
     69    })();
    6170</script>
  • mailazy/trunk/admin/views/test_mail.php

    r2700416 r2721141  
    77<div id="mailazy_admin">
    88    <div class="mailazy_logo">
    9         <img src="<?php echo MAILAZY_ROOT_URL . 'admin/assets/images/logo.svg'?>" alt="Mailazy" title="Mailazy">
     9        <img src="<?php echo MAILAZY_ROOT_URL . 'admin/assets/images/logo.svg' ?>" alt="Mailazy" title="Mailazy">
    1010    </div>
    1111    <br/>
     
    1717            <?php
    1818            settings_fields('mailazy_test_mail');
    19             ?>
     19            ?>
    2020            <div class="mailazy_field">
    2121                <label for="mailazy_test_to">
    22                 <?php _e('To <span class="mailazy_red">*</span> :','mailazy');?>
     22                    <?php _e('To <span class="mailazy_red">*</span> :', 'mailazy'); ?>
    2323                </label>
    24                 <input type="text" id="mailazy_test_to" name="mailazy_test_mail[test_to]" placeholder="[email protected]">
     24                <input type="email" id="mailazy_test_to" name="mailazy_test_mail[test_to]" placeholder="[email protected]">
    2525            </div>
    2626            <hr />
  • mailazy/trunk/mailazy.php

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

    r2700416 r2721141  
    1919    }
    2020
     21    /**
     22     *
     23     * @return type
     24     */
    2125    public function getCustomHeaders() {
    2226        return array();
    2327    }
    2428
     29    /**
     30     *
     31     * @return type
     32     */
    2533    public function clearCustomHeaders() {
    2634        return array();
  • mailazy/trunk/readme.txt

    r2713212 r2721141  
    55Requires at least: 3.4
    66Tested up to: 5.9
    7 Stable tag: 1.6
     7Stable tag: 2.0
    88Requires PHP: 5.6
    99License: GPLv2 or later
     
    4343
    4444-   Live chat
    45 -   Email Support mailto:[email protected]
     45-   [Email Support](mailto:[email protected])
    4646-   [Support documentation](https://mailazy.com/docs/)
    4747
     
    7171
    7272== Changelog ==
     73= 2.0 =
     74* Developed SMTP functionality
     75
    7376= 1.6 =
    7477* Bug fix
     
    9194== Upgrade Notice ==
    9295
     96= 2.0 =
     97* Developed SMTP functionality
     98
    9399= 1.6 =
    94100* Bug fix
  • mailazy/trunk/sdk/mailazyAPI.php

    r2651280 r2721141  
    11<?php
    2 class mailazyAPI
    3 {
     2
     3class mailazyAPI {
     4
    45    public $apiurl;
    56    public $apikey;
    6     public $apisecret;
    7 
    8     public function __construct()
    9     {
     7    public $apisecret;
     8
     9    public function __construct() {
    1010        $apiurl = "https://api.mailazy.com/";
    1111        $this->setApiurl($apiurl);
    12         $this->isHTML(true);
    13     }
     12        $this->isHTML(true);
     13    }
     14
    1415    /**
    1516     * Get API URL
    1617     */
    17     public function getApiurl()
    18     {
     18    public function getApiurl() {
    1919        return $this->apiurl;
    2020    }
     21
    2122    /**
    2223     * Set API URL
    2324     */
    24     public function setApiurl($url)
    25     {
     25    public function setApiurl($url) {
    2626        return $this->apiurl = $url;
    2727    }
     28
    2829    /**
    2930     * Get API key
    3031     */
    31     public function getApikey()
    32     {
    33         return $this->apikey?$this->apikey:"";
    34     }
     32    public function getApikey() {
     33        return $this->apikey ? $this->apikey : "";
     34    }
     35
    3536    /**
    3637     * Set API key
    3738     */
    38     public function setApikey($apikey)
    39     {
     39    public function setApikey($apikey) {
    4040        return $this->apikey = $apikey;
    4141    }
    42    
     42
    4343    /**
    4444     * Get API secret
    4545     */
    46     public function getApisecret()
    47     {
    48         return $this->apisecret?$this->apisecret:"";
    49     }
     46    public function getApisecret() {
     47        return $this->apisecret ? $this->apisecret : "";
     48    }
     49
    5050    /**
    5151     * Set API secret
    5252     */
    53     public function setApisecret($apisecret)
    54     {
     53    public function setApisecret($apisecret) {
    5554        return $this->apisecret = $apisecret;
    5655    }
    57     /**
     56
     57    /**
    5858     * Get To Address
    5959     */
    60     public function getAddress()
    61     {
    62         return isset($this->addresses)?$this->addresses:array();
    63     }
     60    public function getAddress() {
     61        return isset($this->addresses) ? $this->addresses : array();
     62    }
     63
    6464    /**
    6565     * Set To Address
    6666     */
    67     public function addAddress($email,$name="")
    68     {
    69         $this->addresses = isset($this->addresses)?$this->addresses:array();
    70         if(empty($name)){
    71             $toAddress = array($email);
    72         }else{
    73             $toAddress = array($name.'<'.$email.'>');
    74         }
    75         return $this->addresses = array_merge($this->addresses, $toAddress);;
    76     }
    77     /**
     67    public function addAddress($email, $name = "") {
     68        $this->addresses = isset($this->addresses) ? $this->addresses : array();
     69        if (empty($name)) {
     70            $toAddress = array($email);
     71        } else {
     72            $toAddress = array($name . '<' . $email . '>');
     73        }
     74        return $this->addresses = array_merge($this->addresses, $toAddress);
     75        ;
     76    }
     77
     78    /**
    7879     * Get CC Address
    7980     */
    80     public function getCC()
    81     {
    82         return isset($this->cc)?$this->cc:array();
    83     }
     81    public function getCC() {
     82        return isset($this->cc) ? $this->cc : array();
     83    }
     84
    8485    /**
    8586     * Set CC Address
    8687     */
    87     public function addCC($email,$name="")
    88     {
    89         $this->cc = isset($this->cc)?$this->cc:array();
    90         if(empty($name)){
    91             $toAddress = array($email);
    92         }else{
    93             $toAddress = array($name.'<'.$email.'>');
    94         }
    95         return $this->cc = array_merge($this->cc, $toAddress);;
    96     }
    97     /**
     88    public function addCC($email, $name = "") {
     89        $this->cc = isset($this->cc) ? $this->cc : array();
     90        if (empty($name)) {
     91            $toAddress = array($email);
     92        } else {
     93            $toAddress = array($name . '<' . $email . '>');
     94        }
     95        return $this->cc = array_merge($this->cc, $toAddress);
     96        ;
     97    }
     98
     99    /**
    98100     * Get BCC Address
    99101     */
    100     public function getBCC()
    101     {
    102         return isset($this->bcc)?$this->bcc:array();
    103     }
     102    public function getBCC() {
     103        return isset($this->bcc) ? $this->bcc : array();
     104    }
     105
    104106    /**
    105107     * Set BCC Address
    106108     */
    107     public function addBCC($email,$name="")
    108     {
    109         $this->bcc = isset($this->bcc)?$this->bcc:array();
    110         if(empty($name)){
    111             $toAddress = array($email);
    112         }else{
    113             $toAddress = array($name.'<'.$email.'>');
    114         }
    115         return $this->bcc = array_merge($this->bcc, $toAddress);;
    116     }
    117     /**
     109    public function addBCC($email, $name = "") {
     110        $this->bcc = isset($this->bcc) ? $this->bcc : array();
     111        if (empty($name)) {
     112            $toAddress = array($email);
     113        } else {
     114            $toAddress = array($name . '<' . $email . '>');
     115        }
     116        return $this->bcc = array_merge($this->bcc, $toAddress);
     117        ;
     118    }
     119
     120    /**
    118121     * Get subject
    119122     */
    120     public function getSubject()
    121     {
    122         return isset($this->subject)?$this->subject:"";
    123     }
     123    public function getSubject() {
     124        return isset($this->subject) ? $this->subject : "";
     125    }
     126
    124127    /**
    125128     * Set subject
    126129     */
    127     public function setSubject($subject)
    128     {
     130    public function setSubject($subject) {
    129131        return $this->subject = $subject;
    130132    }
    131     /**
     133
     134    /**
    132135     * Get body
    133136     */
    134     public function getBody()
    135     {
    136         return isset($this->body)?$this->body:"";
    137     }
     137    public function getBody() {
     138        return isset($this->body) ? $this->body : "";
     139    }
     140
    138141    /**
    139142     * Set body
    140143     */
    141     public function setBody($body)
    142     {
     144    public function setBody($body) {
    143145        return $this->body = $body;
    144146    }
    145     /**
     147
     148    /**
    146149     * Get from
    147150     */
    148     public function getFrom()
    149     {
    150         return $this->from?$this->from:"";
    151     }
     151    public function getFrom() {
     152        return $this->from ? $this->from : "";
     153    }
     154
    152155    /**
    153156     * Set from
    154157     */
    155     public function setFrom($from,$name="")
    156     {
    157         if(empty($name)){
    158             $fromAddress = $from;
    159         }else{
    160             $fromAddress = $name.'<'.$from.'>';
    161         }
     158    public function setFrom($from, $name = "") {
     159        if (empty($name)) {
     160            $fromAddress = $from;
     161        } else {
     162            $fromAddress = $name . '<' . $from . '>';
     163        }
    162164        return $this->from = $fromAddress;
    163165    }
    164     /**
     166
     167    /**
    165168     * Get replyTo
    166169     */
    167     public function getReplyTo()
    168     {
    169         return isset($this->replyTo)?$this->replyTo:"";
    170     }
     170    public function getReplyTo() {
     171        return isset($this->replyTo) ? $this->replyTo : "";
     172    }
     173
    171174    /**
    172175     * Set replyTo
    173176     */
    174     public function addReplyTo($replyTo,$name="")
    175     {
    176         if(empty($name)){
    177             $replyToAddress = $replyTo;
    178         }else{
    179             $replyToAddress = $name.'<'.$replyTo.'>';
    180         }
     177    public function addReplyTo($replyTo, $name = "") {
     178        if (empty($name)) {
     179            $replyToAddress = $replyTo;
     180        } else {
     181            $replyToAddress = $name . '<' . $replyTo . '>';
     182        }
    181183        return $this->replyTo = $replyToAddress;
    182184    }
    183     /**
     185
     186    /**
    184187     * Get from
    185188     */
    186     public function getIsHTML()
    187     {
     189    public function getIsHTML() {
    188190        return $this->ishtml;
    189191    }
     192
    190193    /**
    191194     * Set from
    192195     */
    193     public function isHTML($ishtml)
    194     {
    195         return $this->ishtml = !$ishtml?false:true;
    196     }
     196    public function isHTML($ishtml) {
     197        return $this->ishtml = !$ishtml ? false : true;
     198    }
     199
    197200    /**
    198201     * Get Attachment
    199202     */
    200     public function getAttachment()
    201     {
    202         return isset($this->attachments)?$this->attachments:array();
    203     }
     203    public function getAttachment() {
     204        return isset($this->attachments) ? $this->attachments : array();
     205    }
     206
    204207    /**
    205208     * add Attachment
    206209     */
    207     public function addAttachment($file, $name = '',  $encoding = 'base64', $type = 'application/pdf')
    208     {
    209         $this->attachments = isset($this->attachments)?$this->attachments:array();
     210    public function addAttachment($file, $name = '', $encoding = 'base64', $type = 'application/pdf') {
     211        $this->attachments = isset($this->attachments) ? $this->attachments : array();
    210212        $fileName = basename($file);
    211         $name = (!empty($name)?$name:$fileName);
    212         $ContentType = mime_content_type($file)?mime_content_type($file):$type;
     213        $name = (!empty($name) ? $name : $fileName);
     214        $ContentType = mime_content_type($file) ? mime_content_type($file) : $type;
    213215        $data = file_get_contents($file);
    214         $attachment = array(array("type"=> $ContentType,
    215             "file_name"=> $name,
    216             "content"=> base64_encode($data)));
     216        $attachment = array(array("type" => $ContentType,
     217                "file_name" => $name,
     218                "content" => base64_encode($data)));
    217219        return $this->attachments = array_merge($this->attachments, $attachment);
    218220    }
     221
    219222    /**
    220223     * Send Link on Email
    221224     */
    222     public function send()
    223     {
    224         $payload = array(
    225             "to"=>$this->getAddress(),
    226             "from"=>$this->getFrom(),
    227             "subject"=>$this->getSubject(),
    228             "content"=>array(
    229                 array(
    230                 "type"=> "text/plain",
    231                 "value"=> strip_tags($this->getBody())
    232                 )
     225    public function send() {
     226        $payload = array(
     227            "to" => $this->getAddress(),
     228            "from" => $this->getFrom(),
     229            "subject" => $this->getSubject(),
     230            "content" => array(
     231                array(
     232                    "type" => "text/plain",
     233                    "value" => strip_tags($this->getBody())
     234                )
    233235            )
    234         );
    235         if($this->getIsHTML()){
    236             $payload['content'][] = array(
    237                 "type"=> "text/html",
    238                 "value"=> $this->getBody()
    239             );
    240         }
    241         if(!empty($this->getBCC())){
    242             $payload['bcc']=$this->getBCC();
    243         }
    244         if(!empty($this->getCC())){
    245             $payload['cc']=$this->getCC();
    246         }
    247         if(!empty($this->getReplyTo())){
    248             $payload['reply_to']=$this->getReplyTo();
    249         }
    250         if(!empty($this->getAttachment())){
    251             $payload['attachments']=$this->getAttachment();
    252         }
     236        );
     237        if ($this->getIsHTML()) {
     238            $payload['content'][] = array(
     239                "type" => "text/html",
     240                "value" => $this->getBody()
     241            );
     242        }
     243        if (!empty($this->getBCC())) {
     244            $payload['bcc'] = $this->getBCC();
     245        }
     246        if (!empty($this->getCC())) {
     247            $payload['cc'] = $this->getCC();
     248        }
     249        if (!empty($this->getReplyTo())) {
     250            $payload['reply_to'] = $this->getReplyTo();
     251        }
     252        if (!empty($this->getAttachment())) {
     253            $payload['attachments'] = $this->getAttachment();
     254        }
    253255        return $this->request("v1/mail/send", array(
    254             "method"     => "POST",
    255             "headers"=>array("X-Api-Key"=>$this->getApikey(),
    256             "X-Api-Secret"=>$this->getApisecret(),
    257             'Content-Type' => 'application/json'),
    258             "body"=>json_encode($payload)
    259       ));
    260     }
     256                    "method" => "POST",
     257                    "headers" => array("X-Api-Key" => $this->getApikey(),
     258                        "X-Api-Secret" => $this->getApisecret(),
     259                        'Content-Type' => 'application/json'),
     260                    "body" => json_encode($payload)
     261        ));
     262    }
     263
    261264}
Note: See TracChangeset for help on using the changeset viewer.