【问题标题】:cannot get the POST variables from email form无法从电子邮件表单中获取 POST 变量
【发布时间】:2013-09-16 22:21:04
【问题描述】:

我无法从此电子邮件表单中获取 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;
}

【问题讨论】:

  • 您是否在某处关闭了表单标签?
  • 那么...错误是什么?顺便说一句,$email 没有被使用
  • 您是否遇到任何错误?当您执行var_dump($_POST); 时会发生什么?
  • @k102 $email 在 From 中使用
  • 我们能看到“return validate_form_28(this)”吗?也许 validate_form_28(this) 返回 false 或者把脚本搞砸了

标签: php forms email variables post


【解决方案1】:

我玩了一下,php和enctype="text/plain"不兼容,拿出来应该可以了:

reference from another answer

【讨论】:

    【解决方案2】:

    您好,请删除 enctype="text/plain"

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

    【讨论】:

      【解决方案3】:

      关闭您的表单。

      &lt;/form&gt;

      然后改变:

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

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

      【讨论】:

      • 仅供参考:"From: $email""From: " . $email 做同样的事情。
      • 是的。但它在代码及其功能方面仍然没有任何区别。
      • 不要在php中使用",除非你需要解析内容,否则使用'(这样PHP引擎不会浪费时间查看)。
      • 它会节省 0.000000001 秒左右 即使在大型应用程序中不使用双引号 xD 它也不会很明显,我会说有时要小心注射,并使用更舒适的东西,为人类书写/阅读节省的时间很明显
      猜你喜欢
      • 1970-01-01
      • 2018-07-24
      • 2017-05-01
      • 2016-12-01
      • 1970-01-01
      • 2019-04-10
      • 2018-03-06
      • 2018-07-24
      • 1970-01-01
      相关资源
      最近更新 更多