PHP Mail (Send Email)
By Brian on Apr 01, 2009 with Comments 2
If you have a contact us page or something that sends an email with the use of php, it will use the “mail()” function of PHP. Here is the function:
mail('Send To','Email Title','Email Message','Headers','Parameters');
Send To = Who the email is being sent to.
Email Title = Title of the email, appears in inbox.
Email Message = The body text of the message sent.
Headers = Specifies additional headers, like From, Cc, and Bcc.
Parameters = Specifies additional parameters.
Here is an example:
<?php $toEmail = "sendto@site.com"; $title = "Email title"; $message = "This is a email message."; $headers = "From: anotheremail@site.com"; mail($toEmail,$title,$message,$headers); ?>
You have to be careful with the mail function and using headers/parameters. These are often ways of hackers sending faulty information to the script which can allow for header infections, etc. Always be sure to clean your variables you are sending to the function.
Here is a good way to check an email with preg_match:
function check_email($str){
if(preg_match("/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is", $str)) {
$email = trim($str);
return $email;
}
}
Enjoy!
Popularity: 1% [?]
Filed Under: PHP • Web Programming

Excellent post, bookmarked the blog in hopes to see more!
Informative post, saved your site for hopes to read more information!