I am absolutely 100% new to php programming, so go easy on me.

I have looked at php tutorials on how to create a simple form on a html page and then using a php script, have the contents of the form emailed to me, then it redirect to a "thank you" page. However, the php script i have at the moment is just showing a blank screen when executed.

The php code i am using:

<?php
$name = $_GET ; $company = $_GET ; $emailaddress = $_GET ; $message = $_GET ;
mail( "paul@coatesdesign.net", "Website form", $message, $company, $name, "From: $email" ); header( "Location: http://www.coatesdesign.net/thankyou.htm" );
?>

and the form code i am using on the html page:

<form action="form.php" method="post" name="form" id="form">
Name : <input name="name" type="text" id="name" size="25">
Company: <input name="company" type="text" id="company" size="30">
Email Address: <input name="emailaddress" type="text" id="emailaddress" size="50">
<textarea name="message" cols="80" rows="6" id="message"></textarea>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Clear">
</form>

The page i have it on is here

thank you very much for you help in advance.
Paul.

Hello vismund!

The problem is that you are not using the mail() function the right way... it is just a couple of details (check the manual ):

mail functions uses 4 parameters only. Everything goes right until the end of mail( "paul@coatesdesign.net", "Website form", $message ... the 4th parameter should be the headers. You will need to enter the company and other data inside your $message variable. If you remove everything that follows , $message you can see it work... like this:

mail( "paul@coatesdesign.net", "Website form", $message); header( "Location: http://www.coatesdesign.net/thankyou.htm" );

Try this to solve the problem:

<?php
$name = $_GET['name'] ; $company = $_GET['company'] ; $emailaddress = $_GET['emailaddress'] ; $message = $_GET['message'] ;
mail( "paul@coatesdesign.net", "Website form", $message.$company. $name. "From: $email" ); header( "Location: http://www.coatesdesign.net/thankyou.htm" );
?>

try

$message = "$message\n\n$company\n$name";

for some formatting where \n gives you a new line.

When you're feeling like experimenting take a look at http://phpmailer.sourceforge.net and try some html emails.

Sarah

Thank you both very much for your help.
Although, i'm still finding out that it isnt working and it still shows a blank page while on www.coatesdesign.net/form.php

heres the code i have now:

<?php
$name = $_REQUEST['name'] ; $company = $_REQUEST['company'] ; $emailaddress = $_REQUEST['emailaddress'] ; $message = "$_REQUEST['message']\n\n$company\n$name" ;
mail( "deathonthestairs@hotmail.com", "Website form", $message, "From:
$email" ); header( "Location: http://www.coatesdesign.net/thankyou.htm" );
?>

Is there anything i am doing wrong?

Ive got the email mailing to my email address now.
Although it just emails a blank email, with the header "Website form", doesnt say who sent it, even though i filled in the email address box. Also the "header" code doesnt redirect to that page.
heres the code im using:

<?php
$name = $_GET['name'] ;
$company = $_GET['company'] ;
$emailaddress = $_GET['emailaddress'] ;
$message = $_GET['message'] ;

$message = "$message\n\n$company\n$name";

mail( "paul@coatesdesign.net", "Website form", $message, "From: $emailaddress" );
header( "Location: http://www.coatesdesign.net/thankyou.htm" );
?>

The error i get on the php page is:

Warning: Cannot modify header information - headers already sent by (output started at /home/coatesd/public_html/form.php:4) in /home/coatesd/public_html/form.php on line 13

Somewhere at the top of the page you have a space, maybe a blank line before your <?php
Something like that. Effectively it's starting your page, get rid of it, you can't have anything before the <?php if you want to use header() in your script.

Try putting an exit; afterwards as well.

Sarah

Thank you all very very much!!
I have it working now, with it redirecting to the thanks page using javascript.

for reference, heres my code:

<?
$name = $_REQUEST['name'] ;
$company = $_REQUEST['company'] ;
$emailaddress = $_REQUEST['emailaddress'] ;
$message = $_REQUEST['message'] ;
$message = "$message\n\n$company\n$name"; 

mail( "paul@coatesdesign.net", "Website form", $message, "From: $emailaddress" );
?>
  <script>
  <!--
  window.location= "http://www.coatesdesign.net/thankyou.htm"
  //-->
  </script>
<?php 
exit;?>

thanks again

well done!!

Just a remark: Never use header after any other php script is called.

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.