Пример #1
0
function sendemail()
{
    global $msg, $required;
    if (isset($_POST['ajax'])) {
        $ajax = $_POST['ajax'];
    } else {
        $ajax = false;
    }
    if (isset($_POST['action']) and $_POST['action'] == 'sendmail') {
        $body = BODY;
        $subject = SUBJECT;
        $post_data = array_map('stripslashes', $_POST);
        // print_r($post_data);
        // die;
        foreach ($required as $id_field) {
            if ($post_data[$id_field] == '' || is_null($post_data[$id_field])) {
                if ($ajax) {
                    end_ajax($msg['error']);
                } else {
                    redirect(ERROR_URL);
                }
            }
        }
        if (!is_email($post_data['email']) or $post_data['email'] == '') {
            if ($ajax) {
                end_ajax($msg['error']);
            } else {
                redirect(ERROR_URL);
            }
        }
        foreach ($post_data as $id => $var) {
            if ($id == 'message') {
                $var = nl2br($var);
            }
            $body = str_replace("%{$id}%", $var, $body);
        }
        $subject = str_replace("%messagetype%", $post_data['messagetype'], $subject);
        require_once "fzo.mail.php";
        $mail = new SMTP("localhost", "*****@*****.**", "Refrescola09");
        $headers = $mail->make_header(FROM_EMAIL, TO_EMAIL, $subject, 3, $cc, $bcc);
        $headers .= 'mime-version: 1.0' . "\r\n";
        $headers .= 'content-type: text/html; charset=utf-8' . "\r\n";
        $headers .= "Reply-To: " . $post_data['email'] . " \r\n";
        /* Pueden definirse más encabezados. Tener en cuenta la terminación de la linea con (\r\n) $header .= "Reply-To: ".$_POST['from']." \r\n"; $header .= "Content-Type: text/plain; charset=\"iso-8859-1\" \r\n"; $header .= "Content-Transfer-Encoding: 8bit \r\n"; $header .= "MIME-Version: 1.0 \r\n"; */
        $error = $mail->smtp_send(FROM_EMAIL, TO_EMAIL, $headers, $body, $cc, $bcc);
        // $sendmail = mail( TO_EMAIL, SUBJECT, $body, $headers );
        if ($error == "0") {
            if ($ajax) {
                end_ajax($msg['success']);
            } else {
                redirect(SUCCESS_URL);
            }
        } else {
            if ($ajax) {
                end_ajax($msg['not-sent']);
            } else {
                redirect(NOTSENT_URL);
            }
        }
    }
}
Пример #2
0
function sendemail()
{
    global $msg, $required;
    if (isset($_POST['ajax'])) {
        $ajax = $_POST['ajax'];
    } else {
        $ajax = false;
    }
    if (isset($_POST['action']) and $_POST['action'] == 'sendmail') {
        $body = BODY;
        $post_data = array_map('stripslashes', $_POST);
        // 	    print_r($post_data);
        // 	    die;
        foreach ($required as $id_field) {
            if ($post_data[$id_field] == '' || is_null($post_data[$id_field])) {
                if ($ajax) {
                    end_ajax($msg['error']);
                } else {
                    redirect(ERROR_URL);
                }
            }
        }
        if (!is_email($post_data['email']) or $post_data['email'] == '') {
            if ($ajax) {
                end_ajax($msg['error']);
            } else {
                redirect(ERROR_URL);
            }
        }
        foreach ($post_data as $id => $var) {
            if ($id == 'message') {
                $var = nl2br($var);
            }
            $body = str_replace("%{$id}%", $var, $body);
        }
        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
        $headers .= 'From: ' . FROM_NAME . ' <' . FROM_EMAIL . '>' . "\r\n" . 'Reply-To: ' . $post_data['email'];
        $sendmail = mail(TO_EMAIL, SUBJECT, $body, $headers);
        if ($sendmail) {
            if ($ajax) {
                end_ajax($msg['success']);
            } else {
                redirect(SUCCESS_URL);
            }
        } else {
            if ($ajax) {
                end_ajax($msg['not-sent']);
            } else {
                redirect(NOTSENT_URL);
            }
        }
    }
}