0

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

<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>';
}

请帮帮我谢谢

4

2 回答 2

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>"; 

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

于 2013-05-10T17:19:05.407 回答
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>"; 
于 2013-05-10T17:22:41.303 回答