繁体   English   中英

非常简单的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";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM