function do_send($to_str, $subject_str, $text_str)
{
    // 7/7/09
    global $istest;
    require_once 'smtp.inc.php';
    // defer load until required - 8/2/10
    $sleep = 4;
    // seconds delay between text messages
    $my_smtp_ary = explode("/", trim(get_variable('smtp_acct')));
    //	if ((count($my_smtp_ary)>1) && (count($my_smtp_ary)!=6)) {
    if (count($my_smtp_ary) > 1 && count($my_smtp_ary) < 5) {
        // 4/19/11
        do_log($GLOBALS['LOG_ERROR'], 0, 0, "Invalid smtp account information: " . trim(get_variable('smtp_acct')));
        return;
    }
    if (count($my_smtp_ary) > 3 && !is_email(trim($my_smtp_ary[3]))) {
        // email format test
        do_log($GLOBALS['LOG_ERROR'], 0, 0, "Invalid smtp account address: " . trim($my_smtp_ary[5]));
        return;
    }
    $temp = explode("/", trim(get_variable('email_reply_to')));
    if (!is_email(trim($temp[0]))) {
        // accommodate possible /B
        do_log($GLOBALS['LOG_ERROR'], 0, 0, "Invalid email reply-to: " . trim(get_variable('email_reply_to')));
        return;
    }
    function stripLabels($sText)
    {
        $labels = array("Incident:", "Priority:", "Nature:", "Addr:", "Descr:", "Reported by:", "Phone:", "Written:", "Updated:", "Status:", "Disp:", "Run Start:", "Map:", "Patient:", "Actions:", "Tickets host:");
        // 5/9/10
        for ($x = 0; $x < count($labels); $x++) {
            $sText = str_replace($labels[$x], '', $sText);
        }
        return $sText;
    }
    $to_array = array_values(array_unique(explode("|", $to_str)));
    // input is pipe-delimited string  - 10/17/08
    require_once "cell_addrs.inc.php";
    // 10/22/08
    $ary_cell_addrs = $ary_ll_addrs = array();
    for ($i = 0; $i < count($to_array); $i++) {
        // walk down the input address string/array
        $temp = explode("@", $to_array[$i]);
        if (in_array(trim(strtolower($temp[1])), $cell_addrs)) {
            // cell addr?
            array_push($ary_cell_addrs, $to_array[$i]);
            // yes
        } else {
            // no, land line addr
            array_push($ary_ll_addrs, $to_array[$i]);
        }
    }
    // end for ($i = ...)
    $caption = "";
    $my_from_ary = explode("/", trim(get_variable('email_from')));
    // note /B option
    $my_replyto_str = trim(get_variable('email_reply_to'));
    $count_cells = $count_ll = 0;
    // counters
    if (count($ary_ll_addrs) > 0) {
        // got landline addee's?
        //								  ($my_smtp_ary, $my_to_ary, $my_subject_str, $my_message_str, $my_from_ary, $my_replyto_str)
        if (count($my_smtp_ary) > 1) {
            $count_ll = do_swift_mail($my_smtp_ary, $ary_ll_addrs, $subject_str, $text_str, $my_from_ary, $my_replyto_str);
        } else {
            //									   ($my_smtp_ary, $my_to_ary, $my_subject_str, $my_message_str, $my_from_ary, $my_replyto_str)
            $count_ll = do_native_mail($my_smtp_ary, $ary_ll_addrs, $subject_str, $text_str, $my_from_ary, $my_replyto_str);
        }
    }
    if (count($ary_cell_addrs) > 0) {
        // got cell addee's?
        $lgth = 140;
        $ix = 0;
        $i = 1;
        $cell_text_str = stripLabels($text_str);
        // strip labels 5/10/10
        while (substr($cell_text_str, $ix, $lgth)) {
            // chunk to $lgth-length strings
            $subject_ex = $subject_str . "/part " . $i . "/";
            // 10/21/08
            //										 ($my_smtp_ary, $my_to_ary, $my_subject_str, $my_message_str, $my_from_ary, $my_replyto_str)
            if (count($my_smtp_ary) > 1) {
                $count_cells = do_swift_mail($my_smtp_ary, $ary_cell_addrs, $subject_ex, substr($cell_text_str, $ix, $lgth), $my_from_ary, $my_replyto_str);
            } else {
                //										  ($my_smtp_ary, $my_to_ary, $my_subject_str, $my_message_str, $my_from_ary, $my_replyto_str)
                $count_cells = do_native_mail($my_smtp_ary, $ary_cell_addrs, $subject_ex, substr($cell_text_str, $ix, $lgth), $my_from_ary, $my_replyto_str);
            }
            if ($i > 1) {
                sleep($sleep);
            }
            // 10/17/08
            $ix += $lgth;
            $i++;
        }
        // end while (substr($cell_text_...))
    }
    // end if (count($ary_cell_addrs)>0)
    return (string) ($count_ll + $count_cells);
}
function do_send($to_str, $subject_str, $text_str)
{
    // 7/7/09
    global $istest;
    $sleep = 4;
    // seconds delay between text messages
    function stripLabels($sText)
    {
        $labels = array("Incident:", "Priority:", "Nature:", "Addr:", "Descr:", "Reported by:", "Phone:", "Written:", "Updated:", "Status:", "Disp:", "Run Start:", "Map:", get_text("Patient") . ":", "Actions:", "Tickets host:");
        // 5/9/10
        for ($x = 0; $x < count($labels); $x++) {
            $sText = str_replace($labels[$x], '', $sText);
        }
        return $sText;
    }
    $to_array = explode("|", $to_str);
    // pipe-delimited string  - 10/17/08
    require_once "cell_addrs.inc.php";
    // 10/22/08
    $cell_addrs = array("vtext.com", "messaging.sprintpcs.com", "txt.att.net", "vmobl.com", "myboostmobile.com");
    // 10/5/08
    if ($istest) {
        array_push($cell_addrs, "gmail.com");
    }
    $host = get_variable('host');
    $temp = get_variable('email_reply_to');
    //	$reply_to = (empty($temp))? "": "'Reply-To: '". $temp ."\r\n" ;
    $reply_to = empty($temp) ? "" : "'Reply-To: " . $temp . "'\r\n";
    // 2/18/10
    $temp = get_variable('email_from');
    // 6/24/09
    if (empty($temp)) {
        $from_str = "Tickets_CAD" . '@' . $host;
    } else {
        $temp_ar = explode("@", $temp);
        if (count($temp_ar) == 2) {
            $from_str = $temp;
            // OK
        } else {
            $from_str = $temp_ar[0] . "@" . $host;
        }
    }
    //	$from = (empty($temp))?  "Tickets_CAD" : $temp;
    $headers = 'From:' . $from_str . "\r\n" . $reply_to . 'X-Mailer: PHP/' . phpversion();
    $to_sep = $cell_sep = "";
    $tostr = $tocellstr = "";
    for ($i = 0; $i < count($to_array); $i++) {
        $temp = explode("@", $to_array[$i]);
        if (in_array(trim(strtolower($temp[1])), $cell_addrs)) {
            // cell addr?
            $tocellstr .= $cell_sep . stripslashes($to_array[$i]);
            // yes
            $cell_sep = ",";
        } else {
            // no
            $tostr .= $to_sep . stripslashes($to_array[$i]);
            $to_sep = ",";
            // comma separated addr string
        }
    }
    // end for ($i = ...)
    $caption = "";
    $smtp = trim(get_variable('smtp_acct'));
    // 7/7/09
    if (strlen($tostr) > 0) {
        if (strlen($smtp) == 0) {
            @mail($tostr, $subject_str, $text_str, $headers);
        } else {
            smtp($tostr, $subject_str, $text_str, $smtp, $from_str);
            // ($my_to, $my_subject, $my_message, $my_params)
        }
        $caption = "Email sent";
    }
    if (strlen($tocellstr) > 0) {
        $lgth = 140;
        $ix = 0;
        $i = 1;
        $cell_text_str = stripLabels($text_str);
        // strip labels 5/10/10
        while (substr($cell_text_str, $ix, $lgth)) {
            // chunk to $lgth-length strings
            $subject_ex = $subject_str . "/part " . $i . "/";
            // 10/21/08
            if (strlen($smtp) == 0) {
                mail($tocellstr, $subject_ex, substr($cell_text_str, $ix, $lgth), $headers);
            } else {
                smtp($tocellstr, $subject_ex, substr($cell_text_str, $ix, $lgth), $smtp, $from_str);
                // ($my_to, $my_subject, $my_message, $my_params, $my_from)
            }
            if ($i > 1) {
                sleep($sleep);
            }
            // 10/17/08
            $ix += $lgth;
            $i++;
        }
        $caption .= " - Cell mail sent";
    }
    return $caption;
}