We help IT Professionals succeed at work.

Best PHP class for email

DarkHill asked
Medium Priority
Last Modified: 2012-05-06
I'm looking for a good PHP class to use for the emailing functions on my website. Any good suggestions of classes you have personally used?
Watch Question

HI DarkHill,

Here's the one I use regularly (it allows for both plain text and HTML formatted emails):
function multipart_mail($to, $subject, $html_message, $text_message, $from_address, $from_display_name=''){
     $headers = $from_display_name == '' ? "From: ".$from_address : "From: ".$from_display_name." <".$from_address.">";
     $semi_rand = md5(time()); 
     $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
     $headers .= "\nMIME-Version: 1.0\n";
     $headers .= "Content-Type: multipart/alternative;\n";
     $headers .= " boundary=\"{$mime_boundary}\""; 
     $email_message =
     $email_message .= "This is a multi-part message in MIME format.\n\n"; 
     $email_message .= "--{$mime_boundary}\n";
     $email_message .= "Content-Type:text/plain; charset=\"iso-8859-1\"\n";
     $email_message .= "Content-Transfer-Encoding: 7bit\n\n"; 
     $email_message .= $text_message . "\n";
     $email_message .= "--{$mime_boundary}\n"; 
     $email_message .= "Content-Type:text/html; charset=\"iso-8859-1\"\n"; 
     $email_message .= "Content-Transfer-Encoding: 7bit\n\n";
     $email_message .= $html_message;
     return @mail($to, $subject, $email_message, $headers); 

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.