dongzhuji1042 2018-05-17 06:19
浏览 28
已采纳

PHP:收到空白电子邮件

I used isset() function so that I will not receive the blank email. I can still receive blank emails.

Please see my code

Is !empty() better than isset() ?

What is the difference between the two?

Many Thanks

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
";
$headers .= "Content-type: text/html; charset=utf-8
";
@$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条回答 默认 最新

  • doukun8944 2018-05-17 06:38
    关注

    PHP empty function just checks the blank value while on other side isset checks for variable existence.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗