PHP:收到空白电子邮件

时间:2018-05-17 06:19:57

标签: 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);

}

1 个答案:

答案 0 :(得分:2)

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