ben_1uk Posted February 18, 2011 Share Posted February 18, 2011 Hi everyone, I have created a HTML form for collecting data on a web page, ie, name, email address, etc, which works fine. I have then asked for that data to be emailed to me using the POST action in conjunction with a PHP script called "carparkprocess2.php". At the moment, the form works OK on the web page, the confirmation message to say the data has been submitted successfully works OK, but the email that should display the information entered into the form doesn't work properly. It comes through and is formatted OK, but the form information is missing. I've been trying to resolve this issue for 2 days straight now and have tried loads of different things! Can anybody help? I need a quick answer on this one if possible <?php error_reporting(E_ALL ^ E_NOTICE); // Prints all errors except Notices. /* Subject and Email Variables */ $emailSubject = 'Car Park Reservation Confirmation'; $webMaster = '[email protected]'; /* Gathering Data Variables */ if (!isset($_POST['name'])) { $_POST['name'] = "name"; } if (!isset($_POST['carregistration'])) { $_POST['carregistration'] = "carregistration"; } if (!isset($_POST['emailaddress'])) { $_POST['emailaddress'] = "emailaddress"; } if (!isset($_POST['numberinparty'])) { $_POST['numberinparty'] = "numberinparty"; } $body = <<<EOD <br><hr><br> Name: $name <br> Vehicle Registration: $carregistration <br> Email Address: $emailaddress <br> Number in Party: $numberinparty <br> EOD; $mailheaders .= "From: $emailaddress\r\n"; $headers .= "Content-type: text/html"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results rendered as HTML */ $theResults = <<<EOD <html> <head> <title>Car Park Reservation Confirmation</title> <meta http-equiv='Content-Type' content='text/html'> <style type='text/css'> <!-- body { min-height: 100%; height: auto; background: #000000; color: #ffffff; font-size: 14px; font-family: Verdana, Arial, Helvetica, sans-serif; margin: 0; } --> </style> </head> <div> <div align='left'>Your car park reservation request has been successful</div> </div> </body> </html> EOD; echo "$theResults"; ?> Here is the HTML within the form: <form method='post' action='carparkprocess2.php'> Quote Link to comment https://forums.phpfreaks.com/topic/228080-emailing-form-data-using-php-script/ Share on other sites More sharing options...
ronverdonk Posted February 18, 2011 Share Posted February 18, 2011 To me you are switching the assignments, i.e. if (!isset($_POST['name'])) { $_POST['name'] = "name"; } should be if (!isset($_POST['name'])) { $name = $_POST['name']; } this goes for all the assignments from the $_POST array. Quote Link to comment https://forums.phpfreaks.com/topic/228080-emailing-form-data-using-php-script/#findComment-1176134 Share on other sites More sharing options...
ben_1uk Posted February 18, 2011 Author Share Posted February 18, 2011 Thanks for the reply. I have now got rid of the "isset" command as I had only included this originally to try and resolve the "undefined variable" warning messages. However, I have since included the below code to stop this from happening: error_reporting(E_ALL ^ E_NOTICE); // Prints all errors except Notices. Not the "correct" fix I know, but I was going round in circles trying to resolve something that strictly speaking isn't an error. I have simply changed: /* Gathering Data Variables */ if (!isset($_POST['name'])) { $_POST['name'] = "name"; } if (!isset($_POST['carregistration'])) { $_POST['carregistration'] = "carregistration"; } if (!isset($_POST['emailaddress'])) { $_POST['emailaddress'] = "emailaddress"; } if (!isset($_POST['numberinparty'])) { $_POST['numberinparty'] = "numberinparty"; } to... /* Gathering Data Variables */ $name = $_POST['name']; $carregistration = $_POST['carregistration']; $emailaddress = $_POST['emailaddress']; $numberinparty = $_POST['numberinparty']; ...and it now works I just need to add in some validation now. Thanks, BB2011 Quote Link to comment https://forums.phpfreaks.com/topic/228080-emailing-form-data-using-php-script/#findComment-1176149 Share on other sites More sharing options...
ronverdonk Posted February 18, 2011 Share Posted February 18, 2011 In order to prevent possible 'undefined index' notices, you'd better code: $test = isset($_POST['carregistration']) ? $_POST['carregistration'] : null; etc Quote Link to comment https://forums.phpfreaks.com/topic/228080-emailing-form-data-using-php-script/#findComment-1176250 Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2011 Share Posted February 18, 2011 Stopping error messages from displaying != cause of errors corrected. Quote Link to comment https://forums.phpfreaks.com/topic/228080-emailing-form-data-using-php-script/#findComment-1176259 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.