简体   繁体   English

电子邮件中的联系表格不返回值

[英]contact form in email not returning values

I'm using CKEditor to create a html mailer in which a contact form is being sent to email. 我正在使用CKEditor创建一个html mailer ,其中将联系表发送到电子邮件。
The problem is, there is no value being received on submission of that form in email. 问题是,在电子邮件中提交该表格没有任何价值。

Contact Form in E-Mail (code) 电子邮件中的联系表格(代码)

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

Handler - mail.php 处理程序-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();
}

Screenshot from gmail's Message Text Garbled gmail的消息文本乱码的屏幕截图

消息文本乱码

if ($_POST['sub'] != '') {
    unset($_POST['sub']);

The above code means: if $_POST['sub'] is not an empty string, evaluate the statements below. 上面的代码意味着:如果$_POST['sub']不是一个空字符串,请评估以下语句。

If your form wasn't submitted, $_POST['sub']; 如果您的表单未提交,则$_POST['sub']; will be undefined and PHP will throw an error saying Undefined index . 将是未定义的,PHP将抛出错误消息Undefined index

I'd use isset() instead to properly check if the form was submitted or not. 我会使用isset()来正确检查表单是否已提交。

if (isset($_POST['sub'])) {
    # code ...
}

The following should work: 以下应该工作:

if (isset($_POST['sub'])) 
{
    unset($_POST['sub']);
    echo "Details received:<br>";
    foreach ($_POST as $val) 
    {
        echo "$val<br>";
    }
}

Your form is so simple and the $_POST loop, that it narrows down the error sources: 您的表单是如此简单,并且$_POST循环如此,它缩小了错误源的范围:

  • file base: scripts are not in the folder you expect 文件库:脚本不在您期望的文件夹中
  • CKEditor throws out HTML, either you strip it or,... have a look into the HTML sourcecode. CKEditor抛出HTML,或者剥离它,或者...查看HTML源代码。
  • Use print_r($_POST); 使用print_r($_POST); at the beginning of mail.php 在mail.php的开头
  • enable PHP debugging / error reporting: http://blog.flowl.info/2013/enable-display-php-errors/ 启用PHP调试/错误报告: http//blog.flowl.info/2013/enable-display-php-errors/
  • if you have javascript we cannot see in your sample code, remove it for further testing 如果您使用的是JavaScript,我们在示例代码中看不到,请将其删除以进行进一步测试

Update: 更新:

  • the CKEditor changes your inputs in a way that they are not anymore labeled by name attributes or renders the form in any other invalid form (don't think that's the problem) CKEditor会更改您的输入,不再用name属性标记它们,或以任何其他无效形式呈现该表单(不要认为这是问题所在)

I copied your sample code onto my webserver and it's working. 我将示例代码复制到了我的网络服务器上,并且可以正常工作。 You might have something in your real code that doesn't appear in the code above. 您的真实代码中可能有一些未出现在上面的代码中的东西。

Everything was fine except for the one, the form action attribute. 除了表单action属性外,其他一切都很好。
I'm submitting the form to http://techindiainfotech.com/mail.php but due to .htaccess it is being redirected to http://www.techindiainfotech.com/mail.php and that's why the request has been lost (I'm not getting the appropriate word here). 我正在将表单提交到http://techindiainfotech.com/mail.php但是由于.htaccess ,该表单已重定向到http://www.techindiainfotech.com/mail.php ,因此该请求已丢失 (我在这里没有得到合适的词)。

So, I just need to change in my action attribute which is, submit my form to http://www.techindiainfotech.com/mail.php not to http://techindiainfotech.com/mail.php . 因此,我只需要更改action属性即可,即将表单提交到http://www.techindiainfotech.com/mail.php而不是http://techindiainfotech.com/mail.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM