0

I cant get the POST variables from this email form.

Any suggestions?

the part of the form in html file:

<form id="form_28" name="register" onsubmit="return validate_form_28(this)" action="sendmail.php" method="post" target="_blank" enctype="text/plain" style="margin:0;position:absolute;left:67px;top:297px;width:576px;height:291px;">
<input type="text" id="edit_23" name="email" value="" style="position:absolute; left:290px; top:93px; width:209px;">
</form>

the sendmail.php file

<?php
$email = $_POST['email'] ;


$email_body =  "Here is the message";
mail( "mymail@mysite.com", "title", $email_body, "From: $email" );
print "Congratulations your email has been sent";

?>

the validate_form_28 :

function validate_form_28( form )
{
    if( ltrim(rtrim(form.elements['email'].value,' '),' ')=="" ) { alert("you have to fill it"); form.elements['email'].focus(); return false; }
    if(!ValidateEmail(form.elements['email'].value)) { alert("not valid emailv"); form.elements['email'].focus(); return false; }
    return true;
}
  • 1
    Did you close the form tag somewhere ? – Scalpweb Sep 12 '13 at 13:35
  • 1
    So... What is the error? `$email` is not being used btw – k102 Sep 12 '13 at 13:35
  • Are you getting any errors? what happens when you do `var_dump($_POST);`? – NDM Sep 12 '13 at 13:36
  • @k102 `$email` is used in the From – DarkBee Sep 12 '13 at 13:37
  • can we see the "return validate_form_28(this)" ? maybe validate_form_28(this) is returning false or screwing the script up – aleation Sep 12 '13 at 13:38
  • function validate_form_28( form ) { if( ltrim(rtrim(form.elements['email'].value,' '),' ')=="" ) { alert("you have to fill this"); form.elements['email'].focus(); return false; } if(!ValidateEmail(form.elements['email'].value)) { alert("not email form"); form.elements['email'].focus(); return false; } return true; } – Aggelos SunDance Troulakis Sep 12 '13 at 13:39

3 Answers3

3

close your form.

</form>

And change:

mail( "mymail@mysite.com", "title", $email_body, "From: $email" );

to

mail( "mymail@mysite.com", "title", $email_body, "From: " . $email );
q0re
  • 1,401
  • 19
  • 32
  • 2
    FYI: `"From: $email"` and `"From: " . $email` do the exact same thing. – MisterBla Sep 12 '13 at 13:38
  • True. But it's still makes no difference in the code and how it functions. – MisterBla Sep 12 '13 at 13:40
  • Don't use `"` in php unless you need the contents to be parsed, otherwise use `'` (this way the PHP engine doesn't waste time looking at it). – sousdev Sep 12 '13 at 13:42
  • it would save 0.000000001 seconds or so not using the double quote xD even in a big application it wouldn't really be noticeable, I would say to be careful for injections sometimes, and use whatever is more comfortable, the time saved for a human writting/reading IS noticeable – aleation Sep 12 '13 at 13:46
0

Hello please remove the enctype="text/plain"

text/plain = Spaces are converted to "+" symbols, but no special characters are encoded

Chinmay235
  • 3,236
  • 8
  • 62
  • 93
0

I played around a bit and php and enctype="text/plain" is not compatible, take it out and it should work:

reference from another answer

Community
  • 1
  • 1
aleation
  • 4,796
  • 1
  • 21
  • 35