我很抱歉这是一个非常基本的问题,但我对网页设计非常陌生,我只是想让我的表单与 php 一起使用。
表格填写得很好,我收到了一封电子邮件,但没有收到任何正文。我没有告诉我信息是什么,而是得到了这个:
您收到了来自用户 fgafdfa 的新消息。这是消息:info@sodium3.com
如您所见,名称在那里(只是输入了乱码)但是消息丢失了,而是出现了我自己的电子邮件地址...
这是表单的 HTML:
<div id="form">
<form action="php/send_form_email.php" method="post" >
<span>Name</span>
<input type="text" name="name" class="name" />
<span>Email</span>
<input type="text" name="email" class="email"/>
<span>Message</span>
<textarea class="message"></textarea>
<input type="submit" name='submit' value="submit" class="submit">
</form>
</div>
这是php:
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = 'info@sodium3.com';//
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "info@sodium3.com";//
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header('Location: ../index.htm');
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;
}
}
?>
任何人都可以帮忙吗?