我正在處理客戶端的聯繫表單,但由於某種原因,它沒有傳遞正確的變量。看看一些代碼,看看你是否能找到任何東西......我沒有想法。
contact.php
<form name="contact" method="post" action="thankyou.php">
<input type="hidden" name="flag" value="1" />
<table style="width: 500px;">
<tr>
<td><p><em><strong>Your email: *</strong></em></p></td>
<td><input name="email" type="text" size="30" /></td>
</tr>
<tr>
<td><p><em><strong>Subject:</strong></em></p></td>
<td><input name="subject" type="text" size="30" /></td>
</tr>
<tr>
<td><p><em><strong>Message: *</strong></em></p></td>
<td><textarea name="message" type="text" rows="7" cols="30"></textarea></td>
</tr>
<tr>
<td></td>
<td><div style="height:5px"></div></td>
</tr>
<tr>
<td colspan="2"><p>To help protect us against spam, please type <em>storage</em> below: *</p></td>
</tr>
<tr>
<td></td>
<td><input name="spam_test" maxlength="7" type="text" size="5" /></td>
</tr>
<tr>
<td></td>
<td><div style="height:5px"></div></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Send" />
<input type="reset" value="Reset" /></td>
</tr>
</table>
</form>
thankyou.php
<?php
$user_message = "";
if(isset($_POST['flag'])) {
$flag = "true";
if (strlen($_POST['message']) > 20000) {
$user_message = "Message too long, please shorten.";
$flag = "false";
}
if (strlen($_POST['message']) < 1) {
$user_message = "Message cannot be blank.";
$flag = "false";
}
if (strlen($_POST['subject']) > 5000) {
$user_message = "Subject too long, please shorten.";
$flag = "false";
}
if(!check_email($_POST['email'])) {
$user_message = "Invalid email address, please re-enter.";
$flag = "false";
}
if($_POST['spam_test'] != "storage") {
$user_message = "Please fill out the spam prevention field correctly.";
$flag = "false";
}
if($flag == "true") {
$user_message = "Your message has been sent. We will be in touch shortly.";
$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: " . $_POST['email'] . "\r\n";
$headers .= "Return-Path: " . $_POST['email'] . "\r\n";
$msg = "This is an automatically generated email from the Contact Form on mrstore.co.uk - below is a message from a user:\n\n";
$msg .= "User's email: " . $_POST['email'] . "\n\n";
$msg .= "Message: " . $_POST['message'] . "\n";
$subject = "Contact Us Message From Website: " . $_POST['subject'];
if(!mail('[email protected]', $subject, $msg, $headers)) {
$user_message = "Error Sending Email, please try again later.";
}
}
}
?>
<h2><?php echo $user_message; ?></h2>
EDIT 以下是的print_r的結果($ _ POST)...領域元素被攜帶到三江源.php,但沒有正確處理(例如,垃圾郵件密鑰在示例中是錯誤的),並且郵件未被髮送。
Array ([flag] => true [email] => [email protected] [subject] => This is the subject [message] => hello moto [spam_test] => blah)
EDIT 2 我覺得我越來越接近計算出來,但現在它的投擲500服務器錯誤。我還創建了變量$電子郵件中thankyou.php並指出,$ _ POST [「郵件」])這裏的功能,check_email ...
function check_email($email) {
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}
最後編輯...我希望! if語句我已經收窄,這...
if($flag == "true") {
$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: " . $_POST['email'] . "\r\n";
$headers .= "Return-Path: " . $_POST['email'] . "\r\n";
$msg = "This is an automatically generated email from the Contact Form on mrstore.co.uk - below is a message from a user:\n\n";
$msg .= "User's email: " . $_POST['email'] . "\n\n";
$msg .= "Message: " . $_POST['message'] . "\n";
$subject = "Contact Us Message From Website: " . $_POST['subject'];
mail("[email protected]", $subject, $msg, $headers);
$user_message = "Your message has been sent. We will be in touch shortly."; }
它是如何「沒有攜帶變量」?你在期待什麼?你有什麼? – 2012-03-29 18:55:34
當我回顯$ _POST時,所有出現的是一個空數組。不知何故,表單中的變量不會被轉移。不知道爲什麼。這個方法是post ...有一個thankyou.php的動作...所有的標籤都關閉了..這是否與它在開發子域的事實有關? – MBY 2012-03-29 18:55:36
事實上,當表單提交給thankyou.php時,$ _POST是一個空數組。沒有表單元素被轉交進行處理。 – MBY 2012-03-29 18:56:18