View Full Version : Cannot get this PHP contact form to work
deronsizemore
October 18th, 2004, 12:26 PM
Here is the site I'm working on: www.mcihost.com/naturalchoices/requestinfo.php
And here is the PHP code I've used in the body of the file "email.php":
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$dayphone = $_POST['dayphone'];
$nightphone = $_POST['nightphone'];
$regarding = $_POST['regarding'];
$regarding2 = $_POST['regarding2'];
$regarding3 = $_POST['regarding3'];
$regarding4 = $_POST['regarding4'];
$regarding5 = $_POST['regarding5'];
$regarding6 = $_POST['regarding6'];
$regarding7 = $_POST['regarding7'];
$regarding8 = $_POST['regarding8'];
$othertests = $_POST['othertests'];
$healthproducts = $_POST['healthproducts'];
$comments = $_POST['comments'];
$toaddress = "deronsizemore@yahoo.com";
$subject = "Request Information";
$msg = "$name\n";
$msg.= "$email\n";
$msg.= "$dayphone\n";
$msg.= "$nightphone\n";
$msg.= "$regarding\n";
$msg.= "regarding2\n";
$msg.= "regarding3\n";
$msg.= "regarding4\n";
$msg.= "regarding5\n";
$msg.= "regarding6\n";
$msg.= "regarding7\n";
$msg.= "regarding8\n";
$msg.= "$othertests\n";
$msg.= "$healthproducts\n";
$msg.= "$comments\n";
$mailheaders = "From: $email\r\n";
$mailheaders .= "To: deronsizemore@yahoo.com\r\n";
$mailheaders .= "Content-Type: multipart/mixed\r\n";
mail("$toaddress", "$subject", "$msg", "$mailheaders");
echo("Thank you $name for requesting information about Natural Choices!"); ?>
I've been using my own e-mail address to test the script and make sure it works. I click submit and then the screen reads "Thank you for requesting info...." like it should. I get an e-mail which has the subject "request info" and the senders e-mail address, but there is not message...just blank. Anyone know what I'm doing wrong. I'm ready to pull my hair out.
aknatn
October 18th, 2004, 02:10 PM
Try concatinating all of your "msg" fields into the msg variable, like this:
$msg = "$name\n"."$email\n"."$dayphone\n"."$nightphone\n"."$regarding\n"."regarding2\n"."regarding3\n"."regarding4\n"."regarding5\n"."regarding6\n"."regarding7\n"."regarding8\n"."$othertests\n"."$healthproducts\n"."$comments\n";
deronsizemore
October 18th, 2004, 02:27 PM
Nope, nothing! Just like before. I recieved the e-mail but it was blank, no information.
????
aknatn
October 18th, 2004, 02:31 PM
Ok, what you want to do is get all of your form field variables into one variable called "msg", are you getting any error messages?
deronsizemore
October 18th, 2004, 03:55 PM
Yes, this is what I did. I did exactly what you posted above. I get no errors or anything...this is what I don't understand. I get no errors, I recieve the e-mail, but its blank.
Here is my code after changing what you told me in the last post.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$dayphone = $_POST['dayphone'];
$nightphone = $_POST['nightphone'];
$regarding = $_POST['regarding'];
$regarding2 = $_POST['regarding2'];
$regarding3 = $_POST['regarding3'];
$regarding4 = $_POST['regarding4'];
$regarding5 = $_POST['regarding5'];
$regarding6 = $_POST['regarding6'];
$regarding7 = $_POST['regarding7'];
$regarding8 = $_POST['regarding8'];
$othertests = $_POST['othertests'];
$healthproducts = $_POST['healthproducts'];
$comments = $_POST['comments'];
$toaddress = "deronsizemore@yahoo.com";
$subject = "Request Information";
$msg= "$name\n"."$email\n"."$dayphone\n"."$nightphone\n"."$regarding\n"."regarding2\n"."regarding3\n"."regarding4\n"."regarding5\n"."regarding6\n"."regarding7\n"."regarding8\n"."$othertests\n"."$healthproducts\n"."$comments\n";
$mailheaders = "From: $email\r\n";
$mailheaders .= "To: deronsizemore@yahoo.com\r\n";
$mailheaders .= "Content-Type: multipart/mixed\r\n";
mail("$toaddress", "$subject", "$msg", "$mailheaders");
echo("Thank you $name for requesting information about Natural Choices!");
?>
sticmann
October 18th, 2004, 04:49 PM
try:
$msg= $name"\n".$email"\n".$dayphone"\n".$nightphone"\n".$regarding"\n".regarding2"\n".regarding3"\n".regarding4"\n".regarding5"\n".regarding6"\n".regarding7"\n".regarding8"\n".$othertests"\n".$healthproducts"\n".$comments;
$mailheaders = "From: "$email"\r\n";
$mailheaders .= "To: deronsizemore@yahoo.com\r\n";
$mailheaders .= "Content-Type: multipart/mixed\r\n";
mail($toaddress, $subject, $msg, $mailheaders);
echo("Thank you "$name" for requesting information about Natural Choices!");
?>
vars shouldn't be in quotes
-Joshua
aknatn
October 18th, 2004, 05:13 PM
What was I thinking, it was right.
Check this line:
$mailheaders = "From: "$email"\r\n";
make it:
$mailheaders = "From: $email\r\n";
though.
aknatn
October 18th, 2004, 05:23 PM
I am at work and cannot send email from my system, so I can't debug. When I get home, if you still need it, I'll fix it for you (in about 4 hours).
aknatn
October 18th, 2004, 05:26 PM
try:
$msg= $name"\n".$email"\n".$dayphone"\n".$nightphone"\n".$regarding"\n".regarding2"\n".regarding3"\n".regarding4"\n".regarding5"\n".regarding6"\n".regarding7"\n".regarding8"\n".$othertests"\n".$healthproducts"\n".$comments;
$mailheaders = "From: "$email"\r\n";
$mailheaders .= "To: deronsizemore@yahoo.com\r\n";
$mailheaders .= "Content-Type: multipart/mixed\r\n";
mail($toaddress, $subject, $msg, $mailheaders);
echo("Thank you "$name" for requesting information about Natural Choices!");
?>
vars shouldn't be in quotes
-Joshua
These ahould be in quotes because it is setting the area between concats that will be added.
like so:
<?php
$name = "steve";
$greet = "hello";
$msg = "$name\n"."$greet";
echo ($msg);
?>
aknatn
October 18th, 2004, 06:49 PM
I was jsut examining your code and I think I am on to why. You should be getting an undefined index error (maybe check your server error logs) for each check box that is unchecked.
Give your code a try (with the concat fix I posted) againbut this time check all of the check boxes and fill it all out.
teiz77
October 19th, 2004, 03:18 AM
you forgot the $ signs for some of your variables... then it won't work
...
$msg = "$name\n";
$msg.= "$email\n";
$msg.= "$dayphone\n";
$msg.= "$nightphone\n";
$msg.= "$regarding\n";
$msg.= "regarding2\n"; <- here
$msg.= "regarding3\n"; <- here
$msg.= "regarding4\n"; <- here
$msg.= "regarding5\n"; <- here
$msg.= "regarding6\n"; <- here
$msg.= "regarding7\n"; <- here
$msg.= "regarding8\n"; <- here
$msg.= "$othertests\n";
...
try this:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$dayphone = $_POST['dayphone'];
$nightphone = $_POST['nightphone'];
$regarding = $_POST['regarding'];
$regarding2 = $_POST['regarding2'];
$regarding3 = $_POST['regarding3'];
$regarding4 = $_POST['regarding4'];
$regarding5 = $_POST['regarding5'];
$regarding6 = $_POST['regarding6'];
$regarding7 = $_POST['regarding7'];
$regarding8 = $_POST['regarding8'];
$othertests = $_POST['othertests'];
$healthproducts = $_POST['healthproducts'];
$comments = $_POST['comments'];
$toaddress = "deronsizemore@yahoo.com";
$subject = "Request Information";
$msg = $name . "\n";
$msg .= $email . "\n";
$msg .= $dayphone . "\n";
$msg .= $nightphone . "\n";
$msg .= $regarding . "\n";
$msg .= $regarding2 . "\n";
$msg .= $regarding3 . "\n";
$msg .= $regarding4 . "\n";
$msg .= $regarding5 . "\n";
$msg .= $regarding6 . "\n";
$msg .= $regarding7 . "\n";
$msg .= $regarding8 . "\n";
$msg .= $othertests . "\n";
$msg .= $healthproducts . "\n";
$msg .= $comments . "\n";
$mailheaders = "From: " . $email . "\r\n";
$mailheaders .= "To: deronsizemore@yahoo.com\r\n";
$mailheaders .= "Content-Type: multipart/mixed\r\n";
mail($toaddress, $subject, $msg, $mailheaders);
echo("Thank you $name for requesting information about Natural Choices!");
?>
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.