function emailInvoice($invoice_type_id, $invoiceid, $user_id)
{
    global $wpdb;
    require_once ABSPATH . 'wp-content/themes/CSTEM/PHPMailer-master/class.phpmailer.php';
    $form_type = $wpdb->get_var($wpdb->prepare("SELECT form_type FROM wp_invoice_type WHERE invoice_type_id = %d", $invoice_type_id));
    $form_name = $wpdb->get_var($wpdb->prepare("SELECT invoice_name FROM wp_invoice_type WHERE invoice_type_id = %d", $invoice_type_id));
    $user_info = get_userdata($user_id);
    $to = $user_info->user_email;
    // user's email or that of first email if submitting for others
    $recipients = get_recipients_list($form_type, $invoice_type_id, $invoiceid);
    // get recipients (CC Addresses)
    $email_contents = get_email_contents($form_type, $invoice_type_id, $invoiceid, $user_id);
    // get subject & body
    $subject = $email_contents["subject"];
    $message = $email_contents["message"];
    // message lines should not exceed 70 characters (PHP rule), so wrap it
    $message = wordwrap($message, 70);
    // Email object
    $email = new PHPMailer();
    $email->isHTML(true);
    // allows for email formatting
    $email->CharSet = "UTF-8";
    // allows for special character display
    switch ($invoice_type_id) {
        case 8:
            //Student Application
            $email->From = "*****@*****.**";
            $email->FromName = "C-STEM Center";
            $location_name = $wpdb->get_var($wpdb->prepare("SELECT field_value FROM  `wp_invoice_data` WHERE invoice_no = %d AND field_name =  'location'", $invoiceid));
            if (strcmp($location_name, "Valley View, Pleasant Hill, CA") == 0) {
                $email->AddBCC("hawess@mdusd.org ", "Shauna Hawes");
                //$email->AddBCC("*****@*****.**", "Shauna Hawes");
            }
            //If the student will be participating in Valley View, Pleasant Hill, BCC the email to Shauna Hawes
            break;
        case 9:
            //Assistant Coach Application
            $email->From = "*****@*****.**";
            $email->FromName = "C-STEM Center";
            $location_name = $wpdb->get_var($wpdb->prepare("SELECT field_value FROM  `wp_invoice_data` WHERE invoice_no = %d AND field_name =  'location'", $invoiceid));
            if (strcmp($location_name, 'Valley View, Pleasant Hill, CA') == 0) {
                //$email->AddBCC("*****@*****.**", "Shauna Hawes");
                $email->AddBCC("hawess@mdusd.org ", "Shauna Hawes");
            }
            //If the student will be participating in Valley View, Pleasant Hill, BCC the email to Shauna Hawes		break;
            break;
        case 18:
            //Coach Application
            $email->From = "*****@*****.**";
            $email->FromName = "C-STEM Center";
            $location_name = $wpdb->get_var($wpdb->prepare("SELECT field_value FROM  `wp_invoice_data` WHERE invoice_no = %d AND field_name =  'location'", $invoiceid));
            if (strcmp($location_name, 'Valley View, Pleasant Hill, CA') == 0) {
                $email->AddBCC("hawess@mdusd.org ", "Shauna Hawes");
            }
            //If the student will be participating in Valley View, Pleasant Hill, BCC the email to Shauna Hawes
            break;
        case 17:
            //Order Review Copies
            $email->From = "*****@*****.**";
            $email->FromName = "C-STEM Center";
            $to = $wpdb->get_var($wpdb->prepare("SELECT  `field_value` FROM  `wp_invoice_data` WHERE  `invoice_no` = %d AND  `field_name` =  'email_address'", $invoiceid));
            break;
        case 13:
            // Tech Support
            $email->From = "*****@*****.**";
            $email->FromName = "C-STEM Tech Support";
            break;
        default:
            $email->From = "*****@*****.**";
            $email->FromName = "C-STEM Center";
            break;
    }
    // switch: From
    $email->Subject = $subject;
    $email->Body = $message;
    $email->AddAddress($to);
    foreach ($recipients as $mail => $name) {
        $email->AddBCC($mail);
    }
    $form_name = str_replace(' ', '_', $form_name);
    $file_name = $form_name . '_' . $invoiceid . '.pdf';
    /*	// add attachments
    	switch($invoice_type_id) {
    	case 8: // Girl Camp
    	$invoice_file = 'Application_' . $invoiceid . '.pdf';
    	break;
    
    	case 13: // Tech Support
    	$invoice_file = 'Support_' . $invoiceid . '.pdf';
    	break;
    
    	default:
    	$invoice_file = 'Quote_' . $invoiceid . '.pdf';
    	break;
    } // switch: attachment file name*/
    switch ($invoice_type_id) {
        case 9:
            // Girl Camp Assistant Coach
            $rec_file = '2015TeacherRecForm(fillable).pdf';
            $rec_file_attachment = 'wp-content/invoices_files/' . $rec_file;
            $email->AddAttachment($rec_file_attachment, $rec_file);
            break;
        case 10:
            //C-STEM Awards
            $rec_file = 'CSTEMAwardApplicationForm.pdf';
            $rec_file_attachment = 'wp-content/invoice_files/' . $rec_file;
            $email->AddAttachment($rec_file_attachment, $rec_file);
            break;
        case 18:
            //Coach application
            $rec_file = '2015TeacherRecForm(fillable).pdf';
            $rec_file_attachment = 'wp-content/invoice_files/' . $rec_file;
            $email->AddAttachment($rec_file_attachment, $rec_file);
            break;
    }
    //$file_to_attach = 'wp-content/plugins/contact-form-7/html2pdf/' . $file_name;
    $file_to_attach = '/var/www/wordpress/wp-content/invoice_files/' . $file_name;
    if ($invoice_type_id != 10) {
        $email->AddAttachment($file_to_attach, $file_name);
    }
    $email->Send();
}
function emailInvoice($invoice_type_id, $invoiceid, $user_id)
{
    global $wpdb;
    require_once ABSPATH . 'wp-content/themes/CSTEM/PHPMailer-master/class.phpmailer.php';
    $form_type = $wpdb->get_var($wpdb->prepare("SELECT form_type FROM wp_invoice_type WHERE invoice_type_id = %d", $invoice_type_id));
    $form_name = $wpdb->get_var($wpdb->prepare("SELECT invoice_name FROM wp_invoice_type WHERE invoice_type_id = %d", $invoice_type_id));
    $user_info = get_userdata($user_id);
    $to = $user_info->user_email;
    // user's email or that of first email if submitting for others
    $recipients = get_recipients_list($form_type, $invoice_type_id, $invoiceid);
    // get recipients (CC Addresses)
    $email_contents = get_email_contents($form_type, $invoice_type_id, $invoiceid, $user_id);
    // get subject & body
    $subject = $email_contents["subject"];
    $message = $email_contents["message"];
    // message lines should not exceed 70 characters (PHP rule), so wrap it
    $message = wordwrap($message, 70);
    // Email object
    $email = new PHPMailer();
    $email->isHTML(true);
    // allows for email formatting
    $email->CharSet = "UTF-8";
    // allows for special character display
    switch ($invoice_type_id) {
        case 13:
            // Tech Support
            $email->From = "*****@*****.**";
            $email->FromName = "C-STEM Tech Support";
            break;
        default:
            $email->From = "*****@*****.**";
            $email->FromName = "C-STEM Center";
            break;
    }
    // switch: From
    $email->Subject = $subject;
    $email->Body = $message;
    $email->AddAddress($to);
    foreach ($recipients as $mail => $name) {
        $email->AddBCC($mail);
    }
    $form_name = str_replace(' ', '_', $form_name);
    $file_name = $form_name . '_' . $invoiceid . '.pdf';
    /*	// add attachments
    	switch($invoice_type_id) {
    		case 8: // Girl Camp
    			$invoice_file = 'Application_' . $invoiceid . '.pdf';
    			break;
    
    		case 13: // Tech Support
    			$invoice_file = 'Support_' . $invoiceid . '.pdf';
    			break;
    
    		default:
    			$invoice_file = 'Quote_' . $invoiceid . '.pdf';
    			break;
    	} // switch: attachment file name*/
    switch ($invoice_type_id) {
        case 8:
            // Girl Camp
            $rec_file = 'Teacher_Rec.pdf';
            $rec_file_attachment = 'wp-content/invoice_files/' . $rec_file;
            $email->AddAttachment($rec_file_attachment, $rec_file);
            break;
    }
    $file_to_attach = 'wp-content/invoice_files/' . $file_name;
    if ($invoice_type_id != 10) {
        $email->AddAttachment($file_to_attach, $file_name);
    }
    $email->Send();
}