我有一個電子郵件表單工作得很好。我想添加一個功能,如果某些字段沒有填寫,它不會在電子郵件中發送它們爲空。如果這些字段沒有填寫,我怎樣才能讓這些字段不顯示。這是我的完整代碼。有條件地附加到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 2014-09-30 20:34:31