2013-10-16 44 views
-3

我想設置一個聯繫表格: http://48hrcodes.com/contact.php 但是我很難得到它的工作。 這裏是我使用的代碼: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="[email protected]" /> 
      <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; 

} 

?> 

我在頁面頂部出現錯誤,以及當我提交表單,電子郵件我只得到了這些URL文本,而不是姓名或電子郵件。 我已經嘗試了所有我能想到的,但它仍然無法發送除msg變量之外的任何內容。 謝謝:)

+0

你在頁面頂部得到的錯誤消息是什麼? – vbrmnd

+0

你可以訪問鏈接,但我也會在這裏發佈:注意:未定義的索引:txtName在/home/nulledwa/domains/48hrcodes.com/public_html/contact.php在25行注意:未定義索引:txtEmail在/ home /第26行的nulledwa/domains/48hrcodes.com/public_html/contact.php注意:未定義的索引:txtMessage在/home/nulledwa/domains/48hrcodes.com/public_html/contact.php在第27行謝謝 – ollierexx

+0

在此問題中添加代碼不只是一個pastbin,這將不勝感激。同時添加你遇到的這個問題的錯誤。那我們可以幫助你更好。 – mariomario

回答

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']):""; 

爲了避免在頂部的警告。

+0

警告仍然顯示?我加入了完全相同的地方。 – ollierexx

+0

@ollierexx更新了答案。 – vbrmnd

+0

謝謝,這工作:)任何想法,爲什麼其他變量沒有得到電子郵件? – ollierexx

0

使用

這樣

if(isset($_POST['txtName']) 
{ 
    $name = stripslashes($_POST['txtName']); 
}