?>
</option>
			</select><br/><i><small><?php 
_e('Add Email Header Text', MAILUSERS_I18N_DOMAIN);
?>
</small></i></td>
	</tr>
	<tr>
		<th scope="row" valign="top">
            <label for="mailusers_header"><?php 
_e('Email Header<br/>Content', MAILUSERS_I18N_DOMAIN);
?>
</th>
		<td>
            <?php 
wp_editor(stripslashes(mailusers_get_header()), "mailusers_header", array('textarea_rows' => 4));
?>
		</td>
	</tr>
	<tr>
		<th scope="row" valign="top">
			<label for="mailusers_footer_usage"><?php 
_e('Email Footer<br/>Usage', MAILUSERS_I18N_DOMAIN);
?>
</th>
		<td>
			<select class="mailusers-select" name="mailusers_footer_usage" style="width: 235px;">
				<option value="notification" <?php 
if (mailusers_get_footer_usage() == 'notification') {
    echo 'selected="true"';
}
/**
 * Delivers email to recipients in HTML or plaintext
 *
 * Returns number of recipients addressed in emails or false on internal error.
 */
function mailusers_send_mail($recipients = array(), $subject = '', $message = '', $type = 'plaintext', $sender_name = '', $sender_email = '', $useheader = false, $usefooter = false)
{
    $headers = array();
    $base64 = mailusers_get_base64_encode() == 'true';
    $omit = mailusers_get_omit_display_names() == 'true';
    //  Default the To: and Cc: values to the send email address
    //  Some MTAs won't deliver email with an address in the TO header!
    $to = $omit ? $sender_email : sprintf('%s <%s>', $sender_name, $sender_email);
    $cc = sprintf('Cc: %s', $to);
    $num_sent = 0;
    // return value
    if (empty($recipients)) {
        return $num_sent;
    }
    if ('' == $message) {
        return false;
    }
    //  Cc: Sender?
    $ccsender = mailusers_get_copy_sender();
    //  Return path defaults to sender email if not specified
    //$return_path = mailusers_get_send_bounces_to_address_override() ;
    //if (!empty($return_path)) {
    //    echo '<div class="update-nag fade"><p>' . sprintf(__('Setting a bounce email address is no longer supported due to casuing problems delivering mail.  Please remove the current setting (%s).', MAILUSERS_I18N_DOMAIN), $return_path) . '</p></div>';
    //}
    //  Build headers
    $headers[] = $omit ? sprintf('From: %s', $sender_email) : sprintf('From: "%s" <%s>', $sender_name, $sender_email);
    //$headers[] = sprintf('Return-Path: <%s>', $return_path);
    //  Return path defaults to sender email if not specified
    $return_path = mailusers_get_send_bounces_to_address_override();
    if (empty($return_path)) {
        $headers[] = $omit ? sprintf('Reply-To: %s', $sender_email) : sprintf('Reply-To: "%s" <%s>', $sender_name, $sender_email);
    }
    //$headers[] = 'MIME-Version: 1.0';
    if (mailusers_get_add_x_mailer_header() == 'true') {
        $headers[] = sprintf('X-Mailer: PHP %s', phpversion());
    }
    $subject = stripslashes($subject);
    $message = stripslashes($message);
    $header = $useheader ? mailusers_replace_blog_templates(mailusers_get_header()) : '';
    $footer = $usefooter ? mailusers_replace_blog_templates(mailusers_get_footer()) : '';
    if ('html' == $type) {
        if (mailusers_get_add_mime_version_header() == 'true') {
            $headers[] = 'MIME-Version: 1.0';
        }
        $headers[] = sprintf('Content-Type: %s; charset="%s"', get_bloginfo('html_type'), get_bloginfo('charset'));
        //  Apply HTML wrapper filter(s) if one exists
        if (has_filter('mailusers_html_wrapper')) {
            $mailtext = apply_filters('mailusers_html_wrapper', $subject, $message, $footer);
        } else {
            $mailtext = "<html><head><title>" . $subject . "</title></head><body>" . $header . $message . $footer . "</body></html>";
        }
    } else {
        if (mailusers_get_add_mime_version_header() == 'true') {
            $headers[] = 'MIME-Version: 1.0';
        }
        $headers[] = sprintf('Content-Type: text/plain; charset="%s"', get_bloginfo('charset'));
        $message = preg_replace('|&[^a][^m][^p].{0,3};|', '', $message);
        $message = preg_replace('|&amp;|', '&', $message);
        $mailtext = wordwrap(strip_tags($header . "\n" . $message . "\n" . $footer), 80, "\n");
    }
    //  Base64 Encode email?
    if ($base64) {
        //$subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
        $headers[] = "Content-Transfer-Encoding: base64";
        //$mailtext = base64_encode($mailtext);
    }
    // If unique recipient, send mail using TO field.
    //--
    // If multiple recipients, use the BCC field
    //--
    $bcc = array();
    $bcc_limit = mailusers_get_max_bcc_recipients();
    if (count($recipients) == 1) {
        $recipient = reset($recipients);
        // reset will return first value of the array!
        if (mailusers_is_valid_email($recipient->user_email)) {
            $to = $omit ? $recipient->user_email : sprintf('%s <%s>', $recipient->display_name, $recipient->user_email);
            if ($ccsender) {
                $headers[] = $cc;
            }
            if (MAILUSERS_DEBUG) {
                mailusers_preprint_r($headers);
                mailusers_debug_wp_mail($to, $subject, $mailtext, $headers);
            }
            do_action('mailusers_before_wp_mail');
            //  Filter to manipulate the headers?
            if (has_filter('mailusers_manipulate_headers')) {
                $mh = apply_filters('mailusers_manipulate_headers', $to, $headers, $bcc);
                list($to, $headers, $bcc) = $mh;
            }
            if ($base64) {
                @wp_mail($to, sprintf("=UTF-8?B?%s?=", base64_encode($subject)), base64_encode($mailtext), $headers);
            } else {
                @wp_mail($to, $subject, $mailtext, $headers);
            }
            do_action('mailusers_after_wp_mail');
            $num_sent++;
        } else {
            echo '<div class="error fade"><p>' . sprintf(__('The email address (%s) of the user you are trying to send mail to is not a valid email address format.', MAILUSERS_I18N_DOMAIN), $recipient->user_email) . '</p></div>';
            return $num_sent;
        }
        return $num_sent;
    } elseif ($bcc_limit != 0 && count($recipients) > $bcc_limit) {
        $count = 0;
        $sender_emailed = false;
        //  Make sure there are no duplicates which can result
        //  if/when the user selects both roles and users as
        //  the recipients.
        foreach ($recipients as $key => $value) {
            $recipients[$key] = $recipients[$key]->user_email;
        }
        $recipients = array_unique($recipients);
        foreach ($recipients as $recipient) {
            if (!mailusers_is_valid_email($recipient)) {
                continue;
            }
            if (empty($recipient) || $sender_email == $recipient) {
                continue;
            }
            //  When BCC limit is -1, use the TO header to send instead of BCC header
            if ($bcc_limit == -1) {
                //$to = ($omit) ? $recipient->user_email : sprintf('%s <%s>', $recipient->display_name, $recipient->user_email) ;
                $to = $recipient;
            } else {
                $bcc[] = sprintf('Bcc: %s', $recipient);
            }
            $count++;
            //  Use abs() of bcc_limit to account for -1 setting
            if (abs($bcc_limit) == $count || $num_sent == count($recipients) - 1) {
                if (MAILUSERS_DEBUG) {
                    mailusers_debug_wp_mail($to, $subject, $mailtext, array_merge($headers, $bcc));
                }
                do_action('mailusers_before_wp_mail');
                //  Filter to manipulate the headers?
                if (has_filter('mailusers_manipulate_headers')) {
                    $mh = apply_filters('mailusers_manipulate_headers', $to, $headers, $bcc);
                    list($to, $headers, $bcc) = $mh;
                }
                if ($base64) {
                    @wp_mail($to, sprintf("=UTF-8?B?%s?=", base64_encode($subject)), base64_encode($mailtext), array_merge($headers, $bcc));
                } else {
                    @wp_mail($to, $subject, $mailtext, array_merge($headers, $bcc));
                }
                do_action('mailusers_after_wp_mail');
                $count = 0;
                $bcc = array();
            }
            $num_sent++;
        }
    } else {
        if ($ccsender) {
            $headers[] = $cc;
        }
        foreach ($recipients as $key => $value) {
            $recipients[$key] = $recipients[$key]->user_email;
        }
        $recipients = array_unique($recipients);
        foreach ($recipients as $recipient) {
            if (!mailusers_is_valid_email($recipient)) {
                echo '<div class="error fade"><p>' . sprintf(__('Invalid email address ("%s") found.', MAILUSERS_I18N_DOMAIN), $recipient) . '</p></div>';
                continue;
            }
            if (empty($recipient) || $sender_email == $recipient) {
                continue;
            }
            $bcc[] = sprintf('Bcc: %s', $recipient);
            $num_sent++;
        }
        if (MAILUSERS_DEBUG) {
            mailusers_preprint_r(array_merge($headers, $bcc));
            mailusers_debug_wp_mail($to, $subject, $mailtext, array_merge($headers, $bcc));
        }
        do_action('mailusers_before_wp_mail');
        //  Filter to manipulate the headers?
        if (has_filter('mailusers_manipulate_headers')) {
            $mh = apply_filters('mailusers_manipulate_headers', $to, $headers, $bcc);
            list($to, $headers, $bcc) = $mh;
        }
        if ($base64) {
            @wp_mail($to, sprintf("=UTF-8?B?%s?=", base64_encode($subject)), base64_encode($mailtext), array_merge($headers, $bcc));
        } else {
            @wp_mail($to, $subject, $mailtext, array_merge($headers, $bcc));
        }
        do_action('mailusers_after_wp_mail');
    }
    return $num_sent;
}