联系表格没有退回任何内容?

时间:2012-10-23 12:18:56

标签: php 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>
<?php
   if(isset($_REQUEST['contactformid']) && $_REQUEST['contactformid'] == 1){
    $youremail = "garybrowntown@gmail.com";
    $usersname = $_POST["usersname"];
    $usersemail = $_POST["usersemail"];
    $usersphonenumber = $_POST["usersphonenumber"];
    $usersmessage = $_POST["usersmessage"];
    $subject = 'Message From Your Contact Form';
    $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, a member of our staff will contact you soon regarding your email!</p>';

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

?>

    <div class="boxes-full">

            <div class="contacttitle">

                <h2>Contact Mogul</h2>

            </div>

            <div class="boxes-padding fullpadding">

            <div id="contactwarning"></div>
            <div id="contactajax"></div>

            <form action="javascript:parseResponse();" method="post" name="ajaxcontactform" id="ajaxcontactform">

                <div class="contacttextarea">
                    <input name="contactformid" id="contactformid" type="hidden" value="1" />

                    <fieldset>
                        <textarea name="comment" id="comment" cols="5" rows="5" class="contacttextarea"onfocus="if (this.value == 'Please Leave A Message') {this.value = '';}">Please Leave A Message</textarea>
                    </fieldset>

                </div>

                <div class="contacttextboxes">

                    <fieldset>
                        <input id="name" name="name" type="text" class="contacttextform" onfocus="if (this.value == 'Please Insert Your Name') {this.value = '';}"value="Please Insert Your Name">
                    </fieldset>

                    <fieldset>
                        <input id="phone" name="phone" type="text" class="contacttextform" onfocus="if (this.value == 'Please Insert Your Phone Number') {this.value = '';}"value="Please Insert Your Phone Number">
                    </fieldset>

                    <fieldset>
                        <input id="email" name="email" type="text" class="contacttextform" onfocus="if (this.value == 'Please Insert Your Email') {this.value = '';}"value="Please Insert Your Email">
                    </fieldset>

                    <fieldset>
                        <input name="send" type="submit" class="contactformbutton" value="Send">
                    </fieldset>

                </div>

            </form>

            </div>

            <span class="box-arrow"></span>

        </div>

3 个答案:

答案 0 :(得分:1)

也许如果你将回复消息包装在 php TAGS 中,它将正常工作。 看看:

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

像这样使用:

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

答案 1 :(得分:0)

那是因为你使用单引号并且没有评估变量,试试这个代码它会起作用。

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

并完成此tutorial

答案 2 :(得分:-1)

如果要在字符串中包含变量,则必须使用双引号,因此请替换以下代码:

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

这个:

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