[英]very simple php issue I need assistance with
I am sorry for what is a very basic question but I am very new to web design and I am just trying to get my form to work with php. 我很抱歉这是一个非常基本的问题,但是我对网页设计非常陌生,我只是想让我的表格与php一起使用。
The form fills in fine, and I receive an email but I don't get any body text. 表格填写正确,我收到一封电子邮件,但没有收到任何正文。 Instead of telling me what the message is I get this:
我没有告诉我消息是什么,而是得到了:
You have received a new message from the user fgafdfa. 您已经收到来自用户fgafdfa的新消息。 Here is the message: info@sodium3.com
这是消息:info@sodium3.com
As you can see the name is there (just typed gibberish) however the message is missing, instead I get my own email address appearing... 如您所见,名称在那里(只是键入乱码),但是消息丢失了,而是出现了我自己的电子邮件地址...
Here is the HTML for the form: 这是表单的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>
Here's the php: 这是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;
}
}
?>
Can anyone help? 有人可以帮忙吗?
Two errors: 两个错误:
See the missing name in the HTML for the textarea. 请参阅HTML中用于文本区域的缺少名称。 Corrected code:
更正的代码:
<textarea name="message" class="message"></textarea>
For the code you don't end your assignment to $email_body with a semicolon but appended to it by a dot. 对于代码,您不要以分号结束对$ email_body的赋值,而是在其后附加一个点。 Just a bit of luck that you didn't end up with a parse error.
幸运的是,您最终没有遇到解析错误。 Corrected code:
更正的代码:
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message";
$to = "info@sodium3.com";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.