Forum Moderators: coopster

Message Too Old, No Replies

PHP form Mailer

Strong SPAM free mailer script and form

         

AlexB77

12:11 pm on Sep 6, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



HI to all,

I am in need to get a SPAM free PHP mailer script for use on my website in order to get visitors to send me comments or questions.

The php script that I use at the moment is using CAPTCHA and also send an e-mail back to the visitor, but somehow it got SPAMED. So I wonder if there is something that could be easy and secure for me to use to accomplish this task. I am not a programmer and do not know much about scripting.

Thanks to all who will decide to help me.

AlexB77

12:47 pm on Sep 6, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



I use the following script on my site, but I am not please with it since I have now got a lot of SPAM attacks. Is there any way to make it stronger?

<?php

require "includes/jconfig.php";
require "includes/functions.php";
require_once("class/globes.php");

###################
## Modified 5-11-2009
## fixed phpversion checker since
## it wasn't working properly.
$phpvers = phpversion();
$phpversion = substr($phpvers,0,1);
if ($phpversion > 4) {
require_once("class/htmlMimeMail5.php");
$smtp = new htmlMimeMail5();
} else {
$globes->usmtp = 0;
}
##############################
## PREVENT PERMISSION DENIED ERRORS ##
##############################
if(file_exists('ip.txt')) {
if(!is_writeable('ip.txt')) {
echo "Opps. ip text file is not writeable and I cannot continue. Please change permissions to 777 on ip text.";exit;
}
}
$getvars = $HTTP_GET_VARS;
$postvars = $HTTP_POST_VARS;
## Just leave all the variable passing as getvars .##
if(!$getvars) { $getvars = $postvars; }
if(!$getvars) { $getvars = $_POST; }
if(!$getvars) { $getvars = $_GET; }

######################
## STANDARD GLOBALS ##
######################
$globes->HTTP_USER_AGENT = getenv('HTTP_USER_AGENT');
$globes->date = date("$globes->date_format");
$globes->curtime = date("$globes->time_format");
$globes->ip = getenv("REMOTE_ADDR");
$globes->ref_url = getenv("HTTP_REFERER");
$referrers = split(",",$globes->referrers);
$globes->blocked_domains = str_replace(".","",$globes->blocked_domains);
$blocked_domains = split(",",$globes->blocked_domains);
##########################
## build the templates. ##
##########################
build_templates();

############################
## CHECK REFERERS FOR SPAM #
############################
## If a user puts your domain name as their email address
## chances are they are attempting to send spam through
## your script. Jim@yourdomain.com wouldn't use your contact
## form to send email to judy@yourdomain.com etc..
for($i=0;$i<=count($referrers);$i++) {
if($referrers[$i]) {
if(strstr($globes->ref_url,$referrers[$i])) {
$yep = "1";
}
##echo $refferers[$i] . "<BR>";
## Attempt to block spammers. ###
if(strstr($getvars['email'], $referrers[$i])) {
$globes->spam_alert = "t";
$globes->error = $globes->error_email_from_same_domain;
}
}
}

##########################
## CHECK BLOCKED DOMAINS #
##########################
for($i=0;$i<count($blocked_domains);$i++) {
## split the email after @ ##
$temp_email = split("@",$getvars['email']);
## get the domain extention ##
$temp_email1 = split("\.",$temp_email[1]);
## in case it's .co.uk
if(count($temp_email1) > 2) {
$temp_email1[1] = $temp_email1[2];
}
## if we find a blocked domain
if($temp_email1[1] == $blocked_domains[$i]) {
$globes->error .= $globes->error_invalid_domain;
$globes->extention = $blocked_domains[$i];
}

}
###########################
## because of firewalls, I've disabled referrers because
## it doesn't work for some users.
###############################
## CHECK IP ADDRESS FOR SPAM ##
###############################
# I wrote this part to only allow
# x amount of uses per day from a single
# IP address. If someone is using your
# contact form more than 1 or 2 times in a
# day, chances are they are sending spam.
## 9-20-05 ##
## Log everyones IP address into a
## plain text file once a day. ##
## 1-3-09 fixed IP CIP[3] was suppossed to be CIP[2]
## wasn't working at all.
####################
## 6-8-2010 above still doesn't work right ass.
## fixed line CIP3 .= instead of just =.

if(file_exists("ip.txt")) {

if(filesize("ip.txt") > 0) {
$contents = fopen("ip.txt","r");
$CIP= fread($contents, filesize("ip.txt"));
fclose($contents);
}
$CIP = split("\n",$CIP);
$X=0;
$cpcount = count($CIP);
$CIP3 = "";

while($X < $cpcount) {

$CIP2 = split("\|", $CIP[$X]);

####################
## Make sure line isn't blank. ##
if($CIP2[0]) {
## First. Let's see if it's been 24 hours or not.##
$stime = time();
$chkev_time = $stime - $CIP2[2];

###echo "$chkev_time";
# There's 86400 seconds in a day.
## if it has been 24 hours start the count over. #
if($chkev_time > 86400) {

##echo "$chkev_time ..$X. $stime " . $CIP2[2];exit;

$updolefile = fopen("ip.txt","w");
fwrite($updolefile,"");
fclose($updolefile);
}

}
#########################

# if there's something in the file go through it and try and find the users IP.##
if($CIP2[0] != "") {
## Ip is on the left side of the |
if($globes->ip == $CIP2[0]) {
## If I find that the user has in fact used the script today add 1 to their uses.
$CIP2[1]++;

$CIP3 .= "$CIP2[0]|$CIP2[1]|$CIP2[2]\n";
$globes->time2die = $CIP2[1];

##echo "$CIP3<BR>";

} else {

##echo "$CIP3<BR>";
##################
## 6-9-2010 made .= instead of =
## was causing only one IP to be stored. duh.
$CIP3 .= "$CIP2[0]|$CIP2[1]|$CIP2[2]\n";
}
}
$X++;

}

##################################
## never used the script today ##
## so place them in the ip file.##
##################################
if(!$globes->time2die) {
## Open IP file and then append to it. ##
$CIP3 .= "$globes->ip|1|" . time() . "\n";
$globes->time2die = 1;
}
## No matter what write to file.##
$updolefile = fopen("ip.txt","w");
fwrite($updolefile,"$CIP3");
fclose($updolefile);
}
##################
## END IP CHECK ##
##################

##########################
## if we were abused stop them here. ##
## I don't like being abused so go away. ##
##########################
if($globes->time2die > $globes->max_uses_per_day) {
$text = $globes->spam_alert_msg;
$text = translate_info($text,$getvars);
echo $text;
exit;
}

#################
## IF USING CAPTCHA! ##
#################
## if the user already sent headers or started a php session
## then don't start a session.
if(!headers_sent()) {
session_start();
}
if ($_SESSION['CAPTCHAString']) {
if ($_SESSION['CAPTCHAString'] != $getvars['captchastring']) {
$globes->error .= "$globes->error_invalid_captcha_string";
}
}
##########################
## CHECK SOME COMMON VARIABLES ##
##########################
$globes->email = $getvars['email'];
if($getvars['email_to_client_subject']) {
$globes->email_to_client_subject = $getvars['email_to_client_subject'];
}
if($getvars['email_to_admin_subject']) {
$globes->email_to_admin_subject = $getvars['email_to_admin_subject'];
}
if($getvars['req_fields']) {
$globes->req_fields = $getvars['req_fields'];
}
if($getvars['send_auto']) {
$globes->send_auto = strtolower($getvars['send_auto']);
if($globes->send_auto == "yes") {
$globes->send_auto = 1;
}
}

## no more reg express PHP filters now.
##if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $globes->ademail) || $globes->ademail == "you@yourdomain.com") {
if(!filter_var($globes->ademail, FILTER_VALIDATE_EMAIL) || $globes->ademail == "you@yourdomain.com") {
$globes->error .= "$globes->error_invalid_admin_address";
}

if(!filter_var($globes->email, FILTER_VALIDATE_EMAIL)) {
##if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $globes->email)) {
$globes->error .= "$globes->error_invalid_email_address";
}
##if($getvars['thank_you_page']) {
##$globes->thank_you_page = $getvars["thank_you_page"];
## }
###################
# CHECK REQUIRED FIELDS. #
###################
if($globes->req_fields) {
$req_fields = split(",",$globes->req_fields);
$X=0;
$rfields_count = count($req_fields);

while($X < $rfields_count) {
$error_required_field_empty = $globes->error_required_field_empty;

$temp_field = $req_fields[$X];
if($getvars[$temp_field] == "") {
$error_required_field_empty = str_replace("<:<FIELD_NAME>:>", $temp_field, $error_required_field_empty);
$globes->error .= "$error_required_field_empty";
}
$X++;
}
}
#############################
## END REQUIRED FIELD CHECK #
#############################

##########################
## CHECK HERE FOR MISUSE #
##########################
spam_check($getvars);

########################
## If any errors then ##
## stop them here. ##
########################
if($globes->error) {
##3-19-09
if($globes->use_ajax == 1) {
$text = $globes->error;
} else {
$text = $globes->default;
}
$text = translate_info($text,$getvars);
echo $text;
exit;
}
#######################
## ERROR CHECK DONE! ##
#######################

###########################
## PREPARE TO SEND EMAIL ##
###########################
$email_msg = $globes->auto_response;
$email_msg = translate_info($email_msg,$getvars);
$email_msg = stripslashes($email_msg);
if($globes->send_html_email == 1) {
$email_msg = str_replace("\n","<br>",$email_msg);
}
##subject
$email_subject = $globes->email_to_client_subject;
$email_subject = translate_info($email_subject,$getvars);
$email_subject = stripslashes($email_subject);
##administrative subject
$email_admin_subject = $globes->email_to_admin_subject;
$email_admin_subject = translate_info($email_admin_subject,$getvars);
$email_admin_subject = stripslashes($email_admin_subject);
##admin message
$email_admin_msg = $globes->admin_auto_response;
$email_admin_msg = translate_info($email_admin_msg,$getvars);
$email_admin_msg = stripslashes($email_admin_msg);
if($globes->send_html_email == 1) {
$email_admin_msg = str_replace("\n","<br>",$email_admin_msg);
}

##########################
## USE SMTP SERVER CLASS FUNCTION ##
##########################
if($globes->usmtp == 1) {

$type = "smtp";
#####################
## SEND PARAMETERS ##
$smtp->setSMTPParams($globes->host,$globes->port,$globes->helo,$globes->auth, $globes->smtpuser, $globes->smtppass);
#####################

##########################
## SEND EMAIL TO ADMIN ###
##########################
$smtp->setFrom("$globes->email");
$smtp->setSubject("$email_admin_subject");
$smtp->setReturnPath("$globes->ademail");
################################
## html or regular text email.##
################################
if($globes->send_html_email == 1) {
$smtp->setHTML("$email_admin_msg");
} else {
$smtp->setText("$email_admin_msg");
}

##$mail->addAttachment(new fileAttachment('example.zip', 'application/zip', new Base64Encoding()));

if(!$smtp->send(array("$globes->ademail"),"$type")) {
#############################################
## Add Any Errors to global Errors variable.#
$smtperrors = $smtp->errors;
for($i=0;$i<count($smtperrors);$i++) {
$globes->error .= $smtperrors[$i] . "\n";
}
}

########################
## If any errors then ##
## stop them here. ##
########################
if($globes->error) {
if($globes->use_ajax == 1) {
$text = $globes->error;
} else {
$text = $globes->default;
}
$text = translate_info($text,$getvars);
echo $text;
exit;
}
############################
## IF sending autoresponse #
############################
if($globes->send_auto == 1) {
##########################
## SEND EMAIL TO CLIENT ###
##########################
$smtp->setFrom("$globes->ademail");
$smtp->setSubject("$email_subject");
$smtp->setReturnPath("$globes->ademail");
################################
## html or regular text email.##
################################
if($globes->send_html_email == 1) {
$smtp->setHTML("$email_msg");
} else {
$smtp->setText("$email_msg");
}
###########################
if(!$smtp->send(array("$globes->email"),"$type")) {
#############################################
## Add Any Errors to global Errors variable.#
$smtperrors = $smtp->errors;
for($i=0;$i<count($smtperrors);$i++) {
$globes->error .= $smtperrors[$i] . "\n";
}
}
}
########################
## If any errors then ##
## stop them here. ##
########################
if($globes->error) {
if($globes->error == 1) {
$text = $globes->error;
} else {
$text = $globes->default;
}
$text = translate_info($text,$getvars);
echo $text;
exit;
}

################################
## SEND VIA PHP mail function ##
} else {

###################
## BUILD HEADERS ##
###################
$adminmailheaders = "From: $globes->email\n";
if($globes->ccemail) {
$adminmailheaders .= "Cc: $globes->ccemail\n";
}
if($globes->bccemail) {
$adminmailheaders .= "Bcc: $globes->bccemail\n";
}
$adminmailheaders .= "Reply-To: $globes->email\n";

$mailheaders = "From: $globes->email\n";
$mailheaders .= "Reply-To: $globes->email";

if($globes->send_html_email == "1") {
$mailheaders .= "MIME-Version: 1.0\n";
$mailheaders .= "Content-type: text/html; charset=iso-8859-1\n";
$adminmailheaders .= "MIME-Version: 1.0\n";
$adminmailheaders .= "Content-type: text/html; charset=iso-8859-1\n";
}

###############
# Email Admin #
##echo "$globes->ademail,$email_admin_subject,$email_admin_msg,$adminmailheaders";
mail($globes->ademail,$email_admin_subject,$email_admin_msg,$adminmailheaders);

###################
# Email customer. #
###################
if($globes->send_auto == 1) {
mail($globes->email,$email_subject,$email_msg,$mailheaders);
}

}
######################################
## DONE EMAILING NOW SAY THANK YOU! ##
######################################


$text = $globes->thanks;
$globes->form_contents = str_replace("\n","<BR>",$globes->form_contents);
$text = translate_info($text,$getvars);
###########
## 1-3-2009
## thank you page is HTML
echo $text;
exit;
##}
###############
## ALL DONE! ##
###############

?>

morehawes

12:52 pm on Sep 9, 2010 (gmt 0)

10+ Year Member



The php script that I use at the moment is using CAPTCHA


Is this using reCAPTCHA [google.com...] ?

I use this on a few of my sites and it seems to keep pretty much everything out. Also very easy to integrate.

AlexB77

4:26 pm on Sep 9, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks for your suggestion, I will try to use it too, but can I some how integrate it with this script or do I need to create another form for it?

What I need is basically a simple form that can send comments to me as well as to the customer who's using it and be SPAM free with use of reCaptcha as you have suggested. If you have any similar script please share it with me.

Regards