简体   繁体   中英

Contact form issues on HTML5 theme

Forgive me, as this probably has an extremely simple solution and I'm just very inexperienced.

I am using the Massive HTML5 theme and cannot get my contact form to work. I thought I followed the directions, but still nothing happens when I click SUBMIT.

 <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <form method="post" action="contact-us.php" id="form" role="form" class="contact-comments"> <div class="row"> <div class="col-md-6 "> <div class="form-group"> <!-- Name --> <input type="text" name="name" id="name" class=" form-control" placeholder="Name *" maxlength="100" required=""> </div> <div class="form-group"> <!-- Email --> <input type="email" name="email" id="email" class=" form-control" placeholder="Email *" maxlength="100" required=""> </div> <div class="form-group"> <!-- phone --> <input type="text" name="phone" id="phone" class=" form-control" placeholder="Phone" maxlength="100"> </div> </div> <div class="col-md-6 form-group"> <div class="form-group"> <!-- Comment --> <textarea name="text" id="text" class="cmnt-text form-control" placeholder="Comment" maxlength="400"></textarea> </div> <div class="form-group full-width"> <button type="submit" class="btn btn-small btn-dark-solid "> Send Message </button> </div> </div> </div> </form> 

<?php
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($_POST['name']) && isset($_POST['email']) && isset($_POST['subject']) && isset($_POST['comments']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {

    // detect & prevent header injections
    $mailTest = "/(content-type|bcc:|cc:|to:)/i";
    foreach ( $_POST as $key => $val ) {
        if ( preg_match( $mailTest, $val ) ) {
            exit;
        }
    }

    $headers = 'From: ' . $_POST["name"] . '<' . $_POST["email"] . '>' . "\r\n" .
    'Reply-To: ' . $_POST["email"] . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    $success = mail( "myemail@mail.com", $_POST['subject'], $_POST['comments'], $headers );
    //  Replace with your email

    if ($success) {
        ?>
        <div style="color:#3c763d;padding:30px;text-align:center">
            <strong>Success!</strong> Message has been sent successfully.
        </div>
        <?php
    }
}

Of course, I changed myemail@mail.com to my address.

Thanks for the help.

mail() function Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

please refer Documentation .

you can also other php library to send mail like phpmailer.

 if ( isset($_POST['name']) && isset($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) 

从if条件中删除&& isset($ _ POST ['subject'])&& isset($ _ POST ['comments']),因为它们都不是HTML表单中带有名称主题和注释的输入。

If you're on Windows then use XAMPP , if on Mac use MAMP .

PHP contact form will not work if don't have any server side connection. I had the similar problem as you have now. For more information please check my post Configuration issue with PHP contact form .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM