= '2.6.5') check_admin_referer('alo-easymail_main'); if(isset($_REQUEST['submit'])) { // prepare array with recipients' addresses $recipients = array(); // prepare for error $error = ""; // Retrieve post info for TAG $pID = $_REQUEST['select_post']; if ((int)$pID) { $obj_post = get_post($pID); } // If request add all SUBSCRIBERS if ($_REQUEST['select_recipients'] == 'subscr') { $subs = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}easymail_subscribers WHERE active='1'" ); foreach ($subs as $sub) { $recipients[$sub->email]['email'] = $sub->email; $recipients[$sub->email]['name'] = $sub->name; $recipients[$sub->email]['firstname'] = $sub->name; $recipients[$sub->email]['unikey'] = $sub->unikey; } // If request add all REGISTERED users } else if ($_REQUEST['select_recipients'] == 'users') { $reg_users = $wpdb->get_results( "SELECT ID AS UID, user_email FROM $wpdb->users" ); foreach ($reg_users as $reg_user) { $recipients[$reg_user->user_email]['email'] = $reg_user->user_email; $recipients[$reg_user->user_email]['name'] = ucfirst(get_usermeta($reg_user->UID, 'first_name'))." " .ucfirst(get_usermeta($reg_user->UID,'last_name')); $recipients[$reg_user->user_email]['firstname'] = ucfirst(get_usermeta($reg_user->UID, 'first_name')); } } // If any add NO-REGISTERED E-MAILS if ($_REQUEST['emails_add']) { $wrong_add_email = ""; // show them in error div $non_reg_emails = explode(",", $_REQUEST['emails_add']); foreach ($non_reg_emails as $non_reg_email) { $trim_non_reg_email = trim($non_reg_email); if (ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $trim_non_reg_email )) { $recipients[$trim_non_reg_email]['email'] = $trim_non_reg_email; } else { $wrong_add_email .= $trim_non_reg_email." "; } } } // ------------------ // PREPARE THE E-MAIL // ------------------ // From $mail_sender = "noreply@". str_replace("www.","", $_SERVER['HTTP_HOST']); // Headers $headers = "MIME-Version: 1.0\n"; $headers .= "From: ".get_option('blogname')." <".$mail_sender.">\n"; //$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n"; $headers .= "Content-Type: text/html; charset=UTF-8\n"; $headers .= "Content-Transfer-Encoding: 7bit\n\n"; // Subject $subject = stripslashes($wpdb->escape($_REQUEST['input_subject'])); // Main content $main_content = stripslashes($_REQUEST['content']); $main_content = str_replace("\n", "
", $main_content); // check input error: if any stop here if ($subject == "" || $main_content == "") $error .= "- Fill 'subject' and 'main body' fields.
"; if ($_REQUEST['select_recipients'] == 'none' && trim($_REQUEST['emails_add']) == "") $error .= "- No recipients specified.
"; if ($error != "" || $wrong_add_email != "") { //wp_redirect( get_option ('siteurl')."/".'wp-admin/edit.php?page=alo-easymail/alo-easymail_main.php&message='.$error); echo " "; echo "

Error.

"; if ($error !="") echo "

$error

"; if ($wrong_add_email !="") echo "

- Some inserted email addesses are incorrect, please check:
$wrong_add_email.

"; echo "
"; echo "

close

"; exit; } // Save content for next sending, if request if ($_REQUEST['ck_save_template']) update_option('ALO_em_template', $main_content); // Save emails'list for next sending, if request if ($_REQUEST['ck_save_list']) update_option('ALO_em_list', trim($_REQUEST['emails_add']) ); $r = 0; // count sent $s = 0; // count sending success $e = 0; // count sending error $listnosent = ""; // list no sent mails // SEND EMAIL TO EACH RECIPIENT foreach ($recipients as $recipient) { $r ++; // add this send to count // For each recipient delete TAGs update $updated_content = $main_content; // TAG: [POST-TITLE] if ($pID) { $updated_content = str_replace("[POST-TITLE]", $obj_post->post_title, $updated_content); } else { $updated_content = str_replace("[POST-TITLE]", "", $updated_content); } // TAG: [POST-CONTENT] if ($pID) { $updated_content = str_replace("[POST-CONTENT]", $obj_post->post_content, $updated_content); } else { $updated_content = str_replace("[POST-CONTENT]", "", $updated_content); } // TAG: [POST-EXCERPT] - if any if ($pID && !empty($obj_post->post_excerpt)) { $updated_content = str_replace("[POST-EXCERPT]", $obj_post->post_excerpt, $updated_content); } else { $updated_content = str_replace("[POST-EXCERPT]", "", $updated_content); } // TAG: [USER-NAME] if ($recipient['name']) { $updated_content = str_replace("[USER-NAME]", $recipient['name'], $updated_content); } else { $updated_content = str_replace("[USER-NAME]", "", $updated_content); } //>>>>>>> added GAL // TAG: [USER-FIRST-NAME] if ($recipient['firstname']) { $updated_content = str_replace("[USER-FIRST-NAME]", $recipient['firstname'], $updated_content); } else { $updated_content = str_replace("[USER-FIRST-NAME]", "", $updated_content); } //<<<<<<<<< end added GAL // TAG: [SITE-LINK] $updated_content = str_replace("[SITE-LINK]", "".get_option('blogname')."", $updated_content); // Unsubscribe link, only if subscriber if ($recipient['unikey']) { $div_email = explode("@", $recipient['email']); // for link $updated_content .= "

You have received this message because you subscribed our newsletter. If you want to unsubscribe please "; $updated_content .= "click here."; $updated_content .= "

"; } // ---- Send MAIL ---- $mail_engine = @wp_mail($recipient['email'], $subject, $updated_content, $headers); if($mail_engine) { $s ++; // add to success count $recipients[$recipient['email']]['result'] = 1; } else { $listnosent .= $recipient['email'].","; $e ++; // add to error count $recipients[$recipient['email']]['result'] = 0; } // some rest for the processor... if ( ($r % 50) == 0) { sleep(10); // every n° sent wait a little } // DEBUG //echo "
".$headers."
".$recipient['email']."
". $subject."
". $updated_content ."
" ; } // format // $listnosent = str_replace("@", ";at;", $listnosent); // DEBUG //print_r ($recipients); //print_r ($name_for_tag); //print_r ($_REQUEST); //echo $listnosent; /*foreach ($recipients as $rec) { echo "
";print_r ($rec);echo "
"; }*/ // At the end: redirect //wp_redirect( get_option ('siteurl')."/".'wp-admin/edit.php?page=alo-easymail/alo-easymail_main.php&message=success&nsent='.$r.'&nsucc='.$s.'&listnosent='.$listnosent); echo " "; // reset Submit text //wp_enqueue_script( 'listman' ); //wp_print_scripts(); // REPORT echo "

RESULT

"; echo " $r sent"; echo "
$s successful delivered"; if ($e > 0 && $r!=$s) echo "
$e not delivered"; // Summary table ?>

"; echo ""; } echo "
E-mail Name Delivered
".$n."".$recipient['email']."".$recipient['name']."
"; // $listnosent (cut last comma) if ($listnosent != "") { echo "

If you want you can copy the not delivered addresses from box below and paste them in recipients' field of the previous page to try again:
"; echo "
"; } // go back //echo "

« back "; echo "

close

"; } exit; ?>