doulao3905 2015-02-18 18:31
浏览 56
已采纳

无法获取php输出表单

I'm trying to make a functional form with php. Initially i made an "index.html" file and another file called send.php. But it did't work. I also tried to insert "echo" in send.php and it worked! So i converted index.html into index.php and i put the php code inside of it before the body closing tag the tag , but it didn't work! So i realized that the error was in the code, but i copied these lines form the internet and i don't know php very well. Can someone help me? This is the code:

The name="" of the fields are correct, I checked.

<?php 
$name = ($_POST['name'];
$mail = ($_POST['mail'];
$budjet = ($_POST['budjet'];
$society = ($_POST['society'];
$message = ($_POST['message'];
$error = "Message sending failed";
$errorMessage = "Sorry your message can not be sent.";

//Validate first
if(empty($name)||empty($mail)||empty($budjet)||empty($society)||empty($message)) 
{
    echo "Please fill al the fields";
    header('Location: index.html');
}
//validate against any email injection attempts
if(IsInjected($email))
{
    echo "Bad email value";
    header('Location: index.html');
}

$msg = "Name : $name 
"; 
$msg = "Mail : $mail 
";
$msg = "Budjet: $budjet 
";
$msg = "Society: $society 
";
$msg = "Message : ".stripslashes($_POST['message'])."

";
$msg = "User information 
"; 
$msg = "User IP : ".$_SERVER["REMOTE_ADDR"]."
"; 
$msg = "Browser info : ".$_SERVER["HTTP_USER_AGENT"]."
"; 
$msg = "User come from : ".$_SERVER["SERVER_NAME"];

$recipient = "myemail@mail.com"; // Change the recipient email adress to your adrees  
$sujet =  "Mail da Contact di Hindeto";
$mailheaders = "From: $email
Reply-To: $email
Return-Path: $email
";

if (!$error){

        $sending = mail($recipient, $sujet, $msg, $mailheaders); 

        if ($sending) {
                // If the message is sent we output a string to use it 
                echo "Sent"; 
            } else {
                // Display Error Message
                echo $errorMessage; 
            }
    } else {
        echo $error; // Display Error Message
    }


// Function to validate against any email injection attempts
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;
  }
}
?>
  • 写回答

2条回答 默认 最新

  • doufan9805 2015-02-18 18:35
    关注

    you have syntax error at first 5 lines remove ( before $_POST

    $name = $_POST['name'];
    $mail = $_POST['mail'];
    $budjet = $_POST['budjet'];
    $society = $_POST['society'];
    $message = $_POST['message'];
    

    and after header('Location: index.html'); and header('Location: index.html'); print exit();

    header('Location: index.html');
     exit();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)