PHP Classes

Compose Mail: Sending e-mail in text and HTML with attachments

Recommend this page to a friend!
  Info   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 62%Total: 7,708 All time: 230 This week: 112Up
Version License Categories
clssendmail 1.0.0GNU General Publi...Email


This class is intended to send multipart e-mail messages.

It can send messages in HTML with an alternative text part to be viewed with e-mail programs that do not support displaying HTML messages.

Optionally, it can also send multiple files as attachments.

Picture of Daniel Andres Marjos
  Performance   Level  
Name: Daniel Andres Marjos is available for providing paid consulting. Contact Daniel Andres Marjos .
Classes: 13 packages by
Country: Argentina Argentina
Age: 53
All time rank: 261 in Argentina Argentina
Week rank: 101 Down1 in Argentina Argentina Equal
Innovation award
Innovation award
Nominee: 2x


The ComposeMail class was born to accomplish a very particular requirement I had. I needed to send an email in both formats: text/plain and text/html. I've looked around in the repository and I was about to use Manuel Lemos' own Email sending class, but it was too complex for what I wanted to do, so I wrote this simple class. I know it lacks of the CC and BCC capabilities, but I will add those features as soon as I can. Here is a brief explanation on how the class works, via this simple script: Even though the code was added to the class a long time ago, I didn't updated this doc properly, so here we go... ++ Added 2004-12-11 ++ The class has now support for CarbonCopy (CC), BlindCarbonCopy (BCC), ReturnPath, EnvelopeTo via sh_<<Header>> (i.e. sh_CarbonCopy(""); ) A new method was added: BuildAndSendMessageTextPlain, which sends the mail without any attachment and without HTML part. Just the text/plain section. <? // First of all, we include the class file. I assume there is no need to document this require("$DOCUMENT_ROOT/library/clsSendMail.php"); // We build the HTML part of our mail. In this case, a simple bold sentence $content="<b> this is a test</b>"; // Let's create an instance of our class. We must specify here who will // receive the mail and the subject. $mailer=new ComposeMail("","test mail"); // Let's specify who we are // This two functions will make the "From: " header looks like: // From: "Hey hey!!! you know who am I, don't you?" <> $mailer->sh_fromName("Hey hey!!! you know who am I, don't you?"); $mailer->sh_fromAddr(""); // Let's add a sample plain text as the body. Notice that plain text is // not required to be the same as HTML w/o tags. It could be anything you // want $mailer->addTextPlainBodyPart("Test message"); // Let's add the HTML content we created before $mailer->addHTMLBodyPart("$content"); // Let's add our class file as an attachment. Take a look at the parameters // First, we specify the full path of the file to attach // In second place, we say the method to give the file the specified mime // type. It uses the same mime types that you can get when handling // uploaded files in PHP. In this case, text/plain, but it could be // image/jpeg, image/gif or anything that fits the actual file type. // In third place, we must say it will be attached, and not shown inline. $mailer->addAttachFromFile("$DOCUMENT_ROOT/library/clsSendMail.php","text/plain","attachment"); // We have just created our mail... Let's send it and enjoy echo $mailer->BuildAndSendMessage(); ?>

  Files folder image Files  
File Role Description
Plain text file clsSendmail.php Class the only file to this class. Includes a sample script
Accessible without login Plain text file README Doc. A brief explanation of the class

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:230
This week:112Up
 User Ratings  
 All time