View Single Post

  #7 (permalink)  
Old 22-03-2007, 11:09 PM
louie's Avatar
louie louie is offline
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,078
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. 
__________________
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories
:. I Have 2 Find It Directory SEF Directory
Reply With Quote