function _SendEmail($s_to, $s_subj, $a_values, $b_use_template)
 {
     global $aPHPVERSION, $SPECIAL_VALUES, $FROM_USER;
     //
     // need PHP 4.0.5 for the preg_replace_callback function
     //
     if (!IsPHPAtLeast("4.0.5")) {
         SendAlert(GetMessage(MSG_PHP_AUTORESP, array("PHPVERS" => implode(".", $aPHPVERSION))));
         return false;
     }
     $a_headers = array();
     $s_mail_text = "";
     $s_from_addr = GetAROption("FromAddr");
     if (!isset($s_from_addr)) {
         $s_from_addr = "";
         if (isset($FROM_USER) && !empty($FROM_USER)) {
             if ($FROM_USER != "NONE") {
                 $s_from_addr = $FROM_USER;
             }
         } else {
             global $SERVER;
             $s_from_addr = "FormMail@" . $SERVER;
         }
     } else {
         $s_from_addr = UnMangle($s_from_addr);
     }
     if (!empty($s_from_addr)) {
         $a_headers['From'] = SafeHeader($s_from_addr);
     }
     $s_type = "";
     if ($b_use_template) {
         if (IsAROptionSet('PlainTemplate')) {
             $s_type .= "PlainTemplate ";
             $s_template = GetAROption("PlainTemplate");
             if (!ProcessTemplate($s_template, $a_lines, $a_values, GetAROption('TemplateMissing'), 'SubstituteValuePlain')) {
                 return false;
             }
             FMDebug("AutoRespond: PlainTemplate " . count($a_lines) . " lines");
             $s_mail_text = implode(BODY_LF, $a_lines);
         }
         if (IsAROptionSet("HTMLTemplate")) {
             $s_type .= "HTMLTemplate ";
             if (!MakeMimeMail($s_mail_text, $a_headers, $a_values, GetAROption("HTMLTemplate"), GetAROption('TemplateMissing'))) {
                 return false;
             }
             FMDebug("AutoRespond: HTMLTemplate " . strlen($s_mail_text) . " bytes");
         }
     } else {
         global $TEMPLATEURL, $TEMPLATEDIR;
         if (IsAROptionSet('PlainFile')) {
             $s_type .= "PlainFile ";
             //
             // load the plain text file from the templates area
             //
             if (empty($TEMPLATEDIR) && empty($TEMPLATEURL)) {
                 SendAlert(GetMessage(MSG_TEMPLATES));
                 return false;
             }
             $s_file = GetAROption("PlainFile");
             if (($a_lines = LoadTemplate($s_file, $TEMPLATEDIR, $TEMPLATEURL, true)) === false) {
                 return false;
             }
             $s_mail_text = implode(BODY_LF, $a_lines);
             FMDebug("AutoRespond: PlainFile " . count($a_lines) . " lines");
         }
         if (IsAROptionSet("HTMLFile")) {
             $s_type .= "HTMLFile ";
             if (!MakeMimeMail($s_mail_text, $a_headers, $a_values, GetAROption("HTMLFile"), "", false, "", array(), array(), false)) {
                 return false;
             }
             FMDebug("AutoRespond: HTMLTemplate " . strlen($s_mail_text) . " bytes");
         }
     }
     if (strlen($s_mail_text) == 0) {
         SendAlert(GetMessage(MSG_ARESP_EMPTY), array("TYPE" => $s_type));
     }
     FMDebug("AutoRespond: message is " . strlen($s_mail_text) . " bytes");
     return SendCheckedMail($s_to, $s_subj, $s_mail_text, $s_from_addr, $a_headers);
 }
Example #2
0
 function _SendEmail($s_to, $s_subj, $a_values, $b_use_template)
 {
     global $SPECIAL_VALUES;
     $a_headers = array();
     $s_mail_text = "";
     $s_from_addr = GetAROption("FromAddr");
     if (!isset($s_from_addr)) {
         $s_from_addr = "";
         if (!Settings::isEmpty('FROM_USER')) {
             if (Settings::get('FROM_USER') != "NONE") {
                 $s_from_addr = Settings::get('FROM_USER');
             }
         } else {
             global $SERVER;
             $s_from_addr = "FormMail@" . $SERVER;
         }
     } else {
         $s_from_addr = UnMangle($s_from_addr);
     }
     if (!empty($s_from_addr)) {
         $a_headers['From'] = SafeHeader($s_from_addr);
     }
     $s_type = "";
     if ($b_use_template) {
         if (IsAROptionSet('PlainTemplate')) {
             $s_type .= "PlainTemplate ";
             $s_template = GetAROption("PlainTemplate");
             if (!ProcessTemplate($s_template, $a_lines, $a_values, GetAROption('TemplateMissing'), 'SubstituteValuePlain')) {
                 return false;
             }
             FMDebug("AutoRespond: PlainTemplate " . count($a_lines) . " lines");
             $s_mail_text = implode(Settings::get('BODY_LF'), $a_lines);
         }
         if (IsAROptionSet("HTMLTemplate")) {
             $s_type .= "HTMLTemplate ";
             if (!MakeMimeMail($s_mail_text, $a_headers, $a_values, GetAROption("HTMLTemplate"), GetAROption('TemplateMissing'))) {
                 return false;
             }
             FMDebug("AutoRespond: HTMLTemplate " . strlen($s_mail_text) . " bytes");
         }
     } else {
         if (IsAROptionSet('PlainFile')) {
             $s_type .= "PlainFile ";
             //
             // load the plain text file from the templates area
             //
             if (Settings::isEmpty('TEMPLATEDIR') && Settings::isEmpty('TEMPLATEURL')) {
                 SendAlert(GetMessage(MSG_TEMPLATES));
                 return false;
             }
             $s_file = GetAROption("PlainFile");
             if (($a_lines = LoadTemplate($s_file, Settings::get('TEMPLATEDIR'), Settings::get('TEMPLATEURL'), true)) === false) {
                 return false;
             }
             $s_mail_text = implode(Settings::get('BODY_LF'), $a_lines);
             FMDebug("AutoRespond: PlainFile " . count($a_lines) . " lines");
         }
         if (IsAROptionSet("HTMLFile")) {
             $s_type .= "HTMLFile ";
             if (!MakeMimeMail($s_mail_text, $a_headers, $a_values, GetAROption("HTMLFile"), "", false, "", array(), array(), false)) {
                 return false;
             }
             FMDebug("AutoRespond: HTMLTemplate " . strlen($s_mail_text) . " bytes");
         }
     }
     if (strlen($s_mail_text) == 0) {
         SendAlert(GetMessage(MSG_ARESP_EMPTY), array("TYPE" => $s_type));
     }
     FMDebug("AutoRespond: message is " . strlen($s_mail_text) . " bytes");
     return SendCheckedMail($s_to, $s_subj, $s_mail_text, $s_from_addr, $a_headers);
 }
Example #3
0
function SendAlert($s_error, $b_filter = true, $b_non_error = false)
{
    global $SPECIAL_VALUES, $FORMATTED_INPUT, $FROM_USER, $aServerVars, $aStrippedFormVars;
    global $aAlertInfo;
    $s_error = str_replace("\n", BODY_LF, $s_error);
    $b_got_filter = isset($SPECIAL_VALUES["filter"]) && !empty($SPECIAL_VALUES["filter"]);
    //
    // if there is a filter specified and we're not sending the alert
    // through the filter, don't show the user's data.  This is
    // on the assumption that the filter is an encryption program; so,
    // we don't want to send the user's data in clear text inside the
    // alerts.
    //
    $b_show_data = true;
    if ($b_got_filter && !$b_filter) {
        $b_show_data = false;
    }
    $s_form_subject = $s_alert_to = "";
    $b_check = true;
    //
    // might be too early to have $SPECIAL_VALUES set, so
    // look in the form vars too
    //
    if (isset($SPECIAL_VALUES["alert_to"])) {
        $s_alert_to = trim($SPECIAL_VALUES["alert_to"]);
    }
    if (empty($s_alert_to) && isset($aStrippedFormVars["alert_to"])) {
        $s_alert_to = trim($aStrippedFormVars["alert_to"]);
    }
    if (isset($SPECIAL_VALUES["subject"])) {
        $s_form_subject = trim($SPECIAL_VALUES["subject"]);
    }
    if (empty($s_form_subject) && isset($aStrippedFormVars["subject"])) {
        $s_form_subject = trim($aStrippedFormVars["subject"]);
    }
    if (empty($s_alert_to)) {
        $s_alert_to = DEF_ALERT;
        $b_check = false;
    }
    if (!empty($s_alert_to)) {
        $s_from_addr = $s_from = "";
        $a_headers = array();
        if (isset($FROM_USER)) {
            if ($FROM_USER != "NONE") {
                $a_headers['From'] = $FROM_USER;
                $s_from = "From: {$FROM_USER}";
                $s_from_addr = $FROM_USER;
            }
        } else {
            global $SERVER;
            $s_from_addr = "FormMail@" . $SERVER;
            $a_headers['From'] = $s_from_addr;
            $s_from = "From: {$s_from_addr}";
        }
        $s_mesg = "To: " . UnMangle($s_alert_to) . BODY_LF;
        if (!empty($s_from)) {
            $s_mesg .= $s_from . BODY_LF;
        }
        $s_mesg .= BODY_LF;
        if (count($aAlertInfo) > 0) {
            if ($b_show_data) {
                $s_error .= BODY_LF . "More information:" . BODY_LF;
                $s_error .= implode(BODY_LF, $aAlertInfo);
            } else {
                $s_error .= BODY_LF . "(Extra alert information suppressed for security purposes.)" . BODY_LF;
            }
        }
        if ($b_non_error) {
            $s_mesg .= $s_error . BODY_LF . BODY_LF;
            $s_subj = "FormMail alert";
            if (!empty($s_form_subject)) {
                $s_subj .= " ({$s_form_subject})";
            }
        } else {
            $s_mesg .= "The following error occurred in FormMail:" . BODY_LF . $s_error . BODY_LF . BODY_LF;
            $s_subj = "FormMail script error";
            if (!empty($s_form_subject)) {
                $s_subj .= " ({$s_form_subject})";
            }
            if ($b_show_data) {
                $s_mesg .= implode(BODY_LF, $FORMATTED_INPUT);
            } else {
                $s_mesg .= "(User data suppressed for security purposes.)";
            }
        }
        if ($b_filter && $b_got_filter) {
            $s_mesg = "This alert has been filtered through '" . $SPECIAL_VALUES["filter"] . "' for security purposes." . BODY_LF . BODY_LF . Filter($SPECIAL_VALUES["filter"], $s_mesg);
        }
        if ($b_check) {
            if (CheckEmailAddress($s_alert_to, $s_valid, $s_invalid)) {
                return SendCheckedMail($s_valid, $s_subj, $s_mesg, $s_from_addr, $a_headers);
            }
        } else {
            return SendCheckedMail($s_alert_to, $s_subj, $s_mesg, $s_from_addr, $a_headers);
        }
    }
    return false;
}
Example #4
0
function SendResults($a_fld_order, $a_clean_fields, $s_to, $s_cc, $s_bcc, $a_raw_fields)
{
    global $SPECIAL_VALUES, $aFileVars;
    //
    // check for a filter and how to use it
    //
    $b_got_filter = isset($SPECIAL_VALUES["filter"]) && !empty($SPECIAL_VALUES["filter"]);
    $b_filter_attach = false;
    $a_attach_spec = array();
    $s_filter = "";
    $a_filter_list = array();
    if ($b_got_filter) {
        $s_filter = $SPECIAL_VALUES["filter"];
        if (isset($SPECIAL_VALUES["filter_fields"]) && !empty($SPECIAL_VALUES["filter_fields"])) {
            $b_limited_filter = true;
            $a_filter_list = TrimArray(explode(",", $SPECIAL_VALUES["filter_fields"]));
        } else {
            $b_limited_filter = false;
        }
        $s_filter_attach_name = GetFilterOption("Attach");
        if (isset($s_filter_attach_name)) {
            if (!is_string($s_filter_attach_name) || empty($s_filter_attach_name)) {
                SendAlert(GetMessage(MSG_ATTACH_NAME));
            } else {
                $b_filter_attach = true;
                $a_attach_spec = array("Name" => $s_filter_attach_name);
                if (($s_mime = GetFilterAttrib($s_filter, "MIME")) !== false) {
                    $a_attach_spec["MIME"] = $s_mime;
                }
                //
                // Regarding the character set...
                // A filter will not generally change the character set
                // of the message, however, if it does, then we
                // provide that information to the MIME encoder.
                // Remember: this character set specification refers
                // to the data *after* the effect of the filter
                // has been reversed (e.g. an encrypted message
                // in UTF-8 is in UTF-8 when it is decrypted).
                //
                if (($s_cset = GetFilterAttrib($s_filter, "CharSet")) !== false) {
                    $a_attach_spec["CharSet"] = $s_cset;
                }
            }
        }
    }
    //
    // check the need for MIME formatted mail
    //
    $b_mime_mail = IsMailOptionSet("HTMLTemplate") || count($aFileVars) > 0 || $b_filter_attach;
    //
    // create the email header lines - CC, BCC, and From
    //
    $a_headers = array();
    if (!empty($s_cc)) {
        $a_headers['Cc'] = $s_cc;
    }
    //
    // note that BCC is documented to not work prior to PHP 4.3
    //
    if (!empty($s_bcc)) {
        global $aPHPVERSION;
        if ($aPHPVERSION[0] < 4 || $aPHPVERSION[0] == 4 && $aPHPVERSION[1] < 3) {
            SendAlert(GetMessage(MSG_PHP_BCC, array("PHPVERS" => implode(".", $aPHPVERSION))));
        }
        $a_headers['Bcc'] = $s_bcc;
    }
    //
    // create the From address
    //
    // Some servers won't let you set the email address to the
    // submitter of the form.  Therefore, use FromAddr if it's been
    // specified.  If it's empty, don't specify a sender.
    //
    $s_sender = GetMailOption("FromAddr");
    if (!isset($s_sender)) {
        $s_sender = "";
        if (!empty($SPECIAL_VALUES["email"])) {
            $a_headers['From'] = MakeFromLine($SPECIAL_VALUES["email"], $SPECIAL_VALUES["realname"]);
        }
    } elseif ($s_sender !== "") {
        $a_headers['From'] = UnMangle($s_sender);
    }
    //
    // special case: if there is only one non-special string value, then
    // format it as an email (unless an option says not to)
    //
    $a_keys = array_keys($a_raw_fields);
    if (count($a_keys) == 1 && is_string($a_raw_fields[$a_keys[0]]) && !IsMailOptionSet("AlwaysList") && !IsMailOptionSet("DupHeader")) {
        if (IsMailExcluded($a_keys[0])) {
            SendAlert("Exclusion of single field '" . $a_keys[0] . "' ignored");
        }
        $s_value = $a_raw_fields[$a_keys[0]];
        //
        // replace carriage return/linefeeds with <br>
        //
        $s_value = str_replace("\r\n", '<br />', $s_value);
        //
        // replace lone linefeeds with <br>
        //
        $s_value = str_replace("\n", '<br />', $s_value);
        //
        // remove lone carriage returns
        //
        $s_value = str_replace("\r", "", $s_value);
        //
        // replace all control chars with <br>
        //
        $s_value = preg_replace('/[[:cntrl:]]+/', '<br />', $s_value);
        //
        // strip HTML (note that all the <br> above will now be
        // replaced with BODY_LF)
        //
        $s_value = StripHTML($s_value, BODY_LF);
        if ($b_mime_mail) {
            if ($b_got_filter) {
                //
                // filter the whole value (ignore filter_fields for this
                // special case) if a filter has been specified
                //
                $s_results = Filter($s_filter, $s_value);
                if ($b_filter_attach) {
                    $a_attach_spec["Data"] = $s_results;
                    $s_results = "";
                    $s_filter = "";
                    // no more filtering
                }
            } else {
                $s_results = $s_value;
            }
            //
            // send this single value off to get formatted in a MIME
            // email
            //
            if (!MakeMimeMail($s_results, $a_headers, $a_raw_fields, GetMailOption('HTMLTemplate'), GetMailOption('TemplateMissing'), IsMailOptionSet("NoPlain"), $s_filter, $aFileVars, $a_attach_spec)) {
                return false;
            }
        } elseif ($b_got_filter) {
            //
            // filter the whole value (ignore filter_fields for this special case)
            // if a filter has been specified
            //
            $s_results = Filter($s_filter, $s_value);
        } else {
            $s_results = $s_value;
        }
    } else {
        if ($b_mime_mail) {
            //
            // get the plain text version of the email then send it
            // to get MIME formatted
            //
            list($s_results, $s_unfiltered_results, $s_filtered_results) = MakePlainEmail($a_fld_order, $a_clean_fields, $s_to, $s_cc, $s_bcc, $a_raw_fields, $s_filter, $a_filter_list);
            if ($b_filter_attach) {
                //
                // attached the filtered results
                //
                $a_attach_spec["Data"] = $s_filtered_results;
                //
                // put the unfiltered results in the body of the message
                //
                $s_results = $s_unfiltered_results;
                $s_filter = "";
                // no more filtering
            }
            if (!MakeMimeMail($s_results, $a_headers, $a_raw_fields, GetMailOption('HTMLTemplate'), GetMailOption('TemplateMissing'), IsMailOptionSet("NoPlain"), $s_filter, $aFileVars, $a_attach_spec)) {
                return false;
            }
        } else {
            list($s_results, $s_unfiltered_results, $s_filtered_results) = MakePlainEmail($a_fld_order, $a_clean_fields, $s_to, $s_cc, $s_bcc, $a_raw_fields, $s_filter, $a_filter_list);
            if (!$b_got_filter && IsMailOptionSet("CharSet")) {
                //
                // sending plain text email, and the CharSet has been
                // specified; include a header
                //
                $a_headers['Content-Type'] = "text/plain; charset=" . GetMailOption("CharSet");
            }
        }
    }
    //
    // append the environment variables report
    //
    if (isset($SPECIAL_VALUES["env_report"])) {
        $s_results .= BODY_LF . "==================================" . BODY_LF;
        $s_results .= BODY_LF . GetEnvVars(TrimArray(explode(",", $SPECIAL_VALUES["env_report"])), BODY_LF);
    }
    //
    // send the mail - assumes the email addresses have already been checked
    //
    return SendCheckedMail($s_to, $SPECIAL_VALUES["subject"], $s_results, $s_sender, $a_headers);
}
Example #5
0
function AutoRespond($s_to, $s_subj, $a_values)
{
    global $aPHPVERSION, $SPECIAL_VALUES, $FROM_USER;
    //
    // need PHP 4.0.5 for the preg_replace_callback function
    //
    if (!IsPHPAtLeast("4.0.5")) {
        SendAlert(GetMessage(MSG_PHP_AUTORESP, array("PHPVERS" => implode(".", $aPHPVERSION))));
        return false;
    }
    $a_headers = array();
    $s_mail_text = "";
    $s_from_addr = GetAROption("FromAddr");
    if (!isset($s_from_addr)) {
        $s_from_addr = "";
        if (isset($FROM_USER) && !empty($FROM_USER)) {
            if ($FROM_USER != "NONE") {
                $s_from_addr = $FROM_USER;
            }
        } else {
            global $SERVER;
            $s_from_addr = "FormMail@" . $SERVER;
        }
    } else {
        $s_from_addr = UnMangle($s_from_addr);
    }
    if (!empty($s_from_addr)) {
        $a_headers['From'] = $s_from_addr;
    }
    if (IsAROptionSet('PlainTemplate')) {
        $s_template = GetAROption("PlainTemplate");
        if (!ProcessTemplate($s_template, $a_lines, $a_values, GetAROption('TemplateMissing'), 'SubstituteValuePlain')) {
            return false;
        }
        $s_mail_text = implode(BODY_LF, $a_lines);
    }
    if (IsAROptionSet("HTMLTemplate")) {
        if (!MakeMimeMail($s_mail_text, $a_headers, $a_values, GetAROption("HTMLTemplate"), GetAROption('TemplateMissing'))) {
            return false;
        }
    }
    return SendCheckedMail($s_to, $s_subj, $s_mail_text, $s_from_addr, $a_headers);
}