【问题标题】:PHP Simple Contact Form Not Working Not Sure WHYPHP 简单联系表不起作用 不确定 为什么
【发布时间】:2013-05-20 11:26:46
【问题描述】:

似乎无法理解为什么此联系表单不起作用任何指针都会很棒...想通过 ajax 发送表单并将要发送的数据序列化.. 只是似乎不起作用..希望有人可以帮忙

html

<form method="post" action="" id="contact_form">
  <div class="row">
                <div class="large-6 columns">
                    <label for="contact_name">Your Name</label>
                    <input type="text" placeholder="" id="contact_name" name="contact_name" class="required">
                </div>
                <div class="large-6 columns">
                    <label for="contact_email">Your Email</label>
                    <input type="text" placeholder="" id="contact_email" name="contact_email" class="required">
                </div>
            </div>
            <div class="row">
                <div class="large-6 columns">
                    <label for="contact_company">Company Name or Organization</label>
                    <input type="text" placeholder="" id="contact_company" name="contact_company" class="required">
                </div>
                <div class="large-6 columns">
                    <label for="contact_phone">Phone Number</label>
                    <input type="text" placeholder="" id="contact_phone" name="contact_phone" class="required">
                </div>
            </div>
            <div class="row">
                <div class="large-12 columns">
                    <label for="contact_message">Your Message</label>
                    <textarea rows="4" placeholder="" id="contact_message" name="contact_message" class="required"></textarea>
                </div>
            </div>
            <div class="row">
                <div class="large-12 columns">
                    <input type="submit" name="contact_submit" id="contact_submit" value="SEND MESSAGE" class="button">
                </div>
            </div>

        </form>

        <p class="success" style="display:none">Your message has been 
               sent successfully.</p>


邮件.php

    <?php 

$name =  $POST['contact_name'] ;
$email = $POST['contact_email'] ;
$company = $_POST['contact_company'] ;
$number = $_POST['contact_phone'] ;
$message = $POST['contact_message'] ;

mail("allycallow@hotmail.com", $name, $company, $number, $message, "From:" . $email);
    ?>

js文件

$(document).ready(function() {

    $('#contact_form').validate({

    submitHandler: function(form) {
      //do submit

          var dataString = $("this").serialize();
          //alert (dataString);return false;
          $.ajax({
            type: "POST",
            url: "php/mail.php",
            data: dataString,
            success: function() {
             $('.success').fadeIn(1000);
              $("input[type=text], textarea").val("");
              $('.success').fadeToggle(1000);
        }
      });
          return false;
    }
 });
});

【问题讨论】:

  • $POST 更改为 $_POST 并请说明您已经尝试解决的问题
  • 您好,首先需要进行基本调试。究竟是什么在哪里不起作用?测试输出在 JavaScript 和 PHP 中向您展示了什么 - 是否提出过请求?数据是否曾经传输过?
  • 它现在可以工作了,但它似乎没有发送任何数据并被放入我的垃圾邮件中......奇怪......

标签: php ajax forms contact


【解决方案1】:

你犯了一些错误。使用以下代码:

<?php 
$name =  $_POST['contact_name'] ;
$email = $_POST['contact_email'] ;
$company = $_POST['contact_company'] ;
$number = $_POST['contact_phone'] ;
$message = $_POST['contact_message'] ;

//modify the mail function
mail("allycallow@hotmail.com", $name.$company, $message, "From:" . $email);
?>

在 JS 中更改以下内容:

 success: function(returnData) {
      $('.success').fadeIn(1000);
      $("input[type=text], textarea").val("");
      //$('.success').fadeToggle(1000);

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-03
    • 2018-10-27
    • 2014-03-31
    • 1970-01-01
    相关资源
    最近更新 更多