I am new to PHP. This is my code from our mailing.php. When a user submits a request, there are 5-7 select-able fields and 20-25 fields that end up not being selected. The o
Just before foreach loop you should use this
$_POST = array_filter($_POST);
Another option is to use a conditional inside foreach loop
foreach($_POST as $key=>$value)
if ($value != '' && $value != null)
$body .= $key . ": " . $value . "\r\n";
You can try this
if($_POST && count($_POST)) {
$_POST = array_filter($_POST);
$body = '';
foreach($_POST as $key=>$value)
$body .= $key . ": " . $value . "\r\n";
mail("email@email.com", "Email Received at email@email.com", $body);
OR
if($_POST && count($_POST)) {
$body = '';
foreach($_POST as $key=>$value){
$trim_value = trim($value);
if (!empty($trim_value)){
$body .= $key . ": " . $value . "\r\n";
}
}
mail("email@email.com", "Email Received at email@email.com", $body);