PHP - Form Mail Help for a rookie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Asheron
Forum Newbie
Posts: 3
Joined: Thu Jun 02, 2005 10:06 am

PHP - Form Mail Help for a rookie

Post 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
?>
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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.
Asheron
Forum Newbie
Posts: 3
Joined: Thu Jun 02, 2005 10:06 am

Post by Asheron »

Appreciate it very much thanks.
Post Reply