Jump to content

Emailing Form Data using PHP Script


ben_1uk

Recommended Posts

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 = 'ben@maver.co.uk';

/* 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'>

Link to comment
Share on other sites

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  8) I just need to add in some validation now.

 

Thanks,

 

BB2011

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.