我已經瀏覽了很多不同網站上的帖子,包括這一個,仍然無法弄清楚發生了什麼事。首先,我沒有收到一封電子郵件到我想要的電子郵件中放入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> </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;
}
}
?>
PHP不處理'文/ plain'。 –