您好,我已经构建了一个电子邮件表单,我想知道它是否以安全的方式构建。
我已阅读文章如何防止 PHP 表单中的电子邮件注入到邮件脚本并将其应用于我的脚本。现在我想知道变量 $to 和 $bcc 是否已保存。
function sendmail($to,$subject,$message,$bcc=NULL){
//Prevent Email Injection in Your PHP Form to Mail Scripts
if ( preg_match( "/[\r\n]/", $to ) || preg_match( "/[,]/", $to ) || preg_match( "/[\r\n]/", $bcc ) || preg_match( "/[,]/", $bcc ) ) {
return '<h1>Danger found: possible email Injection Hijacking</h1>';
return false;
}else{
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: No Reply <no-reply@domain.nl>' . "\r\n";
if(isset($bcc)) $headers .= 'Bcc: ' .$bcc."\r\n";
// Mail it
return mail($to, $subject, $message, $headers);
}
}
sendmail($_REQUEST['email'],'Subjectline', 'message','admin@domain.com');