无法从电子邮件表单中获取POST变量

时间:2013-09-12 13:34:35

标签: php forms email variables post

我无法从此电子邮件表单中获取POST变量。

有什么建议吗?

html文件中表单的一部分:

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

sendmail.php文件

<?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";

?>

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;
}

3 个答案:

答案 0 :(得分:3)

关闭你的表格。

</form>

并改变:

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

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

答案 1 :(得分:0)

您好请删除 enctype =“text / plain”

text / plain =空格转换为“+”符号,但不会编码特殊字符

答案 2 :(得分:0)

我玩了一下并且php和enctype="text/plain"不兼容,把它取出来它应该有效:

reference from another answer