Jump to content

Secure Php Mail()


scotttyz

Recommended Posts

trying to secure form submited info to disalow spammers. Any other PHP'ers out there with suggestions??

 

><?php

// set up variables
$redirect = "thanks.url"; \\your thank you URL
$subject  = "Enter a subject here"; \\your subject
$mailingto = "you@******"; \\hardcoded to: field
$headers = "From: webserver@******\r\n" . "Reply-to: webserver@******\r\n" . "X-Mailer: PHP-" . phpversion(); \\change who you want the emails from
$message = ""; \\just clearing anything a spammer tried to pass
$tmessage = ""; \\just clearing anything a spammer tried to pass
$securemessage ""; \\just clearing anything a spammer tried to pass
$welcome = "enter message to send to form submittal recipient \n" \\start your email
$footer = "this will apear after the form data\n" \\ this will end the email

//parse form submittal - enters each field submitted on a new line "name : value"
foreach($HTTP_POST_VARS as $key => $value)
{
$message .= $key ." : " .$value ."\n";
}

//eliminate any email at's
$securemessage = srt_replace('@', "at", $message);

//build email
$tmessage = "$welcome\n\n$message\n$footer";
$ret = mail($mailingto, $subject, $securemessage ,$headers);

//make sure we sent email and redirect
if ($ret) {
header("Location: $redirect");
} else {
echo('<h1>Enter your WOOPS form did not work here</h1>');
}
?>

 

I have not checked the script yet, but wanted to get some input. I am aware of some spammers trying to send cc:'s thru form subbmitions and want to make a simple php script that had every place there could be an email either hardcoded or check and remove any @'s. Thoughts? Suggestions? Martini's??

Link to comment
Share on other sites

Thanks for the input Charlie. Unfortunately I have 2 php scripts that do other things in addition to sending out an email (append or modify a .htaccess style file) and it would take way to much work to try to include a script like that into my pages, but thanks for the info on a secure PHP form mailer!! Rock Sign

Link to comment
Share on other sites

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...