doujiyan0031 2012-08-12 19:29
浏览 8

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

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.

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. Here is the message: 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:

<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
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.
".
    "Here is the message:
 $message".

$to = "info@sodium3.com";//
$headers = "From: $email_from 
";
$headers .= "Reply-To: $visitor_email 
";
mail($to,$email_subject,$email_body,$headers);
header('Location: ../index.htm');
function IsInjected($str)
{
  $injections = array('(
+)',
              '(+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}

?> 

Can anyone help?

  • 写回答

1条回答 默认 最新

  • drhib62644 2012-08-12 19:36
    关注

    Two errors:

    See the missing name in the HTML for the textarea. 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. 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.
    ".
    "Here is the message:
     $message";
    
    $to = "info@sodium3.com";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看