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)