简体   繁体   English

使用 PHP、jQuery 和 AJAX 的 Bootstrap 联系表单

[英]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.嗨,我的联系表单提交有问题,它是一个 Bootstrap 模板,它得到了 JQuery 验证,但没有任何用于联系的 PHP 文件,我尝试了许多不同的 contact.php 代码,但它不起作用,其中一些显示“消息发送成功”,但我没有收到任何电子邮件。 i am using "Google Apps For Work" as my email client only.我仅使用“Google Apps For Work”作为我的电子邮件客户端。 please help, really appreciate.请帮助,真的很感激。 (Sorry about my poor English.) Here the code for index.php` (抱歉我的英语不好。)这里是 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这里是我的 contact.php 文件的代码

    <?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.如果您使用的是 xampp/lamp/wamp,它不会那么容易工作,您必须激活一些功能才能从本地主机发送电子邮件,我认为这是问题所在,因为您的代码没有错误。

You can also try using @mail() instead of mail().您也可以尝试使用@mail()而不是mail()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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