Jump to content

php based html feedback form produces blank emails


marcarl

Recommended Posts

Hi folks,

 

I have a php script to handle feedback on a website that I've built for a colleague. The site was based on a template that uses a flash header and 'iframes'. Unfortunately, when the visitor submits the form data, the email that is sent off does not collect any information from the form. I'll admit I'm quite new to php so this is foxing me. Extracts from the Contact page on the site are provided below plus the php file.

 

Contact form code extract:

 

"

 

<form method="POST" ACTION="http://www.cmlcleaning.co.uk/cmlcu.php" id="form" class="form"><table border="0" cellpadding="0" cellspacing="0" style="margin:19px 0 0 3px; width:180px;"><tr><td>

 

<input type="text" value="name" onClick="this.value=''" size="20"></td></tr> <tr><td><img alt="" src="images/spacer.gif" width="1" height="1"></td></tr><tr><td>

 

<input type="text" value="company" onClick="this.value=''" size="20"></td></tr><tr><td><img alt="" src="images/spacer.gif" width="1" height="1"></td></tr><tr><td>

 

<input type="text" value="email" onClick="this.value=''" size="20"></td></tr> <tr><td><img alt="" src="images/spacer.gif" width="1" height="1"></td></tr><tr><td>

 

<input type="text" value="phone" onClick="this.value=''" size="20"></td></tr><tr><td><img alt="" src="images/spacer.gif" width="1" height="1"></td></tr><tr><td>

 

<input type="text" value="address" onClick="this.value=''" size="20"></td></tr><tr><td><img alt="" src="images/spacer.gif" width="1" height="1"></td></tr><tr><td>

 

<textarea onClick="this.value=''" cols="2" rows="2">comments</textarea></td></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" style="margin:13px 0 0 37px;"><tr>

 

<td style="width:72px;"><a href="#" onclick="document.getElementById('form').reset()">

 

<img alt="" src="images/kn_1.jpg" border="0" width="60" height="18"></a></td><td><a href="#" onclick="document.getElementById('form').submit()">

 

<img alt="" src="images/kn_2.jpg" border="0" width="68" height="18"></a></td></tr><tr>

 

<td style="width:72px;"> </td>

 

<td> </td></tr><tr><td style="width:72px;"> </td><td> <p> </p>

 

<p> </p>

 

<p> </p>

 

<p> </p>

 

<p> </td></tr></table></td></tr></table></form></td></tr>

 

"

 

PHP code extract:

 

"

 

//Email configuration

 

$email_to = "[email protected]";

 

$email_subject = "New Contact Us Enquiry";

 

$headers = "MIME-Version: 1.0\r\n";

 

$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

 

/* additional headers */

 

$headers .= "From: Validator <script@".$_REQUEST["SERVER_NAME"].">\r\n";

 

define ("PATH_TO_FILES","http://www.cmlcleaning.co.uk/");

 

/*

 

$_REQUEST -- global array, contains all the variables, passed by form to the script (by method "get" or "post" -- does not matter)

 

The list of validated fields:

 

*/

 

$name = $_REQUEST["name"];

 

$company = $_REQUEST["company"];

 

$email = $_REQUEST["email"];

 

$phone = $_REQUEST["phone"];

 

$address = $_REQUEST["address"];

 

// Now we shell check each field. All error messages we will collect in $errors array, for futher writing it in file

 

$errors = array(); // array of errors;

 

// Full Name field

 

if (empty($name)) $errors[] = "You have not entered your name";

 

if (empty($company)) $errors[] = "You have not entered your company name";

 

if (empty($email)) $errors[] = "You have not entered your E-Mail Address";

 

if (empty($phone)) $errors[] = "You have not entered your phone number";

 

if (empty($address)) $errors[] = "You have not entered your address";

 

?>

 

<html>

 

<body>

 

<?

 

if (count($errors)) {

 

foreach ($errors as $i => $err) print "<p>".$err."</p>";

 

} else {

 

if ($country=="UK") $page=PATH_TO_FILES."iframe_9.html";

 

else $page=PATH_TO_FILES."iframe_9.html";

 

$res = "<p>"."This is the information submitted</p>";

 

$res .="<b>Your name:</b> ".$name."<br>";

 

$res .="<b>Your company name:</b> ".$company."<br>";

 

$res .="<b>E-Mail Address:</b> ".$email."<br>";

 

$res .="<b>Your phone number:</b> ".$phone."<br>";

 

$res .="<b>Your address:</b> ".$address."<br>";

 

$res .="<b>Your message:</b> ".nl2br($comments)."<br>";

 

$res .="<br><br>";

 

$mes = "<html><body>".$res."</body></html>";

 

mail($email_to, $email_subject, $mes, $headers);

 

print $res;

 

print "<small> ".$page." </small>";

 

print "<script>setTimeout(\"window.location.href='".$page."'\",1000)</script >";

 

}

 

?>

 

</body>

 

</html>

 

"

 

The php script is in use elsewhere but with slight changes to the field names and works fine.

 

I'm baffled by this as I can't see why it can't work. The emails come through, but with no data, providing you complete each field (there is some validation going on which also works fine on other sites).  Obviously I'm missing something either in the php script and / or the contact page but I can't see it. 'iframe_9.html' is my Thank You page by the way.  I think the problem lies with posting from the iframe but not being familiar with iframes means I don't know where to go from here.

 

Can anyone else see where I'm going wrong from the above?

 

Hope someone can point me in the right direction.

 

Cheers,

 

Alpinenut.

 

Simple. Your html is wrong.

 

<input type="text" value="company"

 

should be

 

<input type="text" name="company"

 

Then you will get values for each of the named variables passed to the form processing script.

 

PLEASE use the CODE tags when posting code. It makes it so much easier to read.

Thank you very much AndyB for such a quick reply.  I really appreciate it.  Knew it had to be something simple.

 

The form now functions as it should.  However, now that the form picks up the visitor data, when the php script tries to send the visitor to  my thank you page it doesn't work and the result is messy to say the least.  As all my pages are displayed in an iframe, do you know how I would reference a new page, such as the temporary iframe_9.html that I'm currently using as a test?  I don't really mind if it shows the flash header, so long as the page that is displayed is stable.  I can always place a link back to the main home page of the site in the Thank You page.  It seems I can't just refer to the html page so I guess I'm not using the correct code in my php file.

 

Sorry about the missing code tags.

 

Marcarl.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.