Changeset 2721141
- Timestamp:
- 05/10/2022 10:17:21 AM (4 years ago)
- Location:
- mailazy
- Files:
-
- 18 added
- 8 edited
-
tags/2.0 (added)
-
tags/2.0/admin (added)
-
tags/2.0/admin/assets (added)
-
tags/2.0/admin/assets/css (added)
-
tags/2.0/admin/assets/css/style.css (added)
-
tags/2.0/admin/assets/images (added)
-
tags/2.0/admin/assets/images/favicon.ico (added)
-
tags/2.0/admin/assets/images/favicon.png (added)
-
tags/2.0/admin/assets/images/logo.svg (added)
-
tags/2.0/admin/index.php (added)
-
tags/2.0/admin/views (added)
-
tags/2.0/admin/views/settings.php (added)
-
tags/2.0/admin/views/test_mail.php (added)
-
tags/2.0/mailazy.php (added)
-
tags/2.0/mailazyWPClient.php (added)
-
tags/2.0/readme.txt (added)
-
tags/2.0/sdk (added)
-
tags/2.0/sdk/mailazyAPI.php (added)
-
trunk/admin/assets/css/style.css (modified) (2 diffs)
-
trunk/admin/index.php (modified) (9 diffs)
-
trunk/admin/views/settings.php (modified) (3 diffs)
-
trunk/admin/views/test_mail.php (modified) (2 diffs)
-
trunk/mailazy.php (modified) (5 diffs)
-
trunk/mailazyWPClient.php (modified) (1 diff)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/sdk/mailazyAPI.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
mailazy/trunk/admin/assets/css/style.css
r2700416 r2721141 12 12 } 13 13 .mailazy_red{ 14 color:red;14 color:red; 15 15 } 16 16 #mailazy_admin label { … … 20 20 font-weight: bold; 21 21 } 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"]{ 23 27 width: 79%; 24 28 display: inline; -
mailazy/trunk/admin/index.php
r2700416 r2721141 6 6 } 7 7 8 if (!class_exists('mailazy _Admin')) {8 if (!class_exists('mailazyAdmin')) { 9 9 10 10 /** 11 11 * The main class and initialization point of the plugin. 12 12 */ 13 class mailazy _Admin {13 class mailazyAdmin { 14 14 15 15 /** … … 18 18 public function __construct() { 19 19 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')); 22 22 } 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); 26 25 add_action('admin_enqueue_scripts', array($this, 'add_stylesheet_to_admin')); 27 26 } … … 30 29 * Save Plugin option on option table 31 30 */ 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')); 34 33 } 35 34 … … 37 36 * test email after save setting 38 37 */ 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')); 41 40 } 42 41 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.'); 45 72 $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'])) { 47 75 $subject = 'Test email from ' . get_bloginfo('name') . ' via Mailazy Plugin'; 48 76 $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 } 54 87 } 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 } 57 98 } 58 99 } … … 63 104 * Mailazy Validation 64 105 */ 65 public function mailazy_settings_validation($input) {106 public function settings_validation($input) { 66 107 $message = null; 67 108 $type = null; … … 71 112 if (null != $input) { 72 113 if (!isset($input['apikey']) || empty($input['apikey'])) { 73 $message = __('Mailazy Required APIkey.' );114 $message = __('Mailazy Required APIkey.', 'mailazy'); 74 115 $type = 'error'; 75 116 } elseif (!isset($input['apisecretkey']) || empty($input['apisecretkey'])) { 76 $message = __('Mailazy Required API Secret Key.' );117 $message = __('Mailazy Required API Secret Key.', 'mailazy'); 77 118 $type = 'error'; 78 119 } 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'); 80 124 $type = 'error'; 81 125 } elseif (get_option('mailazy_option')) { 82 $message = __('Option updated!' );126 $message = __('Option updated!', 'mailazy'); 83 127 $type = 'updated'; 84 128 } else { 85 $message = __('Option added!' );129 $message = __('Option added!', 'mailazy'); 86 130 $type = 'updated'; 87 131 } 88 132 } else { 89 $message = __('There was a problem.' );133 $message = __('There was a problem.', 'mailazy'); 90 134 $type = 'error'; 91 135 } … … 96 140 97 141 /** 98 *99 * @param type $option100 * @param type $settings101 */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 /**109 142 * Create menu. 110 143 */ 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'); 113 146 $mailazy_option = get_option('mailazy_option'); 114 147 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')); 116 149 } 117 150 } … … 121 154 * so people can go straight from the plugin page to the settings page. 122 155 */ 123 public function mailazy_setting_links($links, $file) {156 public function setting_links($links, $file) { 124 157 static $thisPlugin = ''; 125 158 if (empty($thisPlugin)) { … … 161 194 } 162 195 163 new mailazy _Admin();196 new mailazyAdmin(); 164 197 } -
mailazy/trunk/admin/views/settings.php
r2706842 r2721141 7 7 <div id="mailazy_admin"> 8 8 <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"> 10 10 </div> 11 11 <br/> … … 18 18 $mailazy_option = get_option('mailazy_option'); 19 19 settings_fields('mailazy_option'); 20 ?>20 ?> 21 21 <div class="mailazy_field"> 22 22 <label for="mailazy_enable"> 23 <?php _e('Enable <span class="mailazy_red">*</span> :','mailazy');?>23 <?php _e('Enable <span class="mailazy_red">*</span> :', 'mailazy'); ?> 24 24 </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'" : ""; ?>> 26 26 </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"> 28 37 <label for="mailazy_apikey"> 29 <?php _e('APIkey <span class="mailazy_red">*</span> :','mailazy');?>38 <?php _e('APIkey <span class="mailazy_red">*</span> :', 'mailazy'); ?> 30 39 </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 find your 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> 33 42 </div> 34 <div class="mailazy_field">43 <div class="mailazy_field"> 35 44 <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'); ?> 37 46 </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 find your 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> 40 49 </div> 41 <div class="mailazy_field">50 <div class="mailazy_field"> 42 51 <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'); ?> 44 53 </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"> 46 55 <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> 47 56 </div> … … 54 63 </div> 55 64 <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 })(); 61 70 </script> -
mailazy/trunk/admin/views/test_mail.php
r2700416 r2721141 7 7 <div id="mailazy_admin"> 8 8 <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"> 10 10 </div> 11 11 <br/> … … 17 17 <?php 18 18 settings_fields('mailazy_test_mail'); 19 ?>19 ?> 20 20 <div class="mailazy_field"> 21 21 <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'); ?> 23 23 </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]"> 25 25 </div> 26 26 <hr /> -
mailazy/trunk/mailazy.php
r2713212 r2721141 3 3 /** 4 4 * Plugin Name: Mailazy 5 * Plugin URI: https:// github.com/mailazy/wordpress5 * Plugin URI: https://mailazy.com/ 6 6 * Description: Mailazy provides a secure and delightful experience to your customer with Email API. 7 * Version: 1.67 * Version: 2.0 8 8 * Author: Mailazy Team 9 9 * Author URI: https://mailazy.com … … 11 11 */ 12 12 if (!defined('ABSPATH')) { 13 exit();13 exit(); 14 14 } 15 15 // If this file is called directly, abort. 16 16 define('MAILAZY_ROOT_DIR', plugin_dir_path(__FILE__)); 17 17 define('MAILAZY_ROOT_URL', plugin_dir_url(__FILE__)); 18 define('MAILAZY_PLUGIN_VERSION', ' 1.6');18 define('MAILAZY_PLUGIN_VERSION', '2.0'); 19 19 define('MAILAZY_ROOT_SETTING_LINK', plugin_basename(__FILE__)); 20 20 21 if (!class_exists('mailazy Plugin')) {21 if (!class_exists('mailazy')) { 22 22 23 23 /** 24 24 * The main class and initialization point of the plugin. 25 25 */ 26 class mailazy Plugin{26 class mailazy { 27 27 28 28 /** … … 32 32 $this->define_constants(); 33 33 $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 66 55 /** 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. 80 81 */ 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(); 158 172 } 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; 171 192 } 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) { 172 287 continue; 173 288 } 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; 212 334 } 213 335 } 214 336 } 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 } 215 367 } 216 368 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.0283 *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.0304 *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.0323 *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.0340 *341 * @param WP_Error $error A WP_Error object with the Exception message, and an array342 * 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 }348 369 } 349 350 370 } 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); 351 393 } 352 394 … … 359 401 360 402 /** 361 * Reset Sharing Settings.362 */363 public static function reset_share_options() {364 update_option('mailazy_option', '');365 }366 367 /**368 403 * Post Data validation 369 404 */ … … 374 409 } 375 410 376 new mailazy Plugin();411 new mailazy(); 377 412 } -
mailazy/trunk/mailazyWPClient.php
r2700416 r2721141 19 19 } 20 20 21 /** 22 * 23 * @return type 24 */ 21 25 public function getCustomHeaders() { 22 26 return array(); 23 27 } 24 28 29 /** 30 * 31 * @return type 32 */ 25 33 public function clearCustomHeaders() { 26 34 return array(); -
mailazy/trunk/readme.txt
r2713212 r2721141 5 5 Requires at least: 3.4 6 6 Tested up to: 5.9 7 Stable tag: 1.67 Stable tag: 2.0 8 8 Requires PHP: 5.6 9 9 License: GPLv2 or later … … 43 43 44 44 - Live chat 45 - Email Support mailto:[email protected]45 - [Email Support](mailto:[email protected]) 46 46 - [Support documentation](https://mailazy.com/docs/) 47 47 … … 71 71 72 72 == Changelog == 73 = 2.0 = 74 * Developed SMTP functionality 75 73 76 = 1.6 = 74 77 * Bug fix … … 91 94 == Upgrade Notice == 92 95 96 = 2.0 = 97 * Developed SMTP functionality 98 93 99 = 1.6 = 94 100 * Bug fix -
mailazy/trunk/sdk/mailazyAPI.php
r2651280 r2721141 1 1 <?php 2 class mailazyAPI 3 { 2 3 class mailazyAPI { 4 4 5 public $apiurl; 5 6 public $apikey; 6 public $apisecret; 7 8 public function __construct() 9 { 7 public $apisecret; 8 9 public function __construct() { 10 10 $apiurl = "https://api.mailazy.com/"; 11 11 $this->setApiurl($apiurl); 12 $this->isHTML(true); 13 } 12 $this->isHTML(true); 13 } 14 14 15 /** 15 16 * Get API URL 16 17 */ 17 public function getApiurl() 18 { 18 public function getApiurl() { 19 19 return $this->apiurl; 20 20 } 21 21 22 /** 22 23 * Set API URL 23 24 */ 24 public function setApiurl($url) 25 { 25 public function setApiurl($url) { 26 26 return $this->apiurl = $url; 27 27 } 28 28 29 /** 29 30 * Get API key 30 31 */ 31 public function getApikey() 32 {33 return $this->apikey?$this->apikey:"";34 } 32 public function getApikey() { 33 return $this->apikey ? $this->apikey : ""; 34 } 35 35 36 /** 36 37 * Set API key 37 38 */ 38 public function setApikey($apikey) 39 { 39 public function setApikey($apikey) { 40 40 return $this->apikey = $apikey; 41 41 } 42 42 43 43 /** 44 44 * Get API secret 45 45 */ 46 public function getApisecret() 47 {48 return $this->apisecret?$this->apisecret:"";49 } 46 public function getApisecret() { 47 return $this->apisecret ? $this->apisecret : ""; 48 } 49 50 50 /** 51 51 * Set API secret 52 52 */ 53 public function setApisecret($apisecret) 54 { 53 public function setApisecret($apisecret) { 55 54 return $this->apisecret = $apisecret; 56 55 } 57 /** 56 57 /** 58 58 * Get To Address 59 59 */ 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 64 64 /** 65 65 * Set To Address 66 66 */ 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 /** 78 79 * Get CC Address 79 80 */ 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 84 85 /** 85 86 * Set CC Address 86 87 */ 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 /** 98 100 * Get BCC Address 99 101 */ 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 104 106 /** 105 107 * Set BCC Address 106 108 */ 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 /** 118 121 * Get subject 119 122 */ 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 124 127 /** 125 128 * Set subject 126 129 */ 127 public function setSubject($subject) 128 { 130 public function setSubject($subject) { 129 131 return $this->subject = $subject; 130 132 } 131 /** 133 134 /** 132 135 * Get body 133 136 */ 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 138 141 /** 139 142 * Set body 140 143 */ 141 public function setBody($body) 142 { 144 public function setBody($body) { 143 145 return $this->body = $body; 144 146 } 145 /** 147 148 /** 146 149 * Get from 147 150 */ 148 public function getFrom() 149 {150 return $this->from?$this->from:"";151 } 151 public function getFrom() { 152 return $this->from ? $this->from : ""; 153 } 154 152 155 /** 153 156 * Set from 154 157 */ 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 } 162 164 return $this->from = $fromAddress; 163 165 } 164 /** 166 167 /** 165 168 * Get replyTo 166 169 */ 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 171 174 /** 172 175 * Set replyTo 173 176 */ 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 } 181 183 return $this->replyTo = $replyToAddress; 182 184 } 183 /** 185 186 /** 184 187 * Get from 185 188 */ 186 public function getIsHTML() 187 { 189 public function getIsHTML() { 188 190 return $this->ishtml; 189 191 } 192 190 193 /** 191 194 * Set from 192 195 */ 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 197 200 /** 198 201 * Get Attachment 199 202 */ 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 204 207 /** 205 208 * add Attachment 206 209 */ 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(); 210 212 $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; 213 215 $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))); 217 219 return $this->attachments = array_merge($this->attachments, $attachment); 218 220 } 221 219 222 /** 220 223 * Send Link on Email 221 224 */ 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 ) 233 235 ) 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 } 253 255 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 261 264 }
Note: See TracChangeset
for help on using the changeset viewer.