simple email form

A

Anonymous

Guest
Hi I need a simple email form on my website for the following criteria :

First name: Bob
Surname : Jones
M/F : M
Age: 39

List input:
1 test1
2 test2
3 test3
4 test4
5 test5

I then want the site to email back saying something like :


Thank you Bob

I see you have chosen test1, test2, test3, test3, test5 - Good Luck
regards
Webmaster

I'm still new to PHP and would love some help

Thanks in advance

ian :)
 
I can do the html - no problems....any help/pointer apreciated.

Ian
 
Just a quick test form for now...will tidy it up when complete - Ian


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Test</title>
</head>

Test Form <p>

<body>
<input align="" checked maxlength="" name="" size="" src="" type="button|checkbox|hidden|image|password|radio|reset|submit|text|textarea|file" value="" tabindex="" disabled readonly title="" accesskey=""> First name
<p>
<input align="" checked maxlength="" name="" size="" src="" type="button|checkbox|hidden|image|password|radio|reset|submit|text|textarea|file" value="" tabindex="" disabled readonly title="" accesskey=""> Surname
<p>
<input align="" checked maxlength="" name="" size="" src="" type="button|checkbox|hidden|image|password|radio|reset|submit|text|textarea|file" value="" tabindex="" disabled readonly title="" accesskey=""> Date of Birth
<p>
<input align="" checked maxlength="" name="" size="" src="" type="button|checkbox|hidden|image|password|radio|reset|submit|text|textarea|file" value="" tabindex="" disabled readonly title="" accesskey=""> Item 1
<p>
<input align="" checked maxlength="" name="" size="" src="" type="button|checkbox|hidden|image|password|radio|reset|submit|text|textarea|file" value="" tabindex="" disabled readonly title="" accesskey=""> Item 2
<p>
<input align="" checked maxlength="" name="" size="" src="" type="button|checkbox|hidden|image|password|radio|reset|submit|text|textarea|file" value="" tabindex="" disabled readonly title="" accesskey=""> Item 3
<p>
<input align="" checked maxlength="" name="" size="" src="" type="button|checkbox|hidden|image|password|radio|reset|submit|text|textarea|file" value="" tabindex="" disabled readonly title="" accesskey=""> Item 4
<p>
<input align="" checked maxlength="" name="" size="" src="" type="button|checkbox|hidden|image|password|radio|reset|submit|text|textarea|file" value="" tabindex="" disabled readonly title="" accesskey=""> Item 5

</body>
</html>
 
A little correction here:

Add the form tag to your... "form".
Also in the inputs type you must choose one of them.

So here goes an example:
Code:
<form name="whatever" method="post" action="file_that_will_send_the_mail">
     First name: <input name="fname" type="text" value=""  /><br />
     Surname: <input name="sname" type="text" value=""  /><br />
     Email: <input name="email" type="text" value=""  /><br />
     Item 1: <input name="items[1]" type="checkbox" value="Whatever this item means"  /><br />
     Item 2: <input name="items[2]" type="checkbox" value="Whatever this item means"  /><br />
     Item 3: <input name="items[3]" type="checkbox" value="Whatever this item means"  /><br />
     Itme 4: <input name="items[4]" type="checkbox" value="Whatever this item means"  /><br />
     Item 5: <input name="items[5]" type="checkbox" value="Whatever this item means"  /><br />
     <input name="SendIt" type="submit" value="Send it!"  />
</form>
I added the email field... not sure where you'll get it.
Also i put the Items as checkbox.

Now here goes the code to send your email:
Code:
<?php

// If we have a submittion
if(isset($_POST['SendIt'])) {

     // Check the selected checkboxes (Items)
     $increment = 1;
     $count = count($_POST['items']) + 1;

     // This should output something like:
     // 1: item_name, 3: item_name, 5: item_name
     // Will take off the last "," and should print out just the choosen checkboxes
     // in this case e.g.: 1, 3 and 5

     foreach ($_POST['items'] as $key => $value){  
          // if the item was choosen  
          if(isset($_POST['items'][$key])) {
               $increment++;
               ($count == $increment) ? $items .= $key . ": " . $value : $items .= $key . ": " . $value . ", ";
          }
     } 

// I love this style :)
// This style must be all at left or it won't work
$message =<<<ENDMESSAGE
Thank you {$_POST['fname']} {$_POST['sname']}

I see you have chosen {$items} - Good Luck
regards
Webmaster
ENDMESSAGE;


     $done = mail($_POST['email'], 'the subject', $message, 'FROM:your_email_here');
     print ($done) ? 'Message sent!' : 'Error sending message!'; 

}

?>
Well... as always... i didn't tested it, but... should work (i hope) :)
 
I'll give it a try..many thanks Gesf... I'll get back to you on the results...

Ian
 
worked excelent Gesf - All I would like to do now is replace the check boxes with values the sender inputs - this is going to be a Christmas List website for my 5 year old Son so he can tell Santa what he would like for Christmas - so relacing the check boxes with toy he wants basically -
So is input will be something like

Yoda Toy
Light Sabre
DVD player
Play Station Games
BatMan Outfit

So the email sent will say "I see you would like the following for Christmas

Yoda Toy,
Light Sabre
DVD player
Play Station Games
BatMan Outfit

Santa

you get the idea

I'm not too hot on forms so I would apreciate your input on how to modify...

Regards Ian
 
Just replace all the items inputs with one select tag:
Code:
<form name="whatever" method="post" action="file_that_will_send_the_mail">
First name: <input name="fname" type="text" value=""  /><br />
Surname: <input name="sname" type="text" value=""  /><br />
Email: <input name="email" type="text" value=""  /><br />
Select gift:
<select name="gifts">
   <option value="Yoda Toy">Yoda Toy</option>
   <option value="Light Sabre">Light Sabre</option>
   <option value="DVD player">DVD player</option>
   <option value="Play Station Games">Play Station Games</option>
   <option value="BatMan Outfit">BatMan Outfit</option>
</select>
<input name="SendIt" type="submit" value="Send it!"  />
</form>
That's all. Now your PHP part will be shorter:
Code:
<?php

if(isset($_POST['SendIt'])) {

$message =<<<ENDMESSAGE
Thank you {$_POST['fname']} {$_POST['sname']}
I see you have chosen {$_POST['gifts']} - Good Luck
regards
Webmaster
ENDMESSAGE;

$done = mail($_POST['email'], 'the subject', $message, 'FROM:your_email_here');
print ($done) ? 'Message sent!' : 'Error sending message!'; 

}

?>
 
Nearly there - instead of a drop down menu, I would like the sender to input there own list of toys - can this be easy done ?

I mean -

Name
Surname
Email

What would you like for Christmas ?
Choose 5 things you would like off Santa :-

input a string
input a string
input a string
input a string
input a string

Send

Email recieved

I see you chosen a Barbie Doll, a Dog, PS2, Batman

santa
 
So make inputs like you have e.g.: in the first name with text type and than get the values with $_POST['the_input_name'];

Just follow the code and you'll easily get there ;)
 
Thank you Gesf for you input - I a m slowly getting my head around PHP.



:D
 
Gesf - Sorry to trouble you again - but what is wrong wirth this array ? I've searched the net and ca.t see to find the right format.

I get this error - Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ']' in /homepages/27/d69406243/htdocs/santa/1.php on line 7 which is the

I see you have chosen {$_POST['fname0','fname1','fname2','fname3','fname4']} - Good Luck

<?php

if(isset($_POST['SendIt'])) {

$message =<<<ENDMESSAGE
Thank you {$_POST['fname']} {$_POST['sname']}
I see you have chosen {$_POST['fname0','fname1','fname2','fname3','fname4']} - Good Luck
regards
Webmaster
ENDMESSAGE;
$done = mail($_POST['email'], 'Xmas List', $message, 'FROM:Santa');
print ($done) ? 'Message sent to Santa!' : 'Error sending message!';

}

?>

part of the form is this

<p> <input name="fname0" type="text" value="" /> Item 1</p>
<p> <input name="fname1" type="text" value="" /> Item 2</p>
<p> <input name="fname2" type="text" value="" /> Item 3</p>
<p> <input name="fname3" type="text" value="" /> Item 4</p>
<p> <input name="fname4" type="text" value="" /> Item 5</p>

I tidy things up later when complete
 
Each of those fields (submitted) is an entry in the superglobal $_POST array.
So it should be:
Code:
<?php

// This:

$_POST['fname0']; 
// Or 
$_POST['fname1'];
// Or
$_POST['fname2'];
// Or
$_POST['fname3'];
// Or
$_POST['fname4'];

?>
 
Back
Top