예제 #1
0
function SendCheckedMail($to, $subject, $mesg, $from, $a_headers = array())
{
    global $PEAR_SMTP_HOST;
    $b_f_option = false;
    $b_form_option = IsMailOptionSet("SendMailFOption");
    // this is superseded, but still supported
    if (SENDMAIL_F_OPTION || $b_form_option) {
        if (empty($from)) {
            //
            // SENDMAIL_F_OPTION with no sender is silently ignored
            //
            if ($b_form_option) {
                //
                // form has specified SendMailFOption, but there's no
                // sender address
                //
                static $b_in_here = false;
                global $SERVER;
                if (!$b_in_here) {
                    $b_in_here = true;
                    SendAlert(GetMessage(MSG_NO_FOPT_ADDR));
                    $b_in_here = false;
                }
                //
                // if there's no from address, create a dummy one
                //
                $from = "dummy@" . (isset($SERVER) ? $SERVER : "UnknownServer");
                $a_headers['From'] = $from;
                $b_f_option = true;
            }
        } else {
            $b_f_option = true;
        }
    }
    if (INI_SET_FROM && !empty($from)) {
        ini_set('sendmail_from', $from);
    }
    if ((!isset($PEAR_SMTP_HOST) || empty($PEAR_SMTP_HOST)) && $b_f_option) {
        return mail($to, $subject, $mesg, ExpandMailHeaders($a_headers), "-f{$from}");
    } else {
        return DoMail($to, $subject, $mesg, $a_headers);
    }
}
function DoMail($s_to, $s_subject, $s_mesg, $a_headers, $s_options)
{
    global $PEAR_SMTP_HOST, $PEAR_SMTP_PORT, $PEAR_SMTP_USER, $PEAR_SMTP_PWD;
    //
    // Encode the subject line.
    // Ideally, we want to encode the relevant parts of To, From, Cc,
    // Reply-To, and this is the right place to do it.
    // However, it's another 1000 lines of code!
    // So, we must compromise the code quality because of this cost.
    // We encode subject here, and we encode the From line where it's
    // created.  The rest remain for a future version where code size
    // can be controlled.
    //
    $s_subject = EncodeHeaderText($s_subject);
    if (isset($PEAR_SMTP_HOST) && !empty($PEAR_SMTP_HOST)) {
        //
        // Note that PEAR Mail seems to take responsibility for header line folding
        //
        require_once "Mail.php";
        $a_params = array("host" => $PEAR_SMTP_HOST, "port" => $PEAR_SMTP_PORT);
        if (isset($PEAR_SMTP_USER) && !empty($PEAR_SMTP_USER)) {
            $a_params["auth"] = TRUE;
            $a_params["username"] = $PEAR_SMTP_USER;
            $a_params["password"] = $PEAR_SMTP_PWD;
        }
        $mailer = Mail::factory("smtp", $a_params);
        if (!is_object($mailer)) {
            ShowError("pear_error", GetMessage(MSG_PEAR_OBJ), FALSE, FALSE);
            exit;
        }
        if (strtolower(get_class($mailer)) === 'pear_error') {
            ShowError("pear_error", $mailer->getMessage(), FALSE, FALSE);
            exit;
        }
        if (!isset($a_headers['To']) && !isset($a_headers['to'])) {
            $a_headers['To'] = SafeHeader($s_to);
        }
        if (!isset($a_headers['Subject']) && !isset($a_headers['subject'])) {
            $a_headers['Subject'] = SafeHeader($s_subject);
        }
        $res = $mailer->send($s_to, $a_headers, $s_mesg);
        if ($res === TRUE) {
            return TRUE;
        }
        global $aAlertInfo;
        $aAlertInfo[] = GetMessage(MSG_PEAR_ERROR, array("MSG" => $res->getMessage()));
        return FALSE;
    } else {
        //$s_subject = HeaderFolding($s_subject,RFCLINELEN-10);   // "Subject: " is about 10 chars
        //
        // Notes from Feb 2010....
        //
        // PHP's mail function (tested in version 5.2.6) does folding of the
        // To line and the Subject line.
        // If we do it, then things break.
        //
        // This area is quite confusing.  It's not clear whether the script
        // should be folding header lines or whether the MTA should do it.
        // We *do know* (as stated above) that folding To and Subject breaks things.
        //
        // But folding other header lines properly, seems to be OK.
        //
        // However, for years FormMail never did header line folding (except for the
        // soft line breaks inserted by the quoted_printable_encode function we had used),
        // and we didn't seem to get any reports of breakage (except for problems
        // with the quoted_printable_encode soft line breaks!).
        //
        // So, even though we've implemented all the code for header line folding,
        // we'll not use it.
        // No header line folding will be performed in version 8.22 onwards.
        //
        if ($s_options !== "") {
            return mail($s_to, $s_subject, $s_mesg, ExpandMailHeaders($a_headers), $s_options);
        } else {
            return mail($s_to, $s_subject, $s_mesg, ExpandMailHeaders($a_headers));
        }
    }
}
예제 #3
0
function SendCheckedMail($to, $subject, $mesg, $from, $a_headers = array())
{
    if (IsMailOptionSet("SendMailFOption")) {
        if (empty($from)) {
            static $b_in_here = false;
            global $SERVER;
            if (!$b_in_here) {
                $b_in_here = true;
                SendAlert("You've specified 'SendMailFOption', but there's no email address to use");
                $b_in_here = false;
            }
            //
            // if there's no from address, create a dummy one
            //
            $from = "dummy@" . (isset($SERVER) ? $SERVER : "UnknownServer");
            $a_headers['From'] = $from;
        }
        return mail($to, $subject, $mesg, ExpandMailHeaders($a_headers), "-f{$from}");
    }
    return DoMail($to, $subject, $mesg, $a_headers);
}