communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "communication" - download "send email"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

communication - send email was created/last modified on Wed 18 Aug 2004 5:19 PM

email sending function with email address validator
    
<?php
     
    
// checks the syntax of the emailaddress
     
    
function funcCheckEmail($sEmailAddress)
    {
       
$sChars = "^[A-Za-z0-9\._-]+@([A-Za-z][A-Za-z0-9-]{1,62})(\.[A-Za-z][A-Za-z0-9-]{1,62})+$";
     
       
$bIsValid = true;
       if(!
ereg("$sChars",$sEmailAddress))
       {
           
$bIsValid = false;
       }
       return
$bIsValid;
    }
     
    
// sends the email
     
    
function funcSendEmail($recipient,$subject,$message,$from,$replyto)
    {
       
$array = array ("\'" => "'");     
       
$message = strtr($message, $array);   
       
$message = '<html><body>'.$message.'</body></html>'."\r\n\r\n";
       
$extra = 'From: '.$from.' <'.$replyto.'>'."\r\n";
       
$extra .= 'Content-Type: text/html; charset="ISO-8859-1"'."\r\n";
       
$extra .= 'Content-Transfer-Encoding: quoted-printable'."\n\r\n";
       
mail ($recipient, $subject, $message, $extra);
    }
     
    
// use like this
     
    
if((funcCheckEmail('recipient@example.com')) && (funcCheckEmail('sender@example.com')))
    {
       
funcSendEmail('recipient@example.com','Re:Re:...','how are you','john foo','sender@example.com');
    }
     
?>

learn more about some of the PHP functions used in this snippet: array, end, ereg, function, mail, print, return, send, strtr

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari