2014-02-11 49 views
0

我已經瀏覽了很多不同網站上的帖子,包括這一個,仍然無法弄清楚發生了什麼事。首先,我沒有收到一封電子郵件到我想要的電子郵件中放入PHP文件。我的重定向也不是我所指定的html頁面,而是轉到PHP文件,這個文件在查看時只是一個空白頁面。HTML和PHP表單正常工作

HTML

<form action="result.php" method="post" enctype="text/plain" name="form1"> 
<table width="500" border="0" align="center" cellspacing="0"> 
<tr> 
<td>Name:</td> 
<td><input name="name" type="text" size="30" maxlength="30"></td> 
</tr> 
<tr> 
<td>Email:</td> 
<td><input name="email" type="text" size="30" maxlength="50" placeholder="[email protected]"></td> 
</tr> 
<tr> 
<td>Phone:</td> 
<td><input name="phone" type="text" size="30" maxlength="20"></td> 
</tr> 
<tr> 
<td>Inquiry type:</td> 
<td><select name="type"> 
<option value="1" selected>Residential Inquiry</option> 
<option value="2">Small Business Inquiry</option> 
<option value="3">Web Design Inquiry</option> 
<option value="4">Existing Client Inquiry</option> 
</select></td> 
</tr> 
<tr> 
<td>Message:</td> 
<td><textarea name="message" cols="45" rows="5"></textarea></td> 
</tr> 
<tr> 
<td>&nbsp;</td> 
<td><input name="submit" type="submit" value="Submit" /> 
<input name="reset" type="reset" value="Reset" /></td> 
</tr> 
</table> 
</form> 

PHP

<?php 

$name = $_POST['name']; 
$visitor_email = $_POST['email']; 
$phone = $_POST['phone']; 
$subject = $_POST['type']; 
$message = $_POST['message']; 

if(IsInjected($visitor_email)) 
{ 
echo "Bad email value!"; 
exit; 
} 

$email_from = '[email protected]';//<== update the email address 
$email_subject = "$subject"; 
$email_body = "$message" + "phone"; 

$to = "[email protected]"; //<== update the email address 
$headers = "From: $email_from \r\n"; 
$headers = "Reply-To: $visitor_email \r\n"; 
//Send the email! 
mail($to,$email_subject,$email_body,$headers); 
//done. redirect to thank-you page. 
header('Location: http://www.example.com/example.html'); 


// Function to validate against any email injection attempts 
function IsInjected($str) 
{ 
$injections = array('(\n+)', 
'(\r+)', 
'(\t+)', 
'(%0A+)', 
'(%0D+)', 
'(%08+)', 
'(%09+)' 
); 
$inject = join('|', $injections); 
$inject = "/$inject/i"; 
if(preg_match($inject,$str)) 
{ 
return true; 
} 
else 
{ 
return false; 
} 
} 

?> 
+0

PHP不處理'文/ plain'。 –

回答

2

刪除此

​​ 從表單標籤

並添加此

<form action="result.php" method="post" name="form1"> 
+0

我仍然收到相同的錯誤,沒有電子郵件進來,它重定向到空白的PHP頁面。 – deceptionx

+0

那是你需要在result.php上打開錯誤並檢查錯誤的問題的一部分。 –

+0

我收到了我想要的電子郵件。重定向是最後一件工作不正確。 – deceptionx

1

您已經設置的形式編碼,以「人類可讀的調試模式」

enctype="text/plain" 

參見the specification:使用純文本/格式

有效載荷旨在是人類可讀的。 由於格式不明確(例如,沒有辦法在值的末尾區分換行符中的文字換行符),因此它們不能可靠地被計算機解釋。

不這樣做。取出屬性。

+0

我刪除了部分表單代碼。我仍然沒有收到任何電子郵件,並提交仍然重定向到空白result.php頁面,而不是我希望它的HTML頁面。我確定它也是正確的電子郵件多次。 – deceptionx

+0

查看您的服務器日誌。 PHP會報告任何錯誤嗎? – Quentin

0

可能需要拼接的頭信息:

$headers = "From: $email_from \r\n"; 
$headers .= "Reply-To: $visitor_email \r\n"; 
+0

我最終將它更改爲$ headers =「Reply-To:」。 $ visitor_email。爲 「\ r \ n」 個;並刪除另一個。 – deceptionx