Best PHP class for email

Posted on 2009-02-11
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?
Question by:DarkHill
    1 Comment
    LVL 2

    Accepted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now