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("another@email.com"); )
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("somebody@somserver.com","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?" <itsme@thisserver.com>
$mailer->sh_fromName("Hey hey!!! you know who am I, don't you?");
$mailer->sh_fromAddr("itsme@thisserver.com");
// 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();
?>
|