这是一个安全的PHP邮件功能吗?

Eys*_*ein 0 php security email

终于得到了这个PHP电子邮件脚本工作(不能在localhost上工作......),但我担心的是它不安全.

那么 - 这对于垃圾邮件以及我不知道的任何其他安全隐患是否安全?

<?php
$email = 'notification@domain.com';
$subject = 'Notify about stuff';
$notify = $_REQUEST['email'];

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $notify)) {
    echo "<h4>Your email address doesn't validate, please check that you typed it correct.</h4>";
    echo "<a href='javascript:history.back(1);'>Back</a>";
}

elseif(mail($email, $subject, $notify)) {
    echo "<h4>Thank you, you will be notified.</h4>";
} else {
    echo "<h4>Sorry, your email didn't get registered.</h4>";
}
?>
Run Code Online (Sandbox Code Playgroud)

不相关:我可以使用PHP函数而不是javascript:history.back(1)吗?

编辑:使用过滤器而不是RegEx 的脚本

<?php
$email = 'notification@domain.com';
$subject = 'Notify about stuff';
$notify = $_REQUEST['email'];

if (!filter_var($notify, FILTER_VALIDATE_EMAIL)) {
    echo "<h4>This email address ($notify) is not considered valid, please check that you typed it correct.</h4>";
    echo "<a href='javascript:history.back(1);'>Back</a>";
}

elseif(mail($email, $subject, $notify)) {
    echo "<h4>Thank you, you will be notified.</h4>";
} else {
    echo "<h4>Sorry, your email didn't get registered.</h4>";
}
?>
Run Code Online (Sandbox Code Playgroud)

Gal*_*len 5

我不知道id是否$_SERVER['HTTP_REFERER']用来回去.我觉得这可以让你受到攻击,因为它是通过请求设置的.这样做的方法是使用上一页的会话.这样您就不会将不值得信任的数据转储到您的网站上.

我没有看到任何安全风险,但我想在检查电子邮件的有效性时建议使用过滤器.它比弄乱RE更容易.