security - How to block spam mails in inbox using php -
i have coded contact form , process page 1 of client in php
when user submits form mail generated , redirected clients inbox
here im getting terrible hundreds of unknown spam mails @ end of day, don't know generating from,
due our website in danger being added in blacklist on google , other search engines
can please give me solution block spam mails , please find attachment php mail code
below php code
<?php if($_server['request_method'] == "post") { $email = $_post["email"]; $to = "test@myaddress.com"; $cname = htmlentities(ucfirst($_post['name'])); $subject = "subject comes here"; $body= "name : "; $body.= $cname; $body .= "\ne-mail : "; $body .= htmlentities($_post['email']); $body.= "\nmessage : "; $body.= htmlentities($_post['message']); function is_valid_email($email) { return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email); } function contains_bad_str($str_to_test) { $bad_strings = array( "content-type:" ,"mime-version:" ,"multipart/mixed" ,"content-transfer-encoding:" ,"bcc:" ,"cc:" ,"to:" ); foreach($bad_strings $bad_string) { if(eregi($bad_string, strtolower($str_to_test))) { header('location: status.php?status=failed'); } } } function contains_newlines($str_to_test) { if(preg_match("/(%0a|%0d|\\n+|\\r+)/i", $str_to_test) != 0) { header('location: status.php?status=failed'); } } if (!is_valid_email($email)) { header('location: status.php?status=failed'); } contains_bad_str($email); contains_bad_str($subject); contains_bad_str(body); contains_newlines($email); contains_newlines($subject); $headers = "from: $email"; mail($to, $subject, $body, $headers); header('location: status.php?status=success'); } ?>
use captchas prevent spam bots abusing contact form , ensure human beings can use it.
Comments
Post a Comment