Form HTML generates blank email

  ade.h 21:44 14 Jun 06

Having got over the PHP hurdle click here I have now discovered a new problem. My form doesn't work! click here to view it.

Would anyone be able to work out, from the source code, why none of the text from the fields reaches my inbox? I just get a blank email, even though I have filled in all fields and the elseif command is included in the PHP file.

  ade.h 23:03 14 Jun 06

I'll edit them and see if it helps. At the moment, the html is totally NOF's own and I haven't tried to randomly mess with it in case I make it worse! Thanks for the advice, John. 23:35 14 Jun 06

I might have missed it, but I don't think you gave your form an "Action" which points to your php code on the server. For instance < action= "testform.php" >.

If I'm wrong, forgive me no sleep due to heatwave lately! 23:37 14 Jun 06

I meant "Method".

  harristweed 08:49 15 Jun 06

I can't see anything wrong. I've tested the code and it works for me!

I have noticed that the form asks for a name and that is NOT sent on the email. To include the 'name', change the php to:

else {
$mail_message="From $name

$mail_message.="Message: $message";
mail( "[email protected]", "Form Message",
$mail_message, "From: $email" );
header( "Location: click here" );

also it would be better to change all the $_REQUEST[]


$_POST[] as you are using thepost method, makes the form more secure.


$name = $_POST['name'] ;

and leave out the '

so it becomes

$name = $_POST[name] ;

all the ' do is make php work harder!

Good Luck.

  ade.h 14:25 15 Jun 06

Your eyes are not deceiving you; I had added an action manually after uploading the site, but then I needed to re-upload the site and forgot to re-edit the html file! So I now get an email with the message text, which is a mjor step forward!

  ade.h 14:28 15 Jun 06

You're right about the name issue, but I couldn't work out why it might happen. I checked that the text box is called "name", but I didn't expect a problem in the PHP, as that was copied and pasted.

Thanks very much for that new code; I'll implement that later and - fingers crossed - mark this as resolved!

Cheers both.

  ade.h 17:31 15 Jun 06

Ticked too soon; it's not generating an email at all now. Code as follows:

$name = $_POST[name] ;
$email = $_POST[email] ;
$message = $_POST[message] ;

if (!isset($_POST[email])) {
header( "Location: click here" );
elseif (empty($email) || empty($message)) {
header( "Location: click here" );
else {
$mail_message="From $name";
$mail_message.="Message: $message";
mail( "my email address", "Form Message",
$mail_message, "From: $email" );
header( "Location: click here" );

I've modified the last bit to match (I think) haristweed's "name" modification. I have tried it with and without POST and apostrophes.

What have I missed? (Something basic I bet)

  ade.h 17:32 15 Jun 06

It still gives the success URL, by the way.

  ade.h 19:16 15 Jun 06

I've just received the test email - 1.5 hours late (is that normal for PHP emails?) - so it does work okay, except for slightly messy formatting. It comes out as:

>From A HillierMessage: Test message

Is there any way of forcing each value on to a new line, or at least spaced out, because I will eventually need to add a few other values to the finished form.

  harristweed 21:35 15 Jun 06

php emails go as fast or slow as any other.

Space it like this. (as my original code)

else {
$mail_message="From $name"

$mail_message.="Message: $message

mail( "my email address", "Form Message",

This thread is now locked and can not be replied to.

How to watch Windows Event live stream, live blog | Microsoft event live stream: Watch Microsoft…

1995-2015: How technology has changed the world in 20 years

This amazing app turns your iPad Pro into a Cintiq

iPhone 7 Plus review: A superb big-screen phablet, but the price tag's enormous | iPhone 7 Plus…