Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/247447-omit-null-fields-in-email/
Share on other sites

$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..

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.