示例#1
0
function web_invoice_send_email($invoice_array, $reminder = false)
{
    global $wpdb;
    if (is_array($invoice_array)) {
        $counter = 0;
        foreach ($invoice_array as $invoice_id) {
            $invoice_info = $wpdb->get_row("SELECT * FROM " . Web_Invoice::tablename('main') . " WHERE invoice_num = '" . $invoice_id . "'");
            $profileuser = get_user_to_edit($invoice_info->user_id);
            if ($reminder) {
                $message = strip_tags(web_invoice_show_reminder_email($invoice_id));
                $subject = strip_tags(preg_replace_callback('/(%([a-z_]+))/', 'web_invoice_email_apply_variables', get_option('web_invoice_email_send_reminder_subject')));
            } else {
                $message = strip_tags(web_invoice_show_email($invoice_id));
                $subject = strip_tags(preg_replace_callback('/(%([a-z_]+))/', 'web_invoice_email_apply_variables', get_option('web_invoice_email_send_invoice_subject')));
            }
            $from = strip_tags(stripslashes(get_option("web_invoice_email_address")));
            $from_name = strip_tags(stripslashes(get_option("web_invoice_business_name")));
            $headers = "From: {$from_name} <{$from}>";
            $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
            $attachments = array(web_invoice_pdf_file($invoice_id));
            if (wp_mail($profileuser->user_email, $subject, $message, $headers, $attachments)) {
                $counter++;
                // Success in sending quantified.
                unlink($attachments[0]);
                web_invoice_update_log($invoice_id, 'contact', 'Invoice eMailed');
                //make sent entry
                web_invoice_update_invoice_meta($invoice_id, "sent_date", date("Y-m-d", time()));
            }
        }
        return "Successfully sent {$counter} Web Invoices(s).";
    } else {
        $invoice_id = $invoice_array;
        $invoice_info = $wpdb->get_row("SELECT * FROM " . Web_Invoice::tablename('main') . " WHERE invoice_num = '" . $invoice_array . "'");
        $profileuser = get_userdata($invoice_info->user_id);
        if ($reminder) {
            $message = strip_tags(web_invoice_show_reminder_email($invoice_id));
            $subject = strip_tags(preg_replace_callback('/(%([a-z_]+))/', 'web_invoice_email_apply_variables', get_option('web_invoice_email_send_reminder_subject')));
        } else {
            $message = strip_tags(web_invoice_show_email($invoice_id));
            $subject = strip_tags(preg_replace_callback('/(%([a-z_]+))/', 'web_invoice_email_apply_variables', get_option('web_invoice_email_send_invoice_subject')));
        }
        $from = strip_tags(stripslashes(get_option("web_invoice_email_address")));
        $from_name = strip_tags(stripslashes(get_option("web_invoice_business_name")));
        $headers = "From: {$from_name} <{$from}>";
        $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
        $attachments = array(web_invoice_pdf_file($invoice_id));
        if (wp_mail($profileuser->user_email, $subject, $message, $headers, $attachments)) {
            unlink($attachments[0]);
            web_invoice_update_invoice_meta($invoice_id, "sent_date", date("Y-m-d", time()));
            web_invoice_update_log($invoice_id, 'contact', 'Invoice eMailed');
            return "Web invoice sent successfully.";
        } else {
            return "There was a problem sending the invoice.";
        }
    }
}
示例#2
0
function web_invoice_show_invoice($invoice_id)
{
    apply_filters('web_invoice_email_variables', $invoice_id);
    echo preg_replace_callback('/(%([a-z_]+))/', 'web_invoice_email_apply_variables', "<div class=\"subject\">Subject: <strong>" . get_option('web_invoice_email_send_invoice_subject') . "</strong></div>");
    echo "<div class=\"main_content\">";
    echo str_replace("\n", "<br />", web_invoice_show_email($invoice_id));
    echo "</div>";
}