Jump to content

Recommended Posts

I've recently come across a problem with email injection, and the injection of additional email headers in my contact page. I'm a bit rusty with PHP, I found this function on the web to prevent it:

 

 
<?php
//email injection prevention function

function mailcheck($input) {
if (eregi(”\r”, $input) ||
eregi(”\n”, $input) ||
eregi(”%0a”, $input) ||
eregi(”%0d”, $input) ||
eregi(”Content-Type:”, $input) ||
eregi(”bcc:”, $input) ||
eregi(”to:”, $input) ||
eregi(”cc:”, $input)) {
return true;
} else {
return false;
}
}

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

Now, that's what I've got so far on my new script. How can I alert a message box notifying of illegal characters if mailcheck returns false, and allow it to mail if it returns true? Thanks in advance  :P

Link to comment
https://forums.phpfreaks.com/topic/120618-solved-email-injection/
Share on other sites

Nine times out of ten (or more), email injections are coming from programs, not people. Don't even bother with an error message, just end your script. The programs are made by hackers who screen scraped your generated source.

 

Ken

Nine times out of ten (or more), email injections are coming from programs, not people. Don't even bother with an error message, just end your script. The programs are made by hackers who screen scraped your generated source.

 

Ken

 

Yeah, I know. Here is my more secure script:

 

<?php
function mailcheck($input) {
if (eregi(”\r”, $input) ||
eregi(”\n”, $input) ||
eregi(”%0a”, $input) ||
eregi(”%0d”, $input) ||
eregi(”Content-Type:”, $input) ||
eregi(”bcc:”, $input) ||
eregi(”to:”, $input) ||
eregi(”cc:”, $input)) {
return true;
} else {
return false;
}
}
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$msg = "Name: $name<br>Email Address: $email<br>Message: $message";

if(!mailcheck($email) || !mailcheck($email))
die();
else
{
mail("email@email.com","Website Inquiry",$msg);
header('location: index.htm');
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.