1

I'm trying to make a form that takes name, email and message and sends it to me.

I have this form:

<form id="form" action="form.php" method="post" enctype="text/plain">

    Namn:<br>
    <input id="box1" type="text" name="name"><br>

    E-post:<br>
    <input id="box2" type="text" name="mail"><br>

    Meddelande:<br>
    <textarea id="messagebox" type="text" name="message"></textarea><br><br>

    <input id="submit" type="submit" value="Send">

</form>

This is my form.php:

<?PHP
$name = $_POST["name"];
$mail = $_POST["mail"];
$message = $_POST["message"];

mail("name@example.com", "Message from $name", $message); 

?>

I do receive an email but it does not have the subject or message. It says the mail is empty. If I replace the variables with text in the mail function I get that correct text, which must means the variables don't get their values.

Is this the case and how should I solve it? If not, what else could be wrong?

Wilhelm Michaelsen
  • 665
  • 14
  • 32
  • echo $name, $mail and $message in form.php and check whether you are getting the values entered.. – Lal Aug 08 '14 at 18:58
  • Put `var_dump($_POST);` or `print_r($_POST);` at the top of your PHP file to see what's coming across. – j08691 Aug 08 '14 at 19:04
  • 2
    PHP doesn't support the text/plain encoding. http://stackoverflow.com/questions/7628249/method-post-enctype-text-plain-are-not-compatible – Knyri Aug 08 '14 at 19:06

1 Answers1

1

The problem is that you have set the enctype attribute to "text/plain", which means that only spaces are converted to + characters, and no special characters are encoded. This means that when PHP receives the submitted form, it will not put any of your form parameters in the $_POST auto global array, because they are being received in an unexpected format. To fix this, simply remove the enctype attribute entirely, or replace it with "application/x-www-form-urlencoded".

Treker
  • 386
  • 2
  • 9