[英]contact form in email not returning values
我正在使用CKEditor
创建一个html mailer
,其中将联系表发送到电子邮件。
问题是,在电子邮件中提交该表格没有任何价值。
电子邮件中的联系表格(代码)
<form action="http://techindiainfotech.com/mail.php" method="post" name="test">
<p>Your Name: <input maxlength="75" name="name" size="75" type="text" /></p>
<p>Mobile Number: <input maxlength="10" name="mobile" size="10" type="text" /></p>
<p>Business Name: <input maxlength="100" name="business" size="100" type="text" /></p>
<p><input name="sub" type="submit" value="Submit" /></p>
</form>
处理程序-mail.php
if ($_POST['sub'] != '') {
unset($_POST['sub']);
echo "Details received:<br>";
foreach ($_POST as $val) {
echo "$val<br>";
}
} else {
header("Location: http://www.techindiainfotech.com/files/contact_us.php");
exit();
}
gmail的消息文本乱码的屏幕截图
if ($_POST['sub'] != '') {
unset($_POST['sub']);
上面的代码意味着:如果$_POST['sub']
不是一个空字符串,请评估以下语句。
如果您的表单未提交,则$_POST['sub'];
将是未定义的,PHP将抛出错误消息Undefined index
。
我会使用isset()
来正确检查表单是否已提交。
if (isset($_POST['sub'])) {
# code ...
}
以下应该工作:
if (isset($_POST['sub']))
{
unset($_POST['sub']);
echo "Details received:<br>";
foreach ($_POST as $val)
{
echo "$val<br>";
}
}
您的表单是如此简单,并且$_POST
循环如此,它缩小了错误源的范围:
print_r($_POST);
在mail.php的开头 更新:
name
属性标记它们,或以任何其他无效形式呈现该表单(不要认为这是问题所在) 我将示例代码复制到了我的网络服务器上,并且可以正常工作。 您的真实代码中可能有一些未出现在上面的代码中的东西。
除了表单action
属性外,其他一切都很好。
我正在将表单提交到http://techindiainfotech.com/mail.php
但是由于.htaccess
,该表单已重定向到http://www.techindiainfotech.com/mail.php
,因此该请求已丢失 (我在这里没有得到合适的词)。
因此,我只需要更改action
属性即可,即将表单提交到http://www.techindiainfotech.com/mail.php
而不是http://techindiainfotech.com/mail.php
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.