This the code I use to build my email message body:
[PHP]//Build Message Body from Contact Form
foreach ($_POST as $Field=>$Value)
//Check for NOT Empty Fields
if(!empty($Valu e)) {
$MsgBody .= "$Field: $Value\n";
}[/PHP]
This is the body content of the sent email. At the bottom are the reCaptcha fields that I do not want to send:
First_Name:...
User Profile
Collapse
-
Get rid of reCaptcha fields in emails
How do I get rid of reCaptcha fields that are emailed when I submit a form? I guess what I am asking is how do you exclude unwanted fields from being posted to email from a form in PHP?
Thanks,
Kenny -
Just to help the next person. This is the code that worked for me. Thanks!
foreach ($_POST as $field=>$value)
if(!strlen(trim ($vlaue)) < 1) {
$message .= "$field: $value\n";
}
mail($to, $subject, $message);Leave a comment:
-
Excluding form fields if values are empty
I have created a form that I email the submitted results to an email address. The form has several optional fields that I would like to exclude from the sent email if they are empty. Below is the PHP code that I am using now.
foreach ($_POST as $field=>$value)
$message .= "$field: $value\n";
mail($to, $subject, $message);
No activity results to display
Show More
Leave a comment: