Jump to content

What is wrong with my formmail.php script


Recommended Posts

I get the completed form sent to my email account, but it does not contain any information that the user entered - see below:

 

Name:

Telephone:

Email:

Comment:

 

 

<?php

 

/* Incoming Subject and Email Variables - Fixed */

 

$emailSubject = 'Message from example;

$webMaster = '[email protected]';

 

/* Gathering Data Variables - User Data */

 

$nameField = $_POST['email'];

$emailField = $_POST['name'];

$telephoneField = $_POST['telephone'];

$messageField = $_POST['message'];

 

$body = <<<EOD

<br><hr><br>

Email: $email <br>

Name: $name <br>

Telephone: $telephone <br>

Comments: $comments <br>

EOD;

 

$headers = "From: $email\r\n";

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

$success = mail($webMaster, $emailSubject, $body, $headers);

 

/* Results rendered as code */

 

$theResults = <<<EOD

<html>

<head>

<title>JakesWorks - travel made easy-Homepage</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">

<!--

body {

background-color: #f1f1f1;

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 12px;

font-style: normal;

line-height: normal;

font-weight: normal;

color: #666666;

text-decoration: none;

}

-->

</style>

</head>

<body>

<div>

  <div align="left">Thank you for your interest! Your email will be answered very soon!</div>

</div>

</body>

</html>

EOD;

echo "$theResults"

 

 

?>

 

 

Any eagle eyes out there who can solve the problem?

Try this:

<?php

/* Incoming Subject and Email Variables - Fixed */

   $emailSubject = 'Message from example';
   $webMaster = '[email protected]';

/* Gathering Data Variables - User Data */

   $email = $_POST['email'];
   $name = $_POST['name'];
   $telephone = $_POST['telephone'];
   $message = $_POST['message'];
   
   $body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Telephone: $telephone <br>
Comments: $message <br>
EOD;

   $headers = "From: $email\r\n";
   $headers .= "Content-type: text/html\r\n";
   $success = mail($webMaster, $emailSubject, $body, $headers);
   
/* Results rendered as code */

   $theResults = <<<EOD
<html> 
<head> 
<title>JakesWorks - travel made easy-Homepage</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<style type="text/css"> 
<!--
body {
   background-color: #f1f1f1;
   font-family: Verdana, Arial, Helvetica, sans-serif;
   font-size: 12px;
   font-style: normal;
   line-height: normal;
   font-weight: normal;
   color: #666666;
   text-decoration: none;
}
--> 
</style> 
</head> 
<body> 
<div> 
  <div align="left">Thank you for your interest! Your email will be answered very soon!</div> 
</div> 
</body> 
</html>
EOD;
echo $theResults;  
?>

 

Just a small explanation of what you did wrong to back this up. You had passed your $_POST variables into variables called fieldnameField and then you're trying to call them with $fieldname. You were calling variables that weren't defined. Check your variable names in future! Don't worry, it's quite a common mistake :P

 

Try this:

<?php

/* Incoming Subject and Email Variables - Fixed */

   $emailSubject = 'Message from example';
   $webMaster = '[email protected]';

/* Gathering Data Variables - User Data */

   $email = $_POST['email'];
   $name = $_POST['name'];
   $telephone = $_POST['telephone'];
   $message = $_POST['message'];
   
   $body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Telephone: $telephone <br>
Comments: $message <br>
EOD;

   $headers = "From: $email\r\n";
   $headers .= "Content-type: text/html\r\n";
   $success = mail($webMaster, $emailSubject, $body, $headers);
   
/* Results rendered as code */

   $theResults = <<<EOD
<html> 
<head> 
<title>JakesWorks - travel made easy-Homepage</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<style type="text/css"> 
<!--
body {
   background-color: #f1f1f1;
   font-family: Verdana, Arial, Helvetica, sans-serif;
   font-size: 12px;
   font-style: normal;
   line-height: normal;
   font-weight: normal;
   color: #666666;
   text-decoration: none;
}
--> 
</style> 
</head> 
<body> 
<div> 
  <div align="left">Thank you for your interest! Your email will be answered very soon!</div> 
</div> 
</body> 
</html>
EOD;
echo $theResults;  
?>

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.