I created a contact form to send directly to my email. It sends but not picks up information from the text inputs

0

Hello.

I created a contact form on my page. Along with this contact form, I created a document in PHP so that it sends to my email the information that the user typed in the text inputs of the contact form. I receive the email, but I do not receive the information that the user entered. Could anyone tell me why?

Thank you.

<form action="Send2.php" method="post" enctype="text/plain">
<input type="text" name="nome" id="nome" size="20">
<br/>
<br/>
<input type="text" name="email" id="email" size="20">
<br/>
<br/>

<input type="submit" value="Enviar" >

</form>

<?php

$name= $_POST['nome'];
$email= $_POST['email'];

echo $name;
echo $email;
?>

<?php

$to = "[email protected]";
$subject = "Contato Site - ManaSoft";
$message = "Name: ".$name. "<br/> E-mail: ".$email. "<br/>";
$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/html; charset=iso-8859-1\n";
$header .= "From: $email\n";

mail($to, $subject, $message, $header);

?>
    
asked by anonymous 01.02.2018 / 03:25

3 answers

0

Try this:

<!doctype html>
<html>

<head>
   <meta charset="UTF-8">
</head>

<body>
<form method="POST" action="seuArquivo.php">

<input type="text" name="nome" id="nome" size="20">
<br/>
<br/>
<input type="text" name="email" id="email" size="20">
<br/>
<br/>

<input type="submit" value="Enviar" >

</form>

</body>

<?php

$name= $_POST['nome'];
$email= $_POST['email'];

echo $name;
echo $email;

$to = "[email protected]";
$subject = "Contato Site - ManaSoft";
$message = "Name: ".$name. "<br/> E-mail: ".$email. "<br/>";
$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/html; charset=iso-8859-1\n";
$header .= "From: $email\n";

mail($to, $subject, $message, $header);

?>

</html>
    
01.02.2018 / 03:48
0

PHP does not populate POST or GET with enctype="text/plain" . The values of enctype can be application/x-www-form-urlencoded (default) or multipart/form-data (used to send files).

In your case, you do not need to specify the enctype that will already be the default type ( application/x-www-form-urlencoded ):

<form action="Send2.php" method="post">
    
01.02.2018 / 04:46
0

The action parameter of the <form> tag can only contain a relative URL action="meu-ficheiro-local.php" or an absolute action="http://www.exemplo.com/exemplo.php" URL. In this case what I think is that the declaration in php is in the same file as <form> , but in turn the form sends its content to the file Send2.php . <form action="Send2.php" method="post">

In my opinion, the best thing to do in this case is to use the $_SERVER["PHP_SELF"] server variable, which returns the name of the file that is currently running. We should use this global variable within the htmlspecialchars() method to avoid exploiting its vulnerabilities, below is an example implementation.

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" >

Another issue is the use of a control structure, because in this way the script will send two emails, one when it is started and another when the form is submitted. To fix this, we can use another server variable $_SERVER["REQUEST_METHOD"] that returns the type of method with which the file was requested, the two most commonly used methods are GET and POST , below I leave an example of how would be the structure.

<?php

    //Só envia o email caso o tipo da requisição seja do tipo 'POST'  
    if ($_SERVER["REQUEST_METHOD"] == "POST") {

      $name= $_POST['nome'];
      $email= $_POST['email'];

      echo $name;
      echo $email;

      $to = "[email protected]";
      $subject = "Contato Site - ManaSoft";
      $message = "Name: ".$name. "<br/> E-mail: ".$email. "<br/>";
      $header = "MIME-Version: 1.0\n";
      $header .= "Content-type: text/html; charset=iso-8859-1\n";
      $header .= "From: $email\n";

      mail($to, $subject, $message, $header);
    }
?>
    
01.02.2018 / 05:00