我有一个预订脚本,运行正常并将内容放入数据库。但是,当我希望管理员在预订时发送电子邮件时,我希望在用户未填写电子邮件时将其留空。
例如,用户输入他的姓名,电子邮件,日期等,但是将字段的姓氏和评论留空,我不希望在电子邮件中输出。
我试过
if(isset($_POST['Lastname'])){
$Lastname=$_POST['Lastname'];
} else {
$Lastname="The user didn't input his lastname";
}
我尝试使用empty()。
我知道这是方法,但我不知道放在哪里。
这是我的代码。
if (isset($_POST['submit']))
{
include('../../../wp-config.php');
$Naam=$_POST['Naam'];
$Achternaam=$_POST['Achternaam'];
$Omgeving=$_POST['Omgeving'];
$Geslacht=$_POST['Geslacht'];
$Bedrijfsnaam=$_POST['Bedrijfsnaam'];
$Postcode=$_POST['Postcode'];
$Adres=$_POST['Adres'];
$Woonplaats=$_POST['Woonplaats'];
$Teloverdag=$_POST['Teloverdag'];
$Teldirect=$_POST['Teldirect'];
$Email=$_POST['Email'];
$Aantal=$_POST['Aantal'];
$Datum=$_POST['Datum'];
$Vanuur=$_POST['Vanuur'];
$Vanminuut=$_POST['Vanminuut'];
$Totuur=$_POST['Totuur'];
$Totminuut=$_POST['Totminuut'];
$Opmerkingen=$_POST['Opmerkingen'];
$Nieuwsbrief=$_POST['Nieuwsbrief'];
$Datumverzonden=$_POST['Datumverzonden'];
$Status=$_POST['Status'];
if (!$error) {
require_once('phpMailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->From = $email;
$mail->FromName = $name;
$mail->Subject = "Website Reserveringsformulier Form";
$mail->AddAddress($site_owners_email, $site_owners_name);
$mail->AddAddress('mail@gmail.com', 'Name');
$mail->IsHTML(true);
$mail->Body = "<font size='5'>Beste Zomerlust</font>" . "\r\n<br /><br /> " . "Er is een reservering geplaats via restaurantzomerlust.nl." . "\r\n<br /><br />";
$mail->Body .= "<b>Naam: </b>" . $Naam . "\r\n<br />";
$mail->Body .= "<b>Achternaam: </b>" . $Achternaam . "\r\n<br />";
$mail->Body .= "<b>E-mail: </b>" . $Email . "\r\n<br /><br />";
$mail->Body .= "<b>Reservering: </b>" . $Omgeving . "\r\n<br /><br />";
$mail->Body .= "<b>Aanhef: </b>" . $Geslacht . "\r\n<br /><br />";
$mail->Body .= "<b>Bedrijfsnaam: </b>" . $Bedrijfsnaam . "\r\n<br />";
$mail->Body .= "<b>Postcode: </b>" . $Postcode . "\r\n<br />";
$mail->Body .= "<b>Adres: </b>" . $Adres . "\r\n<br />";
$mail->Body .= "<b>Woonplaats: </b>" . $Woonplaats . "\r\n<br /><br />";
$mail->Body .= "<b>Tel. overdag: </b>" . $Teloverdag . "\r\n<br />";
$mail->Body .= "<b>Tel. direct: </b>" . $Teldirect . "\r\n<br /><br />";
$mail->Body .= "<b>Aantal persronen: </b>" . $Aantal . "\r\n<br />";
$mail->Body .= "<b>Datum: </b>" . $Datum . "\r\n<br />";
$mail->Body .= "<b>Van: </b>" . $Vanuur . ":" . $Vanminuut . " tot " . $Totuur . ":" . $Totminuut . "\r\n<br /><br />";
$mail->Body .= "<b>Opmerkingen: </b>" . $Opmerkingen . "\r\n<br /><br />";
$mail->Body .= "<b>Nieuwsbrief: </b>" . $Nieuwsbrief . "\r\n<br />";
$mail->Send();
} # end if no error
else {
}
还有一点:每当发送电子邮件时,数据也会存储在数据库中。我该怎么做才能为数据库实现相同的效果。因此,如果未设置任何内容,则数据应为“无设置”或其他内容。
我希望你们明白。
答案 0 :(得分:0)
怎么样
if(isset($_POST['Lastname'])){
$Lastname=$_POST['Lastname'];
} else if ($_POST['Lastname'] == ''){
$Lastname="The user didn't input his lastname";
}else{
$Lastname="The user didn't input his lastname";
}