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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改