简体   繁体   中英

Bootstrap Contact Form with PHP, jQuery and AJAX

Hi having a problem with my contact form submission ,Its a Bootstrap template, its got JQuery validation, but there wasn't any PHP file for contact, i tried many different code for contact.php but it doesn't work, some of them showing "message sent successfully" but i didn't receive any email. i am using "Google Apps For Work" as my email client only. please help, really appreciate. (Sorry about my poor English.) Here the code for index.php`

      <form action="Contact.php" method="post" id="sky-form3" class="sky-form contact-style">
            <fieldset>
                <label>Name</label>
            <div class="row">
            <div class="col-md-7 margin-bottom-20 col-md-offset-0">
            <div>
                <input type="text" name="name" id="name" class="form-control">
            </div>
            </div>
            </div>
                <label>Email <span class="color-red">*</span></label>
            <div class="row">
            <div class="col-md-7 margin-bottom-20 col-md-offset-0">
            <div>
                <input type="text" name="email" id="email" class="form-control">
            </div>
            </div>
            </div>
                <label>Message</label>
            <div class="row">
            <div class="col-md-11 margin-bottom-20 col-md-offset-0">
            <div>
                <textarea rows="8" name="message" id="message" class="form-control"></textarea>
            </div>
            </div>
            </div>
               <p><button type="submit" class="btn-u btn-brd btn-brd-hover btn-u-dark">Send Message</button>
                          <button type="reset" class="btn-u btn-brd btn-brd-hover btn-u-dark">Reset Messages</button></p>
            </fieldset>

                            <div class="message">
                                <i class="rounded-x fa fa-check"></i>
                                <p>Your message was successfully sent!</p>
                            </div>
       </form>

Here the code for my contact.php file

    <?php
    error_reporting(E_ALL);
    ini_set('error_reporting', E_ALL);

    <?php


    function isEmail($email) {
        return filter_var($email, FILTER_VALIDATE_EMAIL);
    }

    if($_POST) {

        // Enter the email where you want to receive the message
        $emailTo = 'contact@vertigosourcing.com';

        $name = addslashes(trim($_POST['name']));
        $Email = addslashes(trim($_POST['email']));
        $message = addslashes(trim($_POST['message']));

        $array = array('nameMessage' => '', 'emailMessage' => '', 'messageMessage' => '');

        if(!isEmail($Email)) {
            $array['emailMessage'] = 'Invalid email!';
        }
        if($subject == '') {
            $array['nameMessage'] = 'Empty name!';
        }
        if($message == '') {
            $array['messageMessage'] = 'Empty message!';
        }
        if(isEmail($Email) && $name != '' && $message != '') {
            // Send email
            $headers = "From: " . $Email . " <" . $Email . ">" . "\r\n" . "Reply-To: " . $Email;
            mail($emailTo, $subject . " (contact request from)", $message, $headers);
        }

    }

    ?>

If you are using xampp/lamp/wamp, it won't work that easy, you have to activate some functions to send an email from a localhost, I think that's the problem because you have no mistakes in your code.

You can also try using @mail() instead of mail().

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