首页 > 解决方案 > PHP:接收空白电子邮件

问题描述

我使用isset()了功能,这样我就不会收到空白电子邮件。我仍然可以收到空白电子邮件。

请看我的代码

!empty()优于isset()? _

两者有什么区别?

非常感谢

if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['phone'])){



$postcode = isset($_POST['postcode']) ? $_POST['postcode'] : "";
$name     = isset($_POST['name']) ? $_POST['name'] : "";
$email    = isset($_POST['email']) ? $_POST['email'] : "";
$phone    = isset($_POST['phone']) ? $_POST['phone'] : "";
$business = isset($_POST['business']) ? $_POST['business'] : "";

$to      = 'rme@btel.com';
$subject = "=?UTF-8?B?" . base64_encode('Message from BTelecom') . "?=";

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
@$message = '<!DOCTYPE html><html><body>' .


'Post Code: ' . strip_tags($postcode) . '<br/>' .
'Email: ' . strip_tags($email) . '<br/>' .
'Name: ' . strip_tags($name) . '<br/>' .
'Phone: ' . strip_tags($phone) . '<br/>' .
'Business: ' . strip_tags($business) . '' .

    '</body></html>';
    $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $result = mail($to, $subject, $message, $headers);

}

标签: php

解决方案


PHP函数只检查空白值,而另一方面isset检查变量是否存在。


推荐阅读