I need help Im trying to get a form to work with PHP and it doesnt seem to be working.

I fill out the form and click submit. It changes to a blank white screen not displaying the thank you page or email the form fields. Any ideas? Thanks

<?
/* 
Subject and email Variables. 

Variables holds information and as shown below you have your subject variable and email variable. PHP is case sensitive
*/

	$emailSubject = 'PHP Email Scripting';
	$webMaster = 'mrjelly@hotmail.com';

/* Gathering Data Variables. */

	$nameField = $_POST('name');
	$addressField = $_POST('address');
	$mobileField = $_POST('mobile');
	$emailField = $_POST('email');
	$typeField = $_POST('type of event');
	$occassionField = $_POST('occassion');
	$guestsletterField = $_POST('guests');

$body = <<<EOD
<br><hr><br>
Name: $name <br>
Address: $address <br>
Mobile: $mobile <br>
Email: $email <br>
Type: $type <br>
Occassion: $occassion <br>
Guests: $guests <br>
EOD;

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

/* Results rendered as HTML */

	$theResults = <<<EOD
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Revolution-Bookings</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<link href="Revolution CSS.css" rel="stylesheet" type="text/css" />
<link href="Oceana CSS.css" rel="stylesheet" type="text/css" />
<link href="Oceana CSS 2.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--

.style2 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: xx-large;
	color: #FFFFFF;
	font-weight: bold;
}
.style3 {
	color: #FFFFFF;
	font-weight: bold;
}
-->
</style>
</head>

<body>
<div id = "content" >
  		<div id = "header"></div>
    <div id = "nav">|||<a href="Index.html"> Home </a>||| <a href="Drinks Page.html">Drinks</a> ||| <a href="Galleries Page.html">Galleries</a> ||| <a href="Bookings Page.html">Bookings</a> |||</div>
    <p>&nbsp;</p>
  <div id = "main">
    <p class="style2">THANK YOU FOR BOOKING</p>
    <p class="style3">&nbsp;</p>
    <p class="style3">WE WILL CONFIRM YOUR DETAILS VIA E-MAIL AND LOOK FORWARD TO SEEING YOU SOON!</p>
  </div>
<div id = "footer">
          <div align="center">Copyright 2009 Revolution Bar - All rights reserved. Use of this site is subject to our Terms & Conditions and Privacy & Cookie Policy. Powered by 88Publish. </div>
  </div>  
</div>
</body>
</html>
EOD;
echo "$theResults";
?>

Recommended Answers

All 15 Replies

There are a few things that dont look right but :
- What is all of this EOD stuff? Never seen it before in my life?
- Check your names of the $_POST fields as they contain bad naming conventions
- Last line should be "echo $theResults;" no quotes

See that gets anything on the page?

There are a few things that dont look right but :
- What is all of this EOD stuff? Never seen it before in my life?
- Check your names of the $_POST fields as they contain bad naming conventions
- Last line should be "echo $theResults;" no quotes

See that gets anything on the page?

The EOD stuff is called HEREDOC, php.net/HEREDOC

There are a few things that dont look right but :
- What is all of this EOD stuff? Never seen it before in my life?
- Check your names of the $_POST fields as they contain bad naming conventions
- Last line should be "echo $theResults;" no quotes

See that gets anything on the page?

Thanks I have tried to change the quotes on the last line.
As for the naming convention and EOD i followed a tutorial at this url:

http://www.tutvid.com/tutorials/dreamweaver/tutorials/phpFormHandler.php

I still cant get it to work though

You should note that none of those stylesheets will work, nor will the links or anything else in the email that references a file. They all must be ABSOLUTE paths, including the domain.

Also, if you're getting a white screen make sure you have error reporting turned on: error_reporting(E_ALL); at the top.

Hmmm, just something to say, I have never seen anyone user the round brackets to take post data...

you were usering $_POST('egnejg');
it should be $_POST;

And you can't use EDO twice I think you must use a different three letters for instance FOD...

Hmmm, just something to say, I have never seen anyone user the round brackets to take post data...

you were usering $_POST('egnejg');
it should be $_POST;

And you can't use EDO twice I think you must use a different three letters for instance FOD...

Yeah $_POST('something') would throw an error saying that a Function name must be a string, so switch to []. As for the HEREDOC, you can use the same delimiter as many times as you wish.

You should note that none of those stylesheets will work, nor will the links or anything else in the email that references a file. They all must be ABSOLUTE paths, including the domain.

Also, if you're getting a white screen make sure you have error reporting turned on: error_reporting(E_ALL); at the top.

Thanks for the link.

Also in regards to the 'absolute path' I thought that first to, but I think it is a contact form on the website that appears not one that is sent via email until later.

I just did research on 'heredoc text' in short:
- Acts like a set of " "

Questions I have are in the example code:

$example = <<<EOT // Does it have to always be EOT? why not WTF, etc? always have to be a 3 letter acronym?
blah blah blah
EOT;
// Why would people use this rather then condensed quotes?

It doesn't always have to be EOT, it can be any string as long as the end is the same. Heredoc is used over quotes strings because you don't have to worry about escaping anything save $. In 5.3 PHP is getting nowdoc which is heredoc but wont parse anything, including variables.

Thanks guys I appreciate your help in this. I have changed the round brackets(Parenthesis) to rectangular brackets []. I have also added the error message code.

We shall see if this works. If the code still doesnt work then ill have to find another code.

Thanks again.

It doesn't always have to be EOT, it can be any string as long as the end is the same. Heredoc is used over quotes strings because you don't have to worry about escaping anything save $. In 5.3 PHP is getting nowdoc which is heredoc but wont parse anything, including variables.

parse anything, including variables?

In other words wont accept or compute variables or resource names?

parse anything, including variables?

In other words wont accept or compute variables or resource names?

// HereDoc
$somevar = "Hello";
$somestring = <<<END
  $somevar World!;
END;
echo $somestring;
// Hello World!
// NowDoc
$somevar = "Hello";
$somestring = <<<'END'
  $somevar World!;
END;
echo $somestring;
// $somevar World!

NowDoc is takening over? or being included with HereDoc?

So you would only use NowDoc for a long line of text otherwise u would just use a variable and concactenate it with a period?

NowDoc is takening over? or being included with HereDoc?

So you would only use NowDoc for a long line of text otherwise u would just use a variable and concactenate it with a period?

NowDoc is going to be separate of HereDoc. They'll serve two different purposes like "" and ''

They woudln't replace HereDoc. With NowDoc that would defeat the whole purpose of HereDoc.

I love HereDoc. Good for making results pages. Means you can make a whole html page and stick the PHP in without having to use the tags etc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.