Page 1 of 1

PHP - Form Mail Help for a rookie

Posted: Thu Jun 02, 2005 10:20 am
by Asheron
I need help with the below script. 2 things I need;
1) I need this script to check whether there is data in a field before adding that field to the message (considering using an if else on it after it pulls the content but before it adds to message)
2) I need to know how to use this script to also add values from a form select field

Code: Select all

<?php
foreach ($_POST as $Field=>$Value)
   $MsgBody .= "$Field: $Value\n";
$MsgBody .= "$Divider\n" . $_SERVER["HTTP_USER_AGENT"] . "\n";
$MsgBody = htmlspecialchars($MsgBody);  //make content safe
?>

Posted: Thu Jun 02, 2005 11:17 am
by neophyte

Code: Select all

<?php
foreach ($_POST as $Field=>$Value)
   $MsgBody .= "$Field: $Value\n";
$MsgBody .= "$Divider\n" . $_SERVER["HTTP_USER_AGENT"] . "\n";
$MsgBody = htmlspecialchars($MsgBody);  //make content safe

?>

Add something like this to the code:

Code: Select all

//Check to make sure they're not empty vaues:
if(!empty($val){
 //Add to body message
}
The form select values should appear if there is a value. Leastwise the will be in the POST array.

Posted: Thu Jun 02, 2005 12:35 pm
by Asheron
Appreciate it very much thanks.