-3

我正在尝试在以下位置设置联系表格:http: //48hrcodes.com/contact.php 但是我很难让它工作。这是我正在使用的代码:

<?php

/**
 * Change the email address to your own.
 *
 * $empty_fields_message and $thankyou_message can be changed
 * if you wish.
 */

// Change to your own email address
$your_email = "";

// This is what is displayed in the email subject line
// Change it if you want
$subject = "48hrcodes contact form";

// This is displayed if all the fields are not filled in
$empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>";

// This is displayed when the email has been sent
$thankyou_message = "<p>Thank you. Your message has been received.</p>";

// You do not need to edit below this line

$name = stripslashes($_POST['txtName']);
$email = stripslashes($_POST['txtEmail']);
$message = stripslashes($_POST['txtMessage']);

if (!isset($_POST['txtName'])) {

?>

<html lang="en">
<head>
   <link href='https://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
   <link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <link rel="stylesheet" href="css/style.css">
    <title>Free 48hr Xbox Live Gold Codes</title>
</head>
<body>
        <div id="content">
            <div id="c1">   <center>
            <header id="nav">
                <ul>
                    <li><a href="index.php">Home</a></li>  
                    <li><a href="getcode.php">Get Your Code</a></li>
                    <li><a href="testimonials.php">Testimonials and Proof</a></li>
                    <li><a href="faq.php">Frequently Asked Questions</a></li>
                    <li><a href="contact.php">Contact Us</a></li>  

                </ul>
            </header>
                <img class="clear" src="img/grab3.png" alt="header">

    </center>
    <form class="form" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">

        <p class="name">
            <input type="text" name="txtName" id="name" placeholder="John Doe" />
            <label for="name">Name</label>
        </p>

        <p class="email">
            <input type="text" name="txtEmail" id="email" placeholder="mail@example.com" />
            <label for="email">Email</label>
        </p>

        <p class="text">
            <textarea name="txtMessage" placeholder="Write something to us" /></textarea>
        </p>

        <p class="submit">
            <input type="submit" value="Send" />
        </p>
    </form>
    <div id="cttxt">
        <h3>
                Contact Us
        </h3>
        <p>
            Simply send us message using the contact form to the left and we will get back to you within 24-48 hours.
        </p>
    </div>
<center>
                <footer>
                    © 48hrcodes.com 2013 - site by ollie rex
                </footer>
                </div></center>
        </div>
</body>
</html>

<?php

}

elseif (empty($name) || empty($email) || empty($message)) {

    echo $empty_fields_message;

}

else {

    // Stop the form being used from an external URL
    // Get the referring URL
    $referer = $_SERVER['HTTP_REFERER'];
    // Get the URL of this page
    $this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
    // If the referring URL and the URL of this page don't match then
    // display a message and don't send the email.
    if ($referer != $this_url) {
        echo "You do not have permission to use this script from another URL, nice hacking attempt moron.";
        exit;
    }

    // The URLs matched so send the email
    mail($your_email, $subject, $message, "From: $name <$email>");

    // Display the thankyou message
    echo $thankyou_message;

}

?>

我在页面顶部收到错误,当我提交表单时,我收到的电子邮件只有消息框文本,没有名称或电子邮件。我已经尝试了所有我能想到的东西,但是除了 msg 变量之外它仍然无法发送任何东西。谢谢 :)

4

2 回答 2

0

改变

$name = stripslashes($_POST['txtName']);
$email = stripslashes($_POST['txtEmail']);
$message = stripslashes($_POST['txtMessage']);

至,

$name = (isset($_POST['txtName']))?stripslashes($_POST['txtName']):"";
$email = (isset($_POST['txtEmail']))?stripslashes($_POST['txtEmail']):"";
$message = (isset($_POST['txtMessage']))?stripslashes($_POST['txtMessage']):"";

避免顶部的警告。

于 2013-10-16T06:29:27.777 回答
0

利用

像这样

 if(isset($_POST['txtName'])
 {
    $name = stripslashes($_POST['txtName']);
 }
于 2013-10-16T06:28:58.263 回答