cruizefest Posted September 19, 2011 Share Posted September 19, 2011 Below is the code I'm using, and I would like for when the information is sent to email that it omits empty fields including the field name. I'm not real sure on how to do this. Any help would be great!!!! Thanks!!!!! ]<?php $SendFrom = "Form Feedback <feedback@yourdomain.com>"; $SendTo = "feedback@yourdomain.com"; $SubjectLine = "Feedback Submission"; $ThanksURL = "thanks.html"; //confirmation page foreach ($_POST as $Field=>$Value) $MsgBody .= "$Field: $Value\n"; $MsgBody .= "\n" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n" . $_SERVER["HTTP_USER_AGENT"]; $MsgBody = htmlspecialchars($MsgBody, ENT_NOQUOTES); //make safe mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom"); header("Location: $http://www.yourdomain.org"); ?> [/code Quote Link to comment https://forums.phpfreaks.com/topic/247447-omit-null-fields-in-email/ Share on other sites More sharing options...
AyKay47 Posted September 19, 2011 Share Posted September 19, 2011 in your foreach loop you will want to go about this logic this way.. if(!empty($Value)){ // execute foreach code } Quote Link to comment https://forums.phpfreaks.com/topic/247447-omit-null-fields-in-email/#findComment-1270713 Share on other sites More sharing options...
cruizefest Posted September 19, 2011 Author Share Posted September 19, 2011 I'm sorry, I'm completely new to this. Could you repost my code with the corrections. Thank you!!!! Quote Link to comment https://forums.phpfreaks.com/topic/247447-omit-null-fields-in-email/#findComment-1270718 Share on other sites More sharing options...
AyKay47 Posted September 19, 2011 Share Posted September 19, 2011 $SendFrom = "Form Feedback <feedback@yourdomain.com>"; $SendTo = "feedback@yourdomain.com"; $SubjectLine = "Feedback Submission"; $ThanksURL = "thanks.html"; //confirmation page foreach ($_POST as $Field=>$Value){ if(!empty($Value)){ $MsgBody .= "$Field: $Value\n"; $MsgBody .= "\n" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n" . $_SERVER["HTTP_USER_AGENT"]; } } $MsgBody = htmlspecialchars($MsgBody, ENT_NOQUOTES); //make safe mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom"); header("Location: $http://www.yourdomain.org"); also, I see that you are using a lot of capital letters in your variable names.. word of caution.. variable names are case sensitive.. so $Variable does not equal $variable.. I normally always use lower case characters in my variables.. Quote Link to comment https://forums.phpfreaks.com/topic/247447-omit-null-fields-in-email/#findComment-1270722 Share on other sites More sharing options...
cruizefest Posted September 19, 2011 Author Share Posted September 19, 2011 I just wanted to say thank you so much!!!!! It worked!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/247447-omit-null-fields-in-email/#findComment-1270737 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.