View Full Version : Problems with php contact form
celicasaur
September 27th, 2008, 08:16 PM
Hi guys, right I followed the php contact form to what I believe to be an almost exact replica. The form text is in a htm file and the php code is in a file called mailer.php
When the form is submitted, I get an error screen that says all of this:
"Notice: Undefined index: radio in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 9
Notice: Undefined index: drop_down in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 10
Notice: Undefined index: check in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 12
Warning: Invalid argument supplied for foreach() in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 12
Notice: Undefined variable: check_msg in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 16
Data has been submitted to mr-celica@hotmail.co.uk!
Warning: mail() [function.mail (http://www.bluechipmc.co.uk/function.mail)]: "sendmail_from" not set in php.ini or custom "From:" header missing in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 19"
Here is a link to the page itself so you can see for yourself:
http://www.bluechipmc.co.uk/message.htm
Just enter anything in the fields and click submit to see the error page.
Please can somebody here help? I've tried a search on the forum, but most of the threads seem to be about making this work in a flash file.
Cheers, Ron
tfg
September 29th, 2008, 07:26 AM
firstly, before the mail() command you need to include.
ini_set("sendmail_from", "you@yourdomain.com");
celicasaur
September 29th, 2008, 08:11 AM
Hi, I tried looking for the mail () commant in my code, but couldn't find it...
Here's what my form code is like
<div id="formhouse">
<form method="POST" action="mailer.php">
Name<BR /><input type="text" name="name" size="19"><br>
<br>
Email<BR /><input type="text" name="email" size="19"><br>
<br>
Message<BR /><textarea rows="9" name="message" cols="30"></textarea>
<br>
<br>
<input type="submit" value="Submit" name="submit">
</form>
</div>
...and here is what the mailer.php file looks like:
<?php
if(isset($_POST['submit'])) {
$to = "mr-celica@hotmail.co.uk";
$subject = "Bluechip website query";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$option = $_POST['radio'];
$dropdown = $_POST['drop_down'];
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
$body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "Please enter all fields before submitting your query";
}
?>
:(
tfg
September 29th, 2008, 09:20 AM
the mail command is here:
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
put the code i posted earlier above these lines and retry. it might still not work but it'll be a step closer.
celicasaur
September 29th, 2008, 01:26 PM
I just tried what you suggested, but sadly it doesn't seem to have helped. It's still saying the same thing as posted in my first post:
Notice: Undefined index: radio in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 9
Notice: Undefined index: drop_down in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 10
Notice: Undefined index: check in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 12
Warning: Invalid argument supplied for foreach() in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 12
Notice: Undefined variable: check_msg in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 16
Data has been submitted to mr-celica@hotmail.co.uk!
Any further suggestions? :(
simplistik
September 29th, 2008, 02:22 PM
remove
$option = $_POST['radio'];
$dropdown = $_POST['drop_down'];
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
$check_msg Option: $option\n Drop-Down: $dropdown\n
from your code
notices aren't "errors", they're just notices. it's the warning that is keeping your script from executing, dropdown, radio and check do not exist in your form so when it was getting to that foreach loop it was erroring out since there is nothing to loop. getting rid of all that stuff will also ultimately get rid of the notices as well, even tho those don't hurt your script at all
celicasaur
September 29th, 2008, 03:58 PM
^^^ thanks for that :) seemed to get rid of the notices, like how you anticipated. It now displays:
Parse error: syntax error, unexpected '}' in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 18
My mailer.php page now looks like this:
<?php
if(isset($_POST['submit'])) {
$to = "mr-celica@hotmail.co.uk";
$subject = "Bluechip website query";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
}
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n";
echo "Data has been submitted to $to!";
ini_set("sendmail_from", "you@yourdomain.com");
mail($to, $subject, $body);
} else {
echo "Please enter all fields before submitting your query";
}
?>
Having a look at line 18, it shows
} else { and I cant understand why it doesn't want to work. I removed the
{ but then it displayed this on form submission:
Parse error: syntax error, unexpected T_ELSE in \\NAS40ENT\domains\b\bluechipmc.co.uk\user\htdocs\ mailer.php on line 18
:(
simplistik
September 29th, 2008, 04:47 PM
remove the last } from
if(isset($_POST['submit'])) {
$to = "mr-celica@hotmail.co.uk";
$subject = "Bluechip website query";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
} // <----- this guy right here
celicasaur
September 29th, 2008, 05:53 PM
Awesome help there guys! :)
It now displays "Data has been submitted to mr-celica@hotmail.co.uk!", which I guess is correct :)
Here is my new mailer.php file:
<?php
if(isset($_POST['submit'])) {
$to = "mr-celica@hotmail.co.uk";
$subject = "Bluechip website query";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n";
echo "Data has been submitted to $to!";
ini_set("sendmail_from", "you@yourdomain.com");
mail($to, $subject, $body);
} else {
echo "Please enter all fields before submitting your query";
}
?>
However, I have a couple of queries...
1) How long should I expect to wait until any emails actually come through? I'd have thought they should be instant, but it's been a good few minutes how and nothing has happened...
2) If I wanted to have a page in the same style as my entire website, on the page where the user is informed of the email submission being sucessful, would I have to do the whole page in php inside the "echo" section on the mailer.php file?
3) If I wanted a 'back' button on the mailer.php page, would this have to be done in php?
celicasaur
October 3rd, 2008, 11:07 PM
...guys? :(
celicasaur
October 5th, 2008, 07:34 PM
...anyone?? :( :(
tfg
October 6th, 2008, 11:24 AM
ini_set("sendmail_from", "you@yourdomain.com"); - you@yourdomain.com was for an example only, you should substitute this for the email address you intend to be sending email from.
celicasaur
October 6th, 2008, 01:13 PM
Of course, I'm so silly I forgot to edit that.
Thankyou so much for your help, I'm very grateful :D
celicasaur
October 10th, 2008, 12:24 PM
Guys, any idea how I can get this page below, to get replaced by another html page that looks more presentable?
http://i6.photobucket.com/albums/y239/Ranasaur/screenshot.jpg
Ideally a page would appear for a few seconds, then get timed out and the user will get re-directed to the homepage. If that's not possible, could I have suggestions on how to direct the user to a html page of my choice when the form submit button is clicked?
celicasaur
October 12th, 2008, 08:23 AM
Guys...?
tfg
October 13th, 2008, 05:43 AM
change
echo "Data has been submitted to $to!";
ini_set("sendmail_from", "you@yourdomain.com");
mail($to, $subject, $body);
to
ini_set("sendmail_from", "you@yourdomain.com");
mail($to, $subject, $body);
header("location: emailSent.html");
celicasaur
October 14th, 2008, 04:19 PM
Excellent, thankyou so much, it's working just as I'd like now :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.