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 <[email protected]>"; $SendTo = "[email protected]"; $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 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 } 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!!!! 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 <[email protected]>"; $SendTo = "[email protected]"; $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.. 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!!!!! 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
Archived
This topic is now archived and is closed to further replies.