PDA

View Full Version : php help with form mail



built_by
December 13th, 2005, 08:54 PM
alright i made a survey for my site and I can't seem to figure out the send email php stuff. I get the email when i click submit but it only shows the "comments" and I dont know how to set up the other sections (listed below). I also included the bottom part of the php code, so how do i recieve the rest of the areas?

Favorite- list/menu
Visit- list/menu
Newsletter- checkbox
and then Navigation (set of radio buttons) which is not shown in the php code.
please help.


// -------------------- END OF CONFIGURABLE SECTION ---------------
$name = $_POST['first_name'] ;
$surname = $_POST['last_name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$favorite = $_POST['favorite'] ;
$visit = $_POST['visit'] ;
$newsletter = $_POST['newsletter'] ;
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
header( "Location: $errorurl" );
exit ;
}
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
$messageproper =
"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;
mail($mailto, $subject, $messageproper, "From: \"$name\" \"$surname\"<$email>\nReply-To: \"$name\" \"$surname\" <$email>\nX-Mailer: chfeedback.php 2.03" );
header( "Location: $thankyouurl" );
exit ;
?>

built_by
December 13th, 2005, 09:58 PM
please help!

Ankou
December 14th, 2005, 01:37 AM
What do you mean when you say that you "dont know how to set up the other sections"?

Are you referring to how to get the data in PHP or to use it an include it in the email?

list/menu (select/option) should always submit a value -- well they should because it's a good idea to set one of the options as selected (like Red is below).


<select name="color">
<option value="red" selected="selected">Red</option>
<option value="blue">Blue</option>
<option value="gress">Greed</option>
</select>

So with PHP all you need is:


$color = $_POST['color'];


With radio buttons it's the same thing. Make sure one is selected (checked).


Are you over 18?
<input type="radio" name="over18" value="yes" checked="checked" />Yes
<input type="radio" name="over18" value="no" />No


Again with PHP all you need is:


$over18 = $_POST[over18'];

With checkboxes it's a different story because typically they're used for optional items. If the box is checked it'll be included with the information passed by the form. If not checked it will not be sent. Because of that it's a good idea to use PHP's isset() function.


if(isset( $_POST['newsletter'])){
$newletter = $_POST['newsletter'];
}else{
$newsletter = "";
// Or set $newsletter to whatever you want that will help you remember
// that the checkbox was not selected.
}


Once you have all that information you'll want to build your email. You'll want to add those other parts to the $messageproper variable. I'm not sure how you want that information set up, so this is just a sample:



$messageproper =
"This message was sent from:\n" .
"$name $surname ($email)\n" .
"$http_referrer\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments . "\n" .
$favorite .
$visit .
$newsletter .
"\n\n------------------------------------------------------------\n" ;



Probably over explained things a bit, but I was sure what you wanted and I had some time to kill. :)

built_by
December 14th, 2005, 09:04 AM
wow, thanks a ton.

Ankou
December 14th, 2005, 12:58 PM
No problem, I hope that at least part if it was what you needed.