Send bulk email to users


Create admin tab menu(Bulk email) and submenu (Users list) in backend.

Bulk email tab: You can send email all of users with custom Mail Title and Mail Body.

Users list tab: Fetch all users email address from database table.


/* Register admin main menu and submenu */
add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('None Members', 'None Members', 'manage_options', 'none-member', 'my_menu_output' );
add_submenu_page('none-member', 'Send bulk email', 'Send bulk email', 'manage_options', 'none-member' );
add_submenu_page('none-member', 'Members list', 'Members list', 'manage_options', 'my-menu2', 'memberslist' );

/* admin main menu */
function my_menu_output(){
echo "<h2>Send Bulk Email</h2>";

echo '<form method="post">';
echo '<input style="border:1px solid; type=text" placeholder="Subject" width="358" name="subject"><br><br>';
echo '<textarea style="border:1px solid;" name="message" rows="5" cols="40" placeholder="Message"></textarea> <br><br>';
echo '<input style="border:1px solid;" type="submit" name="submit" value="Send Bulk Email" class="bulk_email">';

echo '</form>';


$subjectmail = $_POST['subject'];
$messagemail = $_POST['message'];

global $wpdb;
$retrieve_data = $wpdb->get_results( "SELECT nonmember_email FROM wp_non_member" );

$emails = array();
foreach($retrieve_data as $retrieve_datas){
$emails[] = $retrieve_datas->nonmember_email;
$send_email = implode(",",$emails);

$blogusers = get_users( 'role=administrator' );
foreach ( $blogusers as $user ) {

$multiple_recipients = array($send_email,$from_email);
$subject = $subjectmail;
$message = $messagemail;
wp_mail( $multiple_recipients, $subject, $message );
window.location = document.URL;

/* Admin sub menu */
function memberslist(){
echo "<h2>All Nonmembers User</h2>";
global $wpdb;

$retrieve_data = $wpdb->get_results( "SELECT * FROM wp_non_member" );
echo '<table class="table table-striped"><tr><th>Name</th><th>Email</th></tr>';
foreach ($retrieve_data as $retrieved_data){
echo '<tr><td>'. $retrieved_data->nonmember_name.'</td>';
echo '<td>'.$retrieved_data->nonmember_email.'</td></tr>';
echo '</table>';


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: