Reputation: 5959
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
Upvotes: 1
Views: 218
Reputation: 5959
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
.
Upvotes: -1
Reputation: 32360
Your form is so simple and the $_POST
loop, that it narrows down the error sources:
print_r($_POST);
at the beginning of mail.phpUpdate:
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.
Upvotes: 1
Reputation: 76676
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>";
}
}
Upvotes: 2