.php контактная форма отправляет, но не отправляет - PullRequest
0 голосов
/ 11 декабря 2018

В настоящее время я создаю очень простую контактную форму для сайта, над которым я работаю, но по какой-то причине моя обычная форма перехода не хочет работать.Php выглядит следующим образом:

    <?php
    // Check for HTML in comment
    function screen_form($ary_check_for_html)
    {
    // check array - reject if any content contains HTML.
    foreach($ary_check_for_html as $field_value)
    {        
    if(is_array($field_value))
    {
    foreach($field_value as $field_array)  // if the field value is an array, step through it
    {
    $stripped = strip_tags($field_array);
    if($field_array!=$stripped) 
    {
    // something in the field value was HTML
    return false;
    }
    }
    } else {
    $stripped = strip_tags($field_value);
    if($field_value!=$stripped) 
    {
    // something in the field value was HTML
    return false;
    }
    }
    }
    return true;
    }

    # Catcher for errors
    $FORM_ERROR = array();
    $SUCCESS = false;
    $resp = null;

    # Check for form processing
    if($_POST) {
    # Little bit of safety checking....
    # Added to try and halt spam....
    sleep(1);

    if(!$_POST['gonzo']) {
    die('No spam thank you.');
    }

    if(!screen_form($_POST)) {
    sleep(5);
    die('No HTML in forms thank you.');
    }

    $form_init = base64_decode($_POST['gonzo']);
    $now = time();
    $diff = $now - $form_init;

    if($form_init > $now || $diff > 1800) {
    die('Attempt failed - Please retry.');
    }

    $stamp = date('d-m-Y H:i:s', $form_init);

    # Validate submission....
    if(!$_POST['name']) {
    array_push($FORM_ERROR, 'name');
    }
    if(!$_POST['email']) {
    array_push($FORM_ERROR, 'email');
    }
    if(!$_POST['telephone']) {
    array_push($FORM_ERROR, 'telephone');
    }
    if(!$_POST['message']) {
    array_push($FORM_ERROR, 'message');
    }

    if(count($FORM_ERROR) < 1) {
    # Escape our values
    $name = htmlspecialchars($_POST['name']);
    $email = htmlspecialchars($_POST['email']);
    $telephone = htmlspecialchars($_POST['telephone']);
    $message = htmlspecialchars($_POST['message']);

    $msg = <<<EOF
    <h3>Contact Form Submission ($stamp)</h3>
    <table>
    <tr>
    <td><strong>Name</strong></td>
    <td>$name</td>
    </tr>
    <tr>
    <td><strong>Email</strong></td>
    <td>$email</td>
    </tr>
    <tr>
    <td><strong>Tel</strong></td>
    <td>$telephone</td>
    </tr>
    <tr>
    <td><strong>Message</strong></td>
    <td>$message</td>
    </tr>
    </table>
    EOF;
    $headers = "From: postmaster@DOMAIN.co.uk\r\n";
    $headers .= "Content-Type: text/html\r\n";

    # Sent email 
    mail("EMAIL", "EMAIL TITLE", $msg, $headers);

    $SUCCESS = true;
    }
    }
    ?>

Форма работает нормально и с ошибками, когда это необходимо, а также завершает, чтобы сообщить мне, что форма была отправлена, но не отправляет на адрес электронной почты или любой другойя пытаюсь?Любые мысли будут приветствоваться по этому поводу.Вот код формы:

    <form action="contact" method="post" id="contact_form">
            <?php
                if($SUCCESS) {
            ?>
            <div class="alert alert-success" role="alert">
                <p>Thank you, the form has been successfully submitted.</p>
                <p>We will be in touch as soon as possible with regards to your enquiry.</p>
            </div>
            <?php
                }
                else {
            ?>
            <p>Please Note: Fields Marked with a <span class="req">*</span> are required</p>
            <div class="form-group">
                <label form="name">Name <span class="req">*</span> <?php if(in_array('name', $FORM_ERROR)) print '<div class="req"><i class="fa fa-exclamation-triangle"></i> This field below is required!</div>'; ?></label>
                <input class="form-control" type="text" name="name" tabindex="1" placeholder="Joe">
            </div>

            <div class="form-group">
                <label form="email">Email <span class="req">*</span> <?php if(in_array('email', $FORM_ERROR)) print '<div class="req"><i class="fa fa-exclamation-triangle"></i> This field below is required!</div>'; ?></label>
                <input class="form-control" type="text" name="email" tabindex="2" placeholder="joe.bloggs@example.com">
            </div>

            <div class="form-group">
                <label form="telephone">Telephone <span class="req">*</span> <?php if(in_array('telephone', $FORM_ERROR)) print '<div class="req"><i class="fa fa-exclamation-triangle"></i> This field below is required!</div>'; ?></label>
                <input class="form-control" type="text" name="telephone" tabindex="3" placeholder="1234567890">
            </div>

            <div class="form-group">
                <label form="message">Message <span class="req">*</span> <?php if(in_array('message', $FORM_ERROR)) print '<div class="req"><i class="fa fa-exclamation-triangle"></i> This field below is required!</div>'; ?></label>
                <textarea class="form-control" name="message" tabindex="4" col="25" row="12" placeholder="I would like to discuss..."></textarea>
            </div>

            <div class="form-check">
                <p>By submitting this form you understand and agree to the <a href="terms">terms</a> set out on this website.</p>
            </div>

            <p>
                <input type="hidden" name="gonzo" value="<?php echo(base64_encode(time())); ?>">
                <button name="submit" type="submit">Submit Form</button>
            </p>
            <?php
                }
            ?>
        </form>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...