Safe Mail

Started on the old forum in June 2008 · view the original in the archive · old links redirect here

2 replies · 553 views · started 18 years ago · 1 min read

2 participants
alesh Lead · 604 posts #1

in every email script tht i downloaded here, i saw no security....

mail($_POST['to'], $_POST['subject'], $_POST['message'], "From: ". $_POST['from']");

smart person cn easily use it 4 own purpose....

its nt tht he/she cn hack ur site but u c get in trouble..... THINK!!! it cn b easily type ur email in field From and send viruses 2 others.....

so u cn use this 2 protect ur email script

1st u need a simple function

function safemail ($header) {
$header = str_replace ("\n", "\", $header); // changes every \n into nullbyte
$header = str_replace ("\r", "\", $header); // changes every \r into nullbyte
return $header;
}

and then use it 4 ur email script

$to = $_POST['to'];
$subject = $_POST['subject'];
$message = htmlspecialchars($_POST['message']);   //<------ c changes here
$header = "From: ". safemail ($_POST['from']);        //<------ and here

mail ($to, $subject, $message, $header);

if sum1s knw more plz share it..

eeeeerrr....

subzero Super moderator Fellow · 3,954 posts #2

Nice idea there bro

also can use this

function is_from_valid($from) {
  if(eregi("^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $from)) return TRUE;
  else return FALSE;
} 

if (is_from_valid($from))
{
$mailok = "";
}else{ 
$mailok = "";
echo "Unfortunately Your E-Mail is [b]Not A Valid Address[/b], Please Use Your Browsers Back Button And Re-Complete The Form";
echo "
<a href=\"index.php?action=a\">Back</a>
";
echo "</div>";
echo "</body>";
echo "</html>";
exit();
}

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

Guest #3

the best way is to use this:

function tikrinti_emaila($emailas) { if(preg_match('/^\w[-.\w]@(\w[-._\w].[a-zA-Z]{2,}.*)$/', $emailas, $matches)) { if(function_exists('checkdnsrr')) { if(checkdnsrr($matches[1] . '.', 'MX')) return true; if(checkdnsrr($matches[1] . '.', 'A')) return true; } else { if(!empty($hostName)) { if( $recType == '' ) $recType = "MX"; exec("nslookup -type=$recType $hostName", $result); foreach ($result as $line) { if(eregi("^$hostName",$line)) { return true; } } return false; } return false; } } return false; }

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close