Question

I'm using CKEditor to create a html mailer in which a contact form is being sent to email.
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

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

Message Text Garbled

Was it helpful?

Solution 3

Everything was fine except for the one, the form action attribute.
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).

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.

OTHER TIPS

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

The above code means: if $_POST['sub'] is not an empty string, evaluate the statements below.

If your form wasn't submitted, $_POST['sub']; will be undefined and PHP will throw an error saying Undefined index.

I'd use isset() instead to properly check if the form was submitted or not.

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:

  • 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.
  • Use print_r($_POST); at the beginning of mail.php
  • enable PHP debugging / error reporting: 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

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)

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top