| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: ZeptoMail |
| 4 |
Version: 2.2.2 |
| 5 |
Plugin URI: https://zeptomail.zoho.com/ |
| 6 |
Author: Zoho Mail |
| 7 |
Author URI: https://www.zoho.com/zeptomail/ |
| 8 |
Description: Configure your ZeptoMail account to send email from your WordPress site. |
| 9 |
Text Domain: ZeptoMail |
| 10 |
Domain Path: /languages |
| 11 |
*/ |
| 12 |
/* |
| 13 |
Copyright (c) 2015, ZOHO CORPORATION |
| 14 |
All rights reserved. |
| 15 |
|
| 16 |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
| 17 |
|
| 18 |
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
| 19 |
|
| 20 |
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
| 21 |
|
| 22 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 |
*/ |
| 24 |
|
| 25 |
|
| 26 |
function ztm_zmplugin_script() { |
| 27 |
wp_enqueue_style( 'zm_zohoTransMail_style', plugin_dir_url( __FILE__ ) . 'assets/css/style.css', false, '1.0.0' ); |
| 28 |
} |
| 29 |
|
| 30 |
add_action( 'admin_enqueue_scripts', 'ztm_zmplugin_script'); |
| 31 |
|
| 32 |
function zohoTransMail_deactivate() { |
| 33 |
//--------------Clear the credentials once deactivated------------------- |
| 34 |
delete_option('transmail_send_mail_token'); |
| 35 |
delete_option('transmail_bounce_email_address'); |
| 36 |
delete_option('transmail_from_email_id'); |
| 37 |
delete_option('transmail_from_name'); |
| 38 |
delete_option('transmail_content_type'); |
| 39 |
delete_option('transmail_domain_name'); |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
register_deactivation_hook( __FILE__, 'zohoTransMail_deactivate'); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
function transmail_integ_settings() { |
| 48 |
add_menu_page ( |
| 49 |
'Welcome to ZeptoMail by Zoho Mail', |
| 50 |
'ZeptoMail', |
| 51 |
'manage_options', |
| 52 |
'transmail-settings', |
| 53 |
'transmail_settings_callback' , |
| 54 |
'dashicons-email' |
| 55 |
); |
| 56 |
add_submenu_page ( |
| 57 |
'transmail-settings', |
| 58 |
'ZeptoMail by Zoho Mail', |
| 59 |
'Configure Account', |
| 60 |
'manage_options', |
| 61 |
'transmail-settings', |
| 62 |
'transmail_settings_callback' |
| 63 |
); |
| 64 |
add_submenu_page ( |
| 65 |
'transmail-settings', |
| 66 |
'Send Mail - ZeptoMail by Zoho Mail', |
| 67 |
'Test Mail', |
| 68 |
'manage_options', |
| 69 |
'transmail-send-mail', |
| 70 |
'transmail_send_mail_callback' |
| 71 |
); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
function transmail_settings_callback() { |
| 78 |
|
| 79 |
if (isset($_POST['transmail_submit']) && !empty($_POST)) { |
| 80 |
$nonce = sanitize_text_field($_REQUEST['_wpnonce']); |
| 81 |
if (!wp_verify_nonce($nonce, 'transmail_settings_nonce')) { |
| 82 |
echo '<div class="error"><p><strong>'.esc_html__('Reload the page again').'</strong></p></div>'."\n"; |
| 83 |
} else { |
| 84 |
$need_to_test = 0; |
| 85 |
$transmail_send_mail_token = sanitize_text_field($_POST['transmail_send_mail_token']); |
| 86 |
$transmail_from_email_id = sanitize_email($_POST['transmail_from_email_id']); |
| 87 |
$transmail_domain_name = sanitize_text_field($_POST['transmail_domain_name']); |
| 88 |
$transmail_from_name = sanitize_text_field($_POST['transmail_from_name']); |
| 89 |
$transmail_content_type = sanitize_text_field($_POST['transmail_content_type']); |
| 90 |
if(strcmp($transmail_from_email_id, get_option('transmail_from_email_id')) != 0 |
| 91 |
|| strcmp($transmail_send_mail_token, base64_decode(get_option('transmail_send_mail_token'))) != 0) { |
| 92 |
|
| 93 |
$need_to_test = 1; |
| 94 |
|
| 95 |
} |
| 96 |
if(get_option('transmail_send_mail_token') == null || strcmp(get_option("last_test_result"), "failed") == 0) { |
| 97 |
$need_to_test = 1; |
| 98 |
} |
| 99 |
update_option('transmail_send_mail_token',base64_encode($transmail_send_mail_token), false); |
| 100 |
update_option('transmail_from_email_id',$transmail_from_email_id, false); |
| 101 |
update_option('transmail_from_name',stripslashes($transmail_from_name), false); |
| 102 |
update_option('transmail_content_type',$transmail_content_type, false); |
| 103 |
update_option('transmail_domain_name',$transmail_domain_name, false); |
| 104 |
if ( $need_to_test == 1) { |
| 105 |
$headers = array('Content-Type: text/html; charset=UTF-8'); |
| 106 |
wp_mail($transmail_from_email_id, "ZeptoMail plugin for WordPress - Test Email", "<html><body><p>Hello,</p><br><br><p>We're glad you're using our ZeptoMail plugin. This is a test email to verify your configuration details. |
| 107 |
Thank you for choosing ZeptoMail for your transactional email needs.<p><br><br>Team ZeptoMail", $headers, null); |
| 108 |
$data = json_decode(get_option('transmail_test_mail_case')); |
| 109 |
if (!empty($data->data)) { |
| 110 |
echo '<div class="updated"><p><strong>'.esc_html__('Plugin has been configured successfully!').'</strong></p></div>'."\n"; |
| 111 |
update_option("last_test_result","sucess",false); |
| 112 |
} else { |
| 113 |
|
| 114 |
$message= ''.$data->error->details[0]->message; |
| 115 |
if(!empty($data->error)) { |
| 116 |
if(!empty($data->error->details[0]->message) && strcmp($data->error->details[0]->message,"Invalid API Token found") == 0 ) { |
| 117 |
$message = "Configuration failed. Enter a valid Send Mail token and try again."; |
| 118 |
} |
| 119 |
if(!empty($data->error->details[0]->target) && strcmp($data->error->details[0]->target,"from") == 0 ) { |
| 120 |
$message = "Configuration failed. Enter a valid From address and try again."; |
| 121 |
} |
| 122 |
update_option("last_test_result","failed",false); |
| 123 |
} |
| 124 |
else{ |
| 125 |
$message= 'Configuration failed. Verify details and try again. For further assistance, contact <a href="mailto:support@zeptomail.com">support.</a>'; |
| 126 |
} |
| 127 |
echo '<div class="error"><p><strong>'.($message).'</strong></p></div>'."\n"; |
| 128 |
} |
| 129 |
} else { |
| 130 |
echo '<div class="updated"><p><strong>'.esc_html__('Configuration saved successfully.').'</strong></p></div>'."\n"; |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
?> |
| 135 |
<head> |
| 136 |
<meta charset="UTF-8"> |
| 137 |
<title>ZeptoMail by Zoho Mail</title> |
| 138 |
</head> |
| 139 |
<body> |
| 140 |
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>"> |
| 141 |
<?php wp_nonce_field('transmail_settings_nonce'); ?> |
| 142 |
<div class="page"><div class="page__content"> |
| 143 |
<div class="page__header"> |
| 144 |
<h1>Welcome to ZeptoMail by <img src=<?php echo esc_url(plugins_url('assets/images/zoho.png',__FILE__))?> title="Zoho" alt="Zoho" width="115" /> Mail.</h1> |
| 145 |
<p>Visit <a class="zm_a" href=<?php echo esc_url("https://zeptomail.zoho.com/#dashboard/setupDetail")?> target="_blank">here</a> to generate your Send Mail token.</p> |
| 146 |
</div> |
| 147 |
<div class="form"> |
| 148 |
<div class="form__row"> |
| 149 |
<label class="form--label">Where is your account hosted?</label> |
| 150 |
<select class="form--input form--input--select" name="transmail_domain_name"> |
| 151 |
<option value="com" <?php if(get_option('transmail_domain_name') == "com") {?> selected="true"<?php } ?>>zeptomail.zoho.com</option> |
| 152 |
<option value="eu" <?php if(get_option('transmail_domain_name') == "eu") {?> selected="true"<?php } ?>>zeptomail.zoho.eu</option> |
| 153 |
<option value="in" <?php if(get_option('transmail_domain_name') == "in") {?> selected="true"<?php }?>>zeptomail.zoho.in</option> |
| 154 |
<option value="com.cn" <?php if(get_option('transmail_domain_name') == "com.cn") {?>selected="true"<?php }?>>zeptomail.zoho.com.cn</option> |
| 155 |
<option value="com.au" <?php if(get_option('transmail_domain_name') == "com.au"){?>selected="true"<?php }?>>zeptomail.zoho.com.au</option> |
| 156 |
</select> <br><i class="form__row-info">The region where your ZeptoMail account is hosted. This is the URL displayed on login to your account.</i> </div> |
| 157 |
<div class="form__row"> |
| 158 |
<label class="form--label">Send Mail Token</label> |
| 159 |
<input type="password" value="<?php echo base64_decode(get_option('transmail_send_mail_token')); ?>" name="transmail_send_mail_token" class="form--input" id="transmail_send_mail_token" required/> |
| 160 |
<i class="form__row-info">Send Mail token of the relevant Mail Agent generated in your ZeptoMail account.</i> |
| 161 |
</div> |
| 162 |
<div class="form__row"> |
| 163 |
<label class="form--label">From Email Address</label> |
| 164 |
<input type="text" name="transmail_from_email_id" value="<?php echo get_option('transmail_from_email_id') ?>" class="form--input" id="transmail_from_email_id" required/> <i class="form__row-info">The email address that will be used as the From address to send emails |
| 165 |
.</i> </div> |
| 166 |
<div class="form__row"> |
| 167 |
<label class="form--label">From Name</label> |
| 168 |
<input type="text" name="transmail_from_name" value="<?php echo get_option('transmail_from_name') ?>" class="form--input" id="transmail_from_name" required/> <i class="form__row-info">The sender name displayed on the emails sent from the plugin.</i> </div> |
| 169 |
<div class="form__row"> |
| 170 |
<label class="form--label">Mail Format</label> |
| 171 |
<select class="form--input form--input--select" name="transmail_content_type"> |
| 172 |
<option value="plaintext" <?php if(get_option('transmail_content_type') == "plaintext") {?> selected="true"<?php } ?>>Plaintext</option> |
| 173 |
<option value="html" <?php if(get_option('transmail_content_type') == "html") {?> selected="true"<?php } ?>>HTML</option> |
| 174 |
</select> <br><i class="form__row-info">The preferred email format for the body of your email.</i> </div> |
| 175 |
<div class="form__row form__row-btn"> |
| 176 |
<input type="submit" name="transmail_submit" id="transmail_submit" class="btn" value="Save"/> |
| 177 |
</div> |
| 178 |
</div> |
| 179 |
</div> |
| 180 |
</div> |
| 181 |
</form> |
| 182 |
</body> |
| 183 |
<?php |
| 184 |
|
| 185 |
|
| 186 |
} |
| 187 |
add_action('admin_menu','transmail_integ_settings'); |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
function transmail_send_mail_callback() { |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
$option = get_option('transmail_send_mail_token'); |
| 199 |
if(!empty($option)){ |
| 200 |
|
| 201 |
if(is_admin() || current_user_can('administrator')) { |
| 202 |
if(isset($_POST['transmail_send_mail_submit']) && !empty($_POST)){ |
| 203 |
$nonce = sanitize_text_field($_REQUEST['_wpnonce']); |
| 204 |
if (!wp_verify_nonce($nonce, 'transmail_send_mail_nonce')) { |
| 205 |
echo '<div class="error"><p><strong>'.esc_html__('Reload the page again').'</strong></p></div>'."\n"; |
| 206 |
} else { |
| 207 |
if(empty($option)){ |
| 208 |
echo '<div class="error"><p><strong>'.esc_html__('Account not Configured').'</strong></p></div>'."\n"; |
| 209 |
} |
| 210 |
$toAddressTest = sanitize_email($_POST['transmail_to_address']); |
| 211 |
$subjectTest = sanitize_text_field($_POST['transmail_subject']); |
| 212 |
$contentTest = sanitize_text_field($_POST['transmail_content']); |
| 213 |
if(wp_mail($toAddressTest,$subjectTest,$contentTest,null, null)) { |
| 214 |
echo '<div class="updated"><p><strong>'.esc_html__('Mail Sent Successfully').'</strong></p></div>'."\n"; |
| 215 |
} else { |
| 216 |
echo '<div class="error"><p><strong>'.esc_html__('Mail Sending Failed').'</strong></p></div>'."\n"; |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
} |
| 221 |
?> |
| 222 |
<head> |
| 223 |
<meta charset="UTF-8"> |
| 224 |
<title>Zoho Mail</title> |
| 225 |
</head> |
| 226 |
|
| 227 |
<form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["REQUEST_URI"]; ?>"> |
| 228 |
<?php wp_nonce_field('transmail_send_mail_nonce'); ?> |
| 229 |
<body> |
| 230 |
<div class="page"><div class="page__content"> |
| 231 |
<div class="page__header"> |
| 232 |
<h1>Send Mail <span class="ico-send"></span></h1> |
| 233 |
</div> |
| 234 |
<div class="form"> |
| 235 |
<div class="form__row"> |
| 236 |
<label class="form--label">To</label> |
| 237 |
<input type="text" class="form--input" name="transmail_to_address" required = "required"/> </div> |
| 238 |
<div class="form__row"> |
| 239 |
<label class="form--label">Subject</label> |
| 240 |
<input type="text" class="form--input" name="transmail_subject" required = "required"/> </div> |
| 241 |
<div class="form__row"> |
| 242 |
<label class="form--label">Content</label> |
| 243 |
<input type="text" class="form--input" name="transmail_content"/> </div> |
| 244 |
<div class="form__row form__row-btn"> <input type="submit" class = "btn" name="transmail_send_mail_submit" id="transmail_send_mail_submit" value="<?php _e('Send Mail');?>"> |
| 245 |
|
| 246 |
</div> |
| 247 |
</div> |
| 248 |
</div> |
| 249 |
</div> |
| 250 |
</body> |
| 251 |
</form> |
| 252 |
<?php |
| 253 |
|
| 254 |
} |
| 255 |
else { |
| 256 |
echo '<div class="error"><p><strong>'.__('Configure Your Account.').'</strong></p></div>'."\n"; |
| 257 |
} |
| 258 |
|
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
if(!function_exists('wp_mail')) { |
| 263 |
function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { |
| 264 |
|
| 265 |
$atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ); |
| 266 |
|
| 267 |
if ( isset( $atts['to'] ) ) { |
| 268 |
$to = $atts['to']; |
| 269 |
} |
| 270 |
if ( !is_array( $to ) ) { |
| 271 |
$to = explode( ',', $to ); |
| 272 |
} |
| 273 |
if ( isset( $atts['subject'] ) ) { |
| 274 |
$subject = $atts['subject']; |
| 275 |
} |
| 276 |
if ( isset( $atts['message'] ) ) { |
| 277 |
$message = $atts['message']; |
| 278 |
} |
| 279 |
if ( isset( $atts['headers'] ) ) { |
| 280 |
$headers = $atts['headers']; |
| 281 |
} |
| 282 |
if ( isset( $atts['attachments'] ) ) { |
| 283 |
$attachments = $atts['attachments']; |
| 284 |
} |
| 285 |
|
| 286 |
if ( ! is_array( $attachments ) ) { |
| 287 |
$attach[] = str_replace( "\r\n", "\n", $attachments ); |
| 288 |
$attachments = implode( "\n", $attach ); |
| 289 |
} |
| 290 |
|
| 291 |
$content_type = null; |
| 292 |
// Headers |
| 293 |
$cc = $bcc = $reply_to = array(); |
| 294 |
$dynamicFrom = array(); |
| 295 |
if ( empty( $headers ) ) { |
| 296 |
$headers = array(); |
| 297 |
} else { |
| 298 |
if ( !is_array( $headers ) ) { |
| 299 |
// Explode the headers out, so this function can take both |
| 300 |
// string headers and an array of headers. |
| 301 |
$tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) ); |
| 302 |
} else { |
| 303 |
$tempheaders = $headers; |
| 304 |
} |
| 305 |
$headers = array(); |
| 306 |
// If it's actually got contents |
| 307 |
if ( !empty( $tempheaders ) ) { |
| 308 |
// Iterate through the raw headers |
| 309 |
foreach ( (array) $tempheaders as $header ) { |
| 310 |
if ( strpos($header, ':') === false ) { |
| 311 |
if ( false !== stripos( $header, 'boundary=' ) ) { |
| 312 |
$parts = preg_split('/boundary=/i', trim( $header ) ); |
| 313 |
$boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) ); |
| 314 |
} |
| 315 |
continue; |
| 316 |
} |
| 317 |
// Explode them out |
| 318 |
list( $name, $content ) = explode( ':', trim( $header ), 2 ); |
| 319 |
|
| 320 |
// Cleanup crew |
| 321 |
$name = trim( $name ); |
| 322 |
$content = trim( $content ); |
| 323 |
$content_type = null; |
| 324 |
switch ( strtolower( $name ) ) { |
| 325 |
case 'content-type': |
| 326 |
if ( strpos( $content, ';' ) !== false ) { |
| 327 |
list( $type, $charset_content ) = explode( ';', $content ); |
| 328 |
$content_type = trim( $type ); |
| 329 |
if ( false !== stripos( $charset_content, 'charset=' ) ) { |
| 330 |
$charset = trim( str_replace( array( 'charset=', '"' ), '', $charset_content ) ); |
| 331 |
} elseif ( false !== stripos( $charset_content, 'boundary=' ) ) { |
| 332 |
$boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) ); |
| 333 |
$charset = ''; |
| 334 |
} |
| 335 |
|
| 336 |
// Avoid setting an empty $content_type. |
| 337 |
} elseif ( '' !== trim( $content ) ) { |
| 338 |
$content_type = trim( $content ); |
| 339 |
} |
| 340 |
break; |
| 341 |
case 'cc': |
| 342 |
$cc = array_merge( (array) $cc, explode( ',', $content ) ); |
| 343 |
break; |
| 344 |
case 'bcc': |
| 345 |
$bcc = array_merge( (array) $bcc, explode( ',', $content ) ); |
| 346 |
break; |
| 347 |
case 'reply-to': |
| 348 |
$reply_to = array_merge( (array) $reply_to, explode( ',', $content ) ); |
| 349 |
break; |
| 350 |
case 'from': |
| 351 |
$dynamicFrom = array_merge( (array) $from, explode( ',', $content ) ); |
| 352 |
break; |
| 353 |
default: |
| 354 |
$headers[trim( $name )] = trim( $content ); |
| 355 |
break; |
| 356 |
} |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
$content_type = apply_filters( 'wp_mail_content_type', $content_type ); |
| 361 |
$data = array(); |
| 362 |
$token = base64_decode(get_option('transmail_send_mail_token')); |
| 363 |
$fromAddress = array(); |
| 364 |
if (!empty($from_name)) { |
| 365 |
$fromAddress['name'] = $from_name; |
| 366 |
} else { |
| 367 |
$fromAddress['name'] = get_option('transmail_from_name'); |
| 368 |
} |
| 369 |
if (!empty($dynamicFrom)) |
| 370 |
{ |
| 371 |
$dynpos = false; |
| 372 |
$dynpos = strpos($dynamicFrom[0], '<'); |
| 373 |
if($dynpos !== false) { |
| 374 |
$dynad = substr($dynamicFrom[0], $dynpos+1, strlen($dynamicFrom[0])-$dynpos-2); |
| 375 |
$dynfrom['address'] = sanitize_email($dynad); |
| 376 |
if($dynpos >0) { |
| 377 |
$dynfrom['name'] = substr($dynamicFrom[0],0,$dynpos-1); |
| 378 |
$fromAddress['name'] = $dynfrom['name']; |
| 379 |
} |
| 380 |
$fromAddress['address'] = $dynfrom['address']; |
| 381 |
} |
| 382 |
|
| 383 |
} |
| 384 |
else { |
| 385 |
$fromAddress['address'] = get_option('transmail_from_email_id'); |
| 386 |
|
| 387 |
|
| 388 |
} |
| 389 |
|
| 390 |
$data['from'] = $fromAddress; |
| 391 |
$zmbccs = array(); |
| 392 |
$zmbcc = array(); |
| 393 |
$zmbce = array(); |
| 394 |
if (!empty($bcc)) { |
| 395 |
$count = 0; |
| 396 |
foreach($bcc as $bc) { |
| 397 |
$zmbcc['address'] = $bc; |
| 398 |
$zmbce['email_address'] = $zmbcc; |
| 399 |
$zmbccs[$count] = $zmbce; |
| 400 |
$count = $count + 1; |
| 401 |
} |
| 402 |
$data['bcc'] = $zmbccs; |
| 403 |
} |
| 404 |
|
| 405 |
if(!empty($reply_to)) { |
| 406 |
$replyTos = array(); |
| 407 |
$replyTo = array(); |
| 408 |
$rte = array(); |
| 409 |
$count = 0; |
| 410 |
foreach($reply_to as $reply) { |
| 411 |
$pos = strpos($reply, '<'); |
| 412 |
if($pos !== false) { |
| 413 |
$ad = substr($reply, $pos+1, strlen($reply)-$pos-2); |
| 414 |
$replyTo['address'] = $ad; |
| 415 |
$replyTo['name'] = substr($reply,0,$pos-1); |
| 416 |
} else { |
| 417 |
$replyTo['address'] = $reply; |
| 418 |
} |
| 419 |
$replyTos[$count] = $replyTo; |
| 420 |
$count = $count + 1; |
| 421 |
} |
| 422 |
$data['reply_to'] = $replyTos; |
| 423 |
} |
| 424 |
$data['subject'] = $subject; |
| 425 |
|
| 426 |
if(!empty($to) && is_array($to)) { |
| 427 |
$tos = array(); |
| 428 |
$count = 0; |
| 429 |
foreach($to as $t) { |
| 430 |
$toa = array(); |
| 431 |
$toe = array(); |
| 432 |
$pos = strpos($t, '<'); |
| 433 |
if($pos !== false) { |
| 434 |
$ad = substr($t, $pos+1, strlen($t)-$pos-2); |
| 435 |
$toa['address'] = sanitize_email($ad); |
| 436 |
$toa['name'] = substr($t,0,$pos-1); |
| 437 |
} else { |
| 438 |
$toa['address'] = sanitize_email($t); |
| 439 |
} |
| 440 |
$toe['email_address'] = $toa; |
| 441 |
$tos[$count] = $toe; |
| 442 |
$count = $count + 1; |
| 443 |
} |
| 444 |
$data['to'] = $tos; |
| 445 |
} else { |
| 446 |
$toa = array(); |
| 447 |
$tos = array(); |
| 448 |
$toa['address'] = $to; |
| 449 |
$tos[0] = $toa; |
| 450 |
$data['to'] = $to; |
| 451 |
} |
| 452 |
//Check and update attachments |
| 453 |
if(!empty($attachments)) { |
| 454 |
$attachmentJSONArr = array(); |
| 455 |
$count = 0; |
| 456 |
foreach($attachments as $attfile) { |
| 457 |
$attachmentupload = array ( |
| 458 |
'name' => basename($attfile), |
| 459 |
'mime_type' => mime_content_type($attfile), |
| 460 |
'content' => base64_encode(file_get_contents($attfile)) |
| 461 |
); |
| 462 |
$attachmentJSONArr[$count] = $attachmentupload; |
| 463 |
$count = $count + 1; |
| 464 |
} |
| 465 |
$data['attachments'] = $attachmentJSONArr; |
| 466 |
} |
| 467 |
if( $content_type == 'text/html' || get_option('transmail_content_type') == 'html') { |
| 468 |
$data['htmlbody'] = $message; |
| 469 |
} else { |
| 470 |
$data['textbody'] = $message; |
| 471 |
|
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
$headers1 = array( |
| 476 |
'Authorization' => $token, |
| 477 |
'User-Agent' => 'Zepto_WordPress' |
| 478 |
); |
| 479 |
$data_string = json_encode($data); |
| 480 |
$args = array( |
| 481 |
'body' => $data_string, |
| 482 |
'headers' => $headers1, |
| 483 |
'method' => 'POST' |
| 484 |
); |
| 485 |
$urlToSend = 'https://zeptomail.zoho.'.get_option('transmail_domain_name').'/v1.1/email'; |
| 486 |
$responseSending = wp_remote_post( $urlToSend, $args ); |
| 487 |
$http_code = wp_remote_retrieve_response_code($responseSending); |
| 488 |
if(!is_wp_error( $responseSending )) |
| 489 |
update_option('transmail_test_mail_case', $responseSending['body'], false); |
| 490 |
|
| 491 |
$responseBody = wp_remote_retrieve_body($responseSending); |
| 492 |
$responseData = json_decode($responseBody); |
| 493 |
|
| 494 |
if($http_code == '200' || $http_code == '201') { |
| 495 |
return true; |
| 496 |
} |
| 497 |
|
| 498 |
$mail_data = array( |
| 499 |
'to' => $to, |
| 500 |
'subject' => $subject, |
| 501 |
'message' => $message, |
| 502 |
'headers' => $headers1, |
| 503 |
'attachments' => $attachments |
| 504 |
); |
| 505 |
|
| 506 |
do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $responseData->data, $mail_data ) ); |
| 507 |
return false; |
| 508 |
|
| 509 |
} |
| 510 |
} |
| 511 |
|