php - 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空函数只检查空白值,而另一方面isset检查变量是否存在。
推荐阅读
- conv-neural-network - 如何在pytorch的MultiClass分类模型中预测标签?
- python - Flask - 如何按类型检索输入的值?
- spring-integration - How to pass object associated with message past outbound channel adapter
- python - 如何为单元测试套件做一个设置
- javascript - 让光标出现在输入焦点上
- opengl - 无法在 Opengl 2.x 中正确配置顶点属性
- hyperledger-fabric - Hyperledger Fabric - collections_config.json 不尊重私有数据收集
- reactjs - React Router 在组件之间共享数据
- html - 如何使我的菜单正确响应
- c - 拆分字符串