PHP Classes

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

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Info   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2004-12-11 (10 years ago) RSS 2.0 feedStarStarStarStar 62%Total: 7,670 This week: 1All time: 215 This week: 1,121Down
Version License Categories  
clssendmail 1.0GNU General Publi...Email
Description Author  

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
Name: Daniel Andres Marjos is available for providing paid consulting. Contact Daniel Andres Marjos .
Classes: 13 packages by
Country: Argentina Argentina
Age: 45
All time rank: 231 in Argentina Argentina
Week rank: 159 Down2 in Argentina Argentina Down
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

// 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?");

// 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

// 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.

// 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  
 0%Total:7,670All time:215
 This week:1This week:1,121Down
 User Ratings  
 All time