非常简单的 php 问题,我需要帮助


very simple php issue I need assistance with

我很抱歉这是一个非常基本的问题,但我对网页设计很陌生,我只是想让我的表单与 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;
  }
}
?> 

谁能帮忙?

两个错误:

请参阅文本区域中 HTML 中缺少的名称。更正的代码:

<textarea name="message" class="message"></textarea>

对于代码,您不会用分号结束对 $email_body 的赋值,而是用点附加一个点。只是运气好,您最终没有出现解析错误。更正的代码:

$email_body = "You have received a new message from the user $name.'n".
"Here is the message:'n $message";
$to = "info@sodium3.com";