PHP不想从Hostinger托管发送任何电子邮件

时间:2018-06-22 20:35:45

标签: php email hosting

我的网站上的联系表格有问题。该网站目前处于启用状态,但是无论是否有错误,联系表单都不想发送任何电子邮件。

这是我的代码。请您告诉我我哪里做错了吗?任何建议都会有所帮助。

<?php

if(isset($_POST['email'])) {
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "tabaccogiftshop@gmail.com";
    $email_subject = $_POST['last_name'];

    /*function died($error) {
        // your error code can go here
        echo "We are very sorry but there were errors whith your submit";
        echo "These errors appear bellow. <br> <br>";
        echo $error."<br> <br>";
        echo "Please go back and fix those errors";
        die();
    }*/
    // validation expected data exists
    if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['comments']) || !isset($_POST['captcha'])) {
        $error_message = "Sva polja se moraju unijeti!";
    }

    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $email_from = $_POST['email'];
    $comments = $_POST['comments'];
    $captcha = $_POST['captcha'];
    $error_message = "";
    $success = "";

    $string_exp = "/^[A-Za-z .'-]+$/";


    if(!preg_match($string_exp, $first_name)) {
        $error_message = "Name should not hold numbers!";
    }

    if(!preg_match($string_exp, $last_name)) {
        $error_message = "Subject should not hold numbers!";
    }

    if(!preg_match("/5/", $captcha)) {
        $error_message = "Captcha is not valid,  please try again!";
    }

    if(strlen($comments) < 2 ) {
        $error_message = "Message you have entered is too short,  please try again!";
    }

    if(strlen($error_message) > 0) {
        echo '

                        <div class="alert alert-danger alert-dismissible">
                            <strong>Error! </strong>'.$error_message.'
                            <button class="close" data-dismiss="alert"> &times;</button>
                        </div>

                        ';

                        include_once('includes-en/form-en.php');
                        include_once('includes-en/footer-en.php');

                        die();
    }

    if(isset($_POST['submit']) && strlen($error_message) === 0) {
        $success = "We have recieved your message,  we will get in touch with you as soon as possible!";
    }

    if(strlen($success) > 0) {
         echo '

                        <div class="alert alert-success alert-dismissible">
                            <strong>Success! </strong>'.$success.'
                            <button class="close" data-dismiss="alert"> &times;</button>
                    </div>


                        ';
    }




    function clean_string($string) {
        $bad = array("content-type", "bcc:", "to:", "cc:", "href");
        return str_replace($bad, "", $string);
    }

    $email_message = "Form details below. \n\n";

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Message: ".clean_string($comments)."\n";
    // Create email headers_list
    $headers = 'From: '.$email_from.'\r\n'.'Reply To: '.$email_from.'\r\n'.'X-Mailer: PHP/' .phpversion();

    @mail($email_to, $email_subject, $email_message, $headers);
    ?>
    <?php
}

    ?>

0 个答案:

没有答案