联系表格不能正常工作

时间:2013-05-10 17:17:26

标签: php html forms contact

我下载了一个网站模板,但是当我使用联系表单时,我似乎无法让联系表单正常工作,所有我收到的电子邮件都是:

<p>$usersname has contacted you from your site.</p>
            <h3>Their Message is as follows:</h3>
            <p>$usersmessage</p>
            <h5>Contact details</h5>
            <p>Phone Number: $usersphonenumber</p>
            <p>Email Address: $usersemail</p>

这是联系人html页面代码:

//// Start Contact Form ////
$('#ajaxcontactform').submit(function(){$('input[type=submit]', this).attr('disabled', 'disabled');});


$('#ajaxcontactform').submit(

    function parseResponse() {

        var usersname = $("#name");
        var usersemail = $("#email");
        var usersphonenumber = $("#phone");
        var usersmessage = $("#comment");
        var contactformid = $("#contactformid");
        var url = "contact.php";

            var emailReg = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
            var valid = emailReg.test(usersemail.val());

            if(!valid) {
                $("#contactwarning").html('<p class="rejectionalert"><span>Your email is not valid!</span></p>').slideDown().delay(2000).slideUp();
                $('input[type=submit]', $("#ajaxcontactform")).removeAttr('disabled');
                return false;
            }

          if (usersname.val() == "" || usersname.val() == "Please Insert Your Name") {                
               $("#contactwarning").html('<p class="rejectionalert"><span>Please Insert Your Name!</span></p>').slideDown().delay(2000).slideUp();
               $('input[type=submit]', $("#ajaxcontactform")).removeAttr('disabled');
               return false;               
          }
          if (usersemail.val() == "" || usersemail.val() == "Please Insert Your Email") {
               $("#contactwarning").html('<p class="rejectionalert"><span>Please Insert Your Email!</span></p>').slideDown().delay(2000).slideUp();
               $('input[type=submit]', $("#ajaxcontactform")).removeAttr('disabled');
               return false;
          }
          if (usersphonenumber.val() == "" || usersphonenumber.val() == "Please Insert Your Phone Number") {
               $("#contactwarning").html('<p class="rejectionalert"><span>Please Insert Your Phone Number!</span></p>').slideDown().delay(2000).slideUp();
               $('input[type=submit]', $("#ajaxcontactform")).removeAttr('disabled');
               return false;
          }
          if (usersmessage.val() == "" || usersmessage.val() == "Please Leave A Message") {
               $("#contactwarning").html('<p class="rejectionalert"><span>You forgot to leave a message!</span></p>').slideDown().delay(2000).slideUp();
               $('input[type=submit]', $("#ajaxcontactform")).removeAttr('disabled');
               return false;
          }

                $.post(url,{ usersname: usersname.val(), usersemail: usersemail.val(), usersphonenumber: usersphonenumber.val(), usersmessage: usersmessage.val(), contactformid: contactformid.val() } , function(data) {
                    $('#contactajax').html(data);
                    $('#contactajax').slideDown().delay(3000).slideUp();
                    $("#name").val('Please Insert Your Name');
                    $("#email").val('Please Insert Your Email');
                    $("#phone").val('Please Insert Your Phone Number');
                    $("#comment").val('Please Leave A Message');
                    $('input[type=submit]', $("#ajaxcontactform")).removeAttr('disabled');
                });

      }

  );
//// End Contact Form ////

这是php代码:

<?php

if(isset($_REQUEST['contactformid']) && $_REQUEST['contactformid'] == 1){

$youremail = "iremovedmyemail@live.com"; // Enter your email here!!

$usersname = $_POST["usersname"];
$usersemail = $_POST["usersemail"];
$usersphonenumber = $_POST["usersphonenumber"];
$usersmessage = $_POST["usersmessage"];
$subject = 'DZ-KEYS';
$message = '<p>$usersname has contacted you from your site.</p>
            <h3>Their Message is as follows:</h3>
            <p>$usersmessage</p>
            <h5>Contact details</h5>
            <p>Phone Number: $usersphonenumber</p>
            <p>Email Address: $usersemail</p>'; 

$headers = 'From:' . $usersemail . "\r\n";
mail($youremail, $subject, $message, $headers);

echo '<p>Thank you for your email, Please check your email for payment and delivery details!</p>';

} else {
echo '<p>Form could not be sent, please try again!</p>';
}

请帮帮我吧谢谢

2 个答案:

答案 0 :(得分:1)

$message声明周围的单引号更改为双引号:

$message = "<p>$usersname has contacted you from your site.</p>
        <h3>Their Message is as follows:</h3>
        <p>$usersmessage</p>
        <h5>Contact details</h5>
        <p>Phone Number: $usersphonenumber</p>
        <p>Email Address: $usersemail</p>"; 

单引号按原样使用字符串;双引号将在其中插入变量。

答案 1 :(得分:0)

你不知道PHP中单引号和双引号之间的区别。单引号不会解析变量而双引号会解析变量。因此,将PHP代码更改为双引号

$message = "<p>$usersname has contacted you from your site.</p>
        <h3>Their Message is as follows:</h3>
        <p>$usersmessage</p>
        <h5>Contact details</h5>
        <p>Phone Number: $usersphonenumber</p>
        <p>Email Address: $usersemail</p>";