我每天大约在同一小时收到空白电子邮件,并且php邮件程序中出现未定义的变量错误,我该怎么办才能解决? 我的页面有2种不同的表格。
我试图将其添加到我的php中:if(isset($ _ POST)){},添加之后,我仍然出现空白,但现在的错误是在不同的行上。现在我的错误是因为$ email_subject $ email_body第35,36行。
这是错误日志:
[2019年9月19日19:26:50 UTC] PHP注意:未定义的变量:第35行的/home/user/public_html/mail/mailer.php中的名称 [2019年9月19日19:26:50 UTC] PHP注意:未定义的变量:/home/user/public_html/mail/mailer.php在第36行的名称
我的PHP:
if (isset($_POST['name'])) {
$name = $_POST['name'];
}
if (isset($_POST['fname'])) {
$fname = $_POST['fname'];
}
if (isset($_POST['lname'])) {
$lname = $_POST['lname'];
}
if (isset($_POST['email'])) {
$email = $_POST['email'];
}
if (isset($_POST['tel'])) {
$tel = $_POST['tel'];
}
if (isset($_POST['address'])) {
$address = $_POST['address'];
}
if (isset($_POST['project'])) {
$project = $_POST['project'];
}
if (isset($_POST['message'])) {
$message = $_POST['message'];
}
$to = '';
$email_subject = "$fname $lname $name Contact You from :";
$email_body = "You have received a new message from your website contact form.<br/>"."Here are the details:<br/><br/> Name: $fname $lname $name<br/> Email: $email<br/> Phone: $tel<br/> Address: $address<br/> Project: $project<br/> Message:\n$message";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . "\r\n";
$headers .= 'Reply-To: ' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$name = $fname = $lname = $email = $tel = $address = $project = $message = '';
if(mail($to,$email_subject,$email_body,$headers)) {
echo "OK";
}
答案 0 :(得分:0)
我没有看到错误消息,所以我猜不是所有字段都被填写了,所以您需要在检查变量是否设置之前将它们默认为默认值:
$name = $fname = $lname = $email = $tel = $address = $project = $message = '';