Irish SEO,  Marketing & Webmaster Discussion

 
Chitika Malls

Need a good formmail script

This is a discussion on Need a good formmail script within the Coding Help forums, part of the Webmaster Help category; Hey guys, As the subject implies, I'm looking for a decent script (php/perl) that'll mail form data. I'm looking for ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help

Register Forum Rules FAQDonate Members List Calendar Search Today's Posts Mark Forums Read


Notices

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 21-03-2007, 11:32 PM
404 username not found's Avatar
Undefined offset:
 
Join Date: Jan 2007
Location: localhost
Posts: 69
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
404 username not found will become famous soon enough
Question Need a good formmail script

Hey guys,
As the subject implies, I'm looking for a decent script (php/perl) that'll mail form data.
I'm looking for something that's generally regarded as being secure/safe against abuse, and something that's adaptable and customisable without a lot of crap.
I don't want to be stuck with error/received pages that have the script-writers life story on them... or have to configure the script with lots of lame "hidden" form fields.
I'm not happy with the ones I've used, and am sorely tempted to write my own.

Any recommendations (even if they don't fit the above criteria)?
Basically I'm wondering what everyone else is using.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 22-03-2007, 12:45 AM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,048
Nominated 5 Times in 3 Posts
Nominated TOTW/F/M Award(s): 1
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

I write my own, this way I know what's going on.
If you want to go that way, just post what you have and lets see if we can get it working properly without errors.
__________________
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Directory Submission Directory Submission
:. News & Press Release Ireland GiveItSocks.com
:. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories
:. I Have 2 Find It Directory SEF Directory
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 22-03-2007, 05:17 AM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default

I use a script that i wrote myself, it an easy to use one that basicly you just change or add your fields and then change the email address! your caal if you want it!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 22-03-2007, 02:26 PM
404 username not found's Avatar
Undefined offset:
 
Join Date: Jan 2007
Location: localhost
Posts: 69
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
404 username not found will become famous soon enough
Default

Ah good, so it's not just me then

I suppose it's a simple enough matter to put the functionality in place, but I'm extremely paranoid about writing exploitable code.
The last thing you want is to get your domain spam-listed because you overlooked something.
I think the good thing about using well known and widely used scripts is that they've already had months/years to get hammered on... but then a custom script can have everything hard-coded and has the benefit of obscurity.

@ziycon:
Thanks, I'd be interested in having a look at it.
I've already got a referer whitelist function written along with a few different input validation funtions, but I'd be interested in seeing how you're implementing mail() since I haven't used it before.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 22-03-2007, 02:35 PM
paul's Avatar
ninja SEO
Recent Blog: That SEO contest
 
Join Date: Dec 2006
Location: .de
Posts: 1,120
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
paul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud of
Default

I can send you the one I use here
Contact us : EirJobs.com : Irish Jobs Resourcer

I'm not sure where I got it from but it does us a CAPCHTA, which stops silly bots submitting things. Sadly it didn't stop a silly person a submitting their CV to me.
Here is the mail function
PHP Code:
<?php
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo 
"<h3>Use Back - Enter valid e-mail</h3>\n";
$badinput "<h3>Feedback was NOT submitted</h3>\n";
echo 
$badinput;
}
if(empty(
$visitor) || empty($visitormail) || empty($notes )) {
echo 
"<h3>Use Back - fill in all fields</h3>\n";
}

$todayis date("l, F j, Y, g:i a") ;

$attn $attn ;
$subject $attn;

$notes stripcslashes($notes);

$message " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
"
;

$from "From: $visitormail\r\n";


mail("MYADDRESS@GMAI.COM"$subject$message$from);

?>
I would be interested to see some examples of people who have more rigorous check against people abusing the form.
__________________
my sites :
irish poker / irish jobs / seo faq / advertise jobs free / green card / skiing

Last edited by paul; 22-03-2007 at 02:47 PM. Reason: more details !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 22-03-2007, 11:02 PM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default

PHP Code:
if($fname)
{
      
$fname "Name: $fname";
      
$msg .= "$fname\n";
}
else
{
      
$error "- Name Missing.<br>\n";
}
if(
$email)
{
      
$email "E-Mail: $email";
      
$msg .= "$email\n";
}
else
{
      
$error .= "- E-Mail Missing.<br>\n";
}
if(
$subject)
{
      
$subject "Subject: $subject";
      
$msg .= "$subject\n";
}
else
{
      
$error .= "- Subject Missing.<br>\n";
}
if(
$message)
{
      
$message "Message: $message";
      
$msg .= "$message\n";
}
else
{
      
$error .= "- Message Missing.<br>\n";
}
if(
$error == "")
{
      echo
'Thank you for contacting Us.';
      
mail("info@site.com""$subject"$msg"From: $email");
      
mail($email"Confirmation""Your message has been sent.\n\nThank you for contacting us.\ninfo@site.com""From: noreply@site.com");
}
else
{
      print 
"Please fill in the missing fields - <br>\n";
      print 
"$error<br>\n";
      print 
"<br>\n";
      print 
"<br>\n";
      print 
"Please use your \"Back\" button to return to the form to correct the omissions.<br>\n";

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 22-03-2007, 11:09 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,048
Nominated 5 Times in 3 Posts
Nominated TOTW/F/M Award(s): 1
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

there is something I use with Ajax as well to check a form
PHP Code:
$err_msg "";
//name
if(isset($_REQUEST['name'])){
 
$name $_REQUEST['name'];
 if(
$name == ""){ 
  
$err_msg " <img src='images/exclamation.gif' /> name can not be empty!";
 }else{
  
$_SESSION['name'] = $name;
  
$err_msg "&nbsp;<img src='images/ok.gif' style='position:absolute;' />";
 }
}

//check email
if(isset($_REQUEST['email'])){
 
$email $_REQUEST['email'];
 if(
valid_email($email)){
  
$_SESSION['email'] = $email;
  
$err_msg "&nbsp;<img src='images/ok.gif' style='position:absolute;' />";
 }else{
  
$err_msg " <img src='images/exclamation.gif' /> Either your email is not valid, domain doesn't exists or there is no valid MX host available";
 } 
}
function 
valid_email($email) { 
 if( (
preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/'$email)) || 
  (
preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) ) { 
  
$host explode('@'$email);
  if (
function_exists('checkdnsrr')) {
   if(
checkdnsrr($host[1].'.''MX') ) return true;
   if(
checkdnsrr($host[1].'.''A') ) return true;
   if(
checkdnsrr($host[1].'.''CNAME') ) return true;
  }
  return 
true;
 }
 return 
false;
 }
if (!
function_exists('checkdnsrr')) {
 function 
checkdnsrr($host$type '') {
  if(!empty(
$host)) {
   if(
$type == ''$type "MX";
   @
exec("nslookup -type=$type $host"$output);
   while(list(
$k$line) = each($output)) {
    if(
eregi("^$host"$line)) {
     return 
true;
    }
   }
   return 
false;
  }
 }
}
//end email
//check tel
if(isset($_REQUEST['tel'])){
 
$x_tel false;
 
$tel $_REQUEST['tel'];
 if(
$tel == ""){ 
  
$err_msg " <img src='images/exclamation.gif' /> Tel can not be empty!";
 }elseif(!
is_numeric(str_replace(" ","",$tel))){
  
$err_msg " <img src='images/exclamation.gif' /> Tel can only be numbers!";
  
$x_tel false;
 }else{
  
$x_tel true;
  
$_SESSION['tel'] = $tel;
  
$err_msg "&nbsp;<img src='images/ok.gif' style='position:absolute;' />";
 }
}
//message
if(isset($_REQUEST['message'])){
 
$message $_REQUEST['message'];
 if(
$message == ""){ 
  
$err_msg " <img src='images/exclamation.gif' /> message can not be empty!";
 }elseif(
strlen($message) <= 10){
  
$err_msg " <img src='images/exclamation.gif' /> message too short. min. 10 chars";
 }else{
  
$message str_replace("%0A","<br />",$message);//%0D
  
$message str_replace("%0D","<br />",$message);//
  
$message str_replace("%20"," ",$message);
  
$message str_replace(chr(10),"<br />",$message);
  
$_SESSION['message'] = str_replace(chr(13),"<br />",$_SESSION['message']);
  
$err_msg "&nbsp;<img src='images/ok.gif' style='position:absolute;' />";
 }
}
//send email
if(isset($_REQUEST['send_email'])){
 
$get_mail_out $_REQUEST['send_email'];
 if(
$get_mail_out == "true"){
  if(isset(
$_SESSION['name']) &&
     isset(
$_SESSION['email']) &&
     isset(
$_SESSION['tel']) &&
     isset(
$_SESSION['message'])){
    
$from "info@eire-webdesign.ie";
    
$bcc "mail@eire-webdesign.ie";
    
$subject ":: Contact from eire-webdesign";
    
$now date("d/m/Y H:i:s");
    
$mime_boundary=md5(time());
    
# Common Headers
    
$headers "MIME-Version: 1.0\r\n".
        
"Content-type: text/html; charset=iso-8859-1\r\n".
        
"From: \"Louie\" <".$from.">\r\n".
        
"To: \"".@$_SESSION['name']."\" <".@$_SESSION['email'].">\r\n".
        
"Date: ".date("r")."\r\n".
        
"Subject: ".$subject."\r\n";   
    
$msg "Name: ".$_SESSION['name']."<br />";
    
$msg .= "Email: ".$_SESSION['email']."<br />";
    
$msg .= "Tel: ".$_SESSION['tel']."<br />";
    
$msg .= "Message: ".$_SESSION['message']."<br />";
     
//send email out
     
ini_set(sendmail_from,'info@eire-webdesign.ie');  // the INI lines are to force the From Address to be used !
     
mail($_SESSION['email'], $subject$msg$headers); 
     
$msg "";
     
session_destroy();
     
$err_msg "<span class='red'><img src='images/ok.gif' />&nbsp;Email sent! Thank you.<br /></span>";
   }else{
    
$err_msg "<span class='red'>We have encounter an error sending your email.<br>
   Please try again later!<br />
   Click <a href='index.php?page=contact' title='go back'>&laquo; here</a> to go back.</span>"
;
   }
 }
}
echo 
$err_msg;//echo response. 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 26-03-2007, 06:02 PM
404 username not found's Avatar
Undefined offset:
 
Join Date: Jan 2007
Location: localhost
Posts: 69
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
404 username not found will become famous soon enough
Default

After a marathon weekend of coding, I finally finished it (is it ever really finished?)... as expected the logic & functionality was easy, but I had a lot of reading to do about mail() injection.
I think I've plugged the injection holes... at least for the limited type of data I've got it configured to accept (I can afford to be strict and unforgiving).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9 (permalink)  
Old 26-03-2007, 10:00 PM
Frontpage User
 
Join Date: Mar 2007
Posts: 7
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
daryllsheridan will become famous soon enough
Default Share?

Dont suppouse you want to share the knowledge, kinda looking for something similar but wouldnt have a clue how to go about it
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10 (permalink)  
Old 26-03-2007, 11:06 PM
404 username not found's Avatar
Undefined offset:
 
Join Date: Jan 2007
Location: localhost
Posts: 69
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
404 username not found will become famous soon enough
Default

Do you have questions on writing one? or are you just looking for a script?

Where I'm at now, it fits the bill for the site it's being used on and not much else... try'n plug any other form element into it and see how fast you have to write more code.
Unless you know your way around regular expressions and want to spend a few hours adding functions, I'd steer clear of my script

A more mature/flexible formmail script I was using prior to doing my own was the one here:
http://www.boaddrink.com
It seems good and was quite easy to set up, and as well as having the features there's a support forum for it... so any setup questions/problems you have with it are probably already answered.

tbh I could have saved myself hours of wheel-reinventing if I'd just had the patience to figure out how to customise it the way I wanted... oh well.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote