| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user, $wpscfunction,$wpdb; |
| 7 |
|
| 8 |
$send_mail_count = get_option('wpsc_en_send_mail_count'); |
| 9 |
|
| 10 |
$from_name = get_option('wpsc_en_from_name',''); |
| 11 |
|
| 12 |
$emails = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpsc_email_notification WHERE attemp=0 ORDER BY id ASC LIMIT $send_mail_count "); |
| 13 |
$fail_emails = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpsc_email_notification WHERE attemp <> 0 ORDER BY id ASC LIMIT 1"); |
| 14 |
$all_mails = array_merge($emails, $fail_emails); |
| 15 |
|
| 16 |
foreach($all_mails as $email){ |
| 17 |
|
| 18 |
$reply_to = $email->reply_to ? $email->reply_to : $email->from_email; |
| 19 |
|
| 20 |
$headers = "From: {$from_name} <{$email->from_email}>\r\n"; |
| 21 |
$headers .= "Reply-To: {$reply_to}\r\n"; |
| 22 |
$email_addresses = explode(',',$email->bcc_email); |
| 23 |
foreach ($email_addresses as $email_address) { |
| 24 |
$headers .= "BCC: {$email_address}\r\n"; |
| 25 |
} |
| 26 |
|
| 27 |
$headers .= "Content-Type: text/html; charset=utf-8\r\n"; |
| 28 |
|
| 29 |
$mail_status = wp_mail($email->to_email, $email->email_subject, $email->email_body, $headers); |
| 30 |
|
| 31 |
$attemp = $email->attemp+1; |
| 32 |
if(!$mail_status){ |
| 33 |
$values=array( |
| 34 |
'send_date' => date("Y-m-d H:i:s"), |
| 35 |
'mail_status' => 1, |
| 36 |
'attemp' => $attemp |
| 37 |
); |
| 38 |
$wpdb->update($wpdb->prefix.'wpsc_email_notification', $values, array('id'=>$email->id)); |
| 39 |
|
| 40 |
if($attemp >= 3){ |
| 41 |
do_action('wpsc_after_failed_attemp_mail_sent',$email); |
| 42 |
$wpdb->delete($wpdb->prefix.'wpsc_email_notification',array('id'=>$email->id)); |
| 43 |
} |
| 44 |
}else{ |
| 45 |
do_action('wpsc_after_successfully_mail_sent',$email); |
| 46 |
$wpdb->delete($wpdb->prefix.'wpsc_email_notification',array('id'=>$email->id)); |
| 47 |
} |
| 48 |
} |
| 49 |
|