dongwei3172 2016-10-25 13:43
浏览 51
已采纳

PHP / js联系表单不发布表单数据

So I have a contact form on my website, which is partially working - The email is being sent to the intended email address, but the contents of the form are not included in the email. I do get the labels for the form inputs within the email, just not what the user inputs as their details.

I've examined and re-examined the variables and checked for typo's & syntax errors in the code but can't find any. PHP & js isn't my strong point so I'm hoping the kind & clever people here can point me in the right direction.

The HTML and js:

<form id="contact-form" name="contact-form" method="post" action="form-processing.php" style="float: right;">
    <span id="sprytextfield1">
        <label for="Name:">Name:</label>
        <br />
        <input name="Name" type="text" id="Name" tabindex="10" />
        <span class="textfieldRequiredMsg">*</span></span>
    <p><span id="sprytextfield2">
        <label for="Email:">Email:</label>
        <br />
        <input type="text" name="Email" id="Email" tabindex="20"/>
        <span class="textfieldInvalidFormatMsg">*</span></span>
    </p>
    <p><span id="sprytextfield3">
        <label for="PhoneNumber">Phone Number:</label>
        <br />
        <input type="text" name="PhoneNumber" id="PhoneNumber" tabindex="30"/>
        <span class="textfieldRequiredMsg">*</span></span>
        <p><span id="sprytextfield4">
        <label for="Message">Message:</label>
        <br />
        <textarea name="Message" cols="20" rows="10" id="Message" tabindex="40"></textarea>
        <span class="textfieldRequiredMsg">*</span></span>
        </p>
        <p>
            <input type="submit" name="Send" id="Send" value="Send" tabindex="50" />
        </p>
</form>
<script type="text/javascript">
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "Name");
    var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "Email", {
        isRequired: false
    });
    var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "PhoneNumber", {
        format: "phone_custom",
        pattern: "07234567890",
        validateOn: ["blur"]
    });
    var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "Message");
</script>

The PHP code:

<?php
   while (list($key, $val) = @each($_GET)) $GLOBALS[$key] = $val;
   while (list($key, $val) = @each($_POST)) $GLOBALS[$key] = $val;
   while (list($key, $val) = @each($_COOKIE)) $GLOBALS[$key] = $val;
   while (list($key, $val) = @each($_FILES)) $GLOBALS[$key] = $val;
   while (list($key, $val) = @each($_SESSION)) $GLOBALS[$key] = $val;

   /* Subject and Email Variables */

    $emailSubject = 'Website Contact Form';
    $webMaster = 'jonnylovesspam@gmail.com';

   /* Gathering Data Variables */

    $nameField = $_POST['Name'];
    $emailField = $_POST['Email'];
    $PhoneNumberField = $_POST['PhoneNumber'];
    $messageField = $_POST['Message'];


    $body = <<<EOD
   <br><hr><br>
   Name: $nameField <br>
   Email: $emailField <br>
   Phone Numbers: $PhoneNumberField <br>
   Message: $messageField <br>
   EOD;

    $headers = "From: $email
";
    $headers = "Content-type: text/html
";
    $success = mail($webMaster, $emailSubject, $body, $headers);

   /* Results Rendered as HTML */

    $theResults = <<<EOD
   <html>
   <head>
   <title></title>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><br />
   <meta HTTP-EQUIV="REFRESH" content="0; url=contact-message-sent">
   <style type="text/css">
   <!--
   body {
    background-color: #fffff;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-style: normal;
    line-height: normal;
    font-weight: normal;
    color: #000000;
    text-decoration: none;
   }
   -->
   </style>
   </head>
   <div align="left">
   Redirecting you...</div>
   </body>
   </html>
   EOD;
   echo "$theResults";

   ?>

You can see the form in action here: http://www.clearpandb.co.uk/contact

Thank you in advance for any pointers or help you can offer.

  • 写回答

1条回答 默认 最新

  • duan1443 2016-10-25 13:52
    关注

    Without your javascript it's working ?

    For my form i use HTML5 input type:

    HTML5 added several new input types:
    
    color
    date
    datetime
    datetime-local
    email
    month
    number
    range
    search
    tel
    time
    url
    

    Best regards,

    Florent.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要