2

我遇到了与我在这里找到的其他人类似的问题,但无法解决我的联系表问题。这是我从电子邮件中的联系表中收到的全部内容。

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

3 回答 3

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>
于 2012-10-23T12:25:45.167 回答
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>'; 

并完成本教程

于 2012-10-23T12:24:03.967 回答
-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>";
于 2012-10-23T12:23:45.183 回答