У меня есть электронная почта, которая работает отлично. Я хотел бы добавить функцию, которая, если определенные поля не заполнены, не отправляет их пустым в электронном письме. Как я могу заставить эти поля не появляться, если они не заполнены. Вот мой полный код.Условно добавление к строке в PHP
$message = 'Hello,<br /><br />
First Name: '.$_POST['first_name'].'<br />
Last Name: '.$_POST['last_name'].'<br />
Email: '.$_POST['email'].'<br />
Address: '.$_POST['address'].'<br />
Phone: '.$_POST['phone'].'<br />
City: '.$_POST['city'].'<br />
State: '.$_POST['state'].'<br />
Zip Code: '.$_POST['zipcode'].'<br />
Country: '.$_POST['country'].'<br />
Preferred Method of Contact: '.$_POST['perferred'].'<br />
Comments/Questions:<br />
'.$_POST['description'].'<br /><br />
//This is the section I am speaking about
Interested in: <br />
'.$_POST['nh_home'].'<br />
'.$_POST['nh_lot'].'<br />
'.$_POST['nh_townhouse'].'<br />
'.$_POST['nh_condo'].'<br />
'.$_POST['nh_marina'].'<br />
'.$_POST['nh_beachclub'].'<br />
'.$_POST['nh_resale'].'<br /><br />
// End Section
How did you hear about us? <br />
'.$_POST['how_about'].'<br />
;
$to = '[email protected]';
$subject = 'Splash Page';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: Meredith Bay <[email protected]>' . "\r\n";
$send = mail($to, $subject, $message, $headers);
if($send){
header('Location: http://www.website.com/thank-you/');
exit;
}
else{
echo "error";
}
Спасибо, что помогли работать как шарм – user3158563