Projects > MIMEMailPHP4 > Documentation >
Feike Open Source

Open Source & GPL Projects

my contribution to the freedom of programing

 
 
 
 
 
 
 
 
 
 
 
NEWS
in



 

Documentation of class MIMEMailxPHP4_V2

class
MIMEMailxPHP4_V2

+ setSubject(string)
+ setTextContent(string)
+ setHTMLContent(string)
+ setFromHeader(string)
+ setRecievers(string|array)
+ setCCRecievers(string|array)
+ setBCCRecievers(string|array)
+ sendMail(boolean)
+ setEOL(string)
+ addBinaryFileAsAttachment(...)
+ addBinaryStringAsAttachment(...)
+ setReplyTo(string)
+ getLastErrorString()
+ getLastErrorCode()

Building a MIME multipart email with php is always not simple and no fun. Therefore I wrote a simple-to-use class in PHP4 to encapsulate this problem.
Usage of this class is pretty simple and straight forward.

  • include code file
  • create a class instance
  • set mail attributes
  • send mail
Please note that we do not support any other SMTP transfer than the php build-in mail() function. Reason is, that there is allready a exhausting (host, port, auth...) configuration via the php.ini file availible. Ask your webspace provider.

Let's do a quick start with a usable but easy example.

Example building a MIME HTML Mail with an image

/**
 * Testprogram for MIMEMailxPHP4_V2
 * Scope: sending simple html mail with inline image
 */

// include class
require_once("MIMEMailxPHP4_V2.inc");

// create instance
$mail = new MIMEMailxPHP4_V2();

// set html content in mail
$mail->setHTMLContent("Hello World, this is my image: <img src='cid:img1'>");
// set sender
$mail->setFromHeader("Example <exm@example.test>");
// set recievers
$mail->setRecievers(Array("exm1@example.de", "exm2@example.test"));
// set subject
$mail->setSubject("testmail from MIMEMailxPHP4 V2 with mime html image");
// attach image
$mail->addBinaryFileAsAttachment("../images/myimage.jpg", "image/jpg", "image.jpg", "img1");

// send mail
$rc = $mail->sendMail();

Important hint: Lots of users encounter problems with linefeeds. The usual problem is, that you use a windows editor to edit your codefile and a unix MTA to send the message. If - for some reason - your FTP transfer misses the /n -> /r/n replacement, your MTA will report a miss-build MIME mail. In this case experiment with function:
$mail->setEOL($eol); // $eol can be "\n" or "\r\n" defualt is unix like "\n"

Class Method Reference

function setEOL($eol)

Set the "End Of Line" character. This is very important for your mail transfer agent (MTA). On unix systems it should be "\n" (that is the default). If for any reason you are running an MTA on windows, use "\r\n". Best thing is to experiment with these two settings.
Returns: Nothing of value

function getLastErrorCode()

Some functions do set an error code - in case of an error. Use this to get an interger representing this errorcode.
Returns: Zero or the last error code (see next function for textual representation).

function getLastErrorString()

Returns a textual representation of the last error. Usually you will not need this. There are very less error situations.

function setTextContent($text, $charset = "ISO-8859-1", $encoding = "8bit")

A multipart mail can contain a plain-text message as well as a html message. The mail client has to decide which one to display. With this function you can set the text-only part of the message. It should say the same thing as the html text. Charset is the charset of your content. Another popular example is "utf-8". Encoding is 7 or 8 bit. Use 8 Bit in case of doubt.

function setHTMLContent($html, $charset = "ISO-8859-1", $encoding = "8bit")

A multipart mail can contain a plain-text message as well as a html message. The mail client has to decide which one to display. With this function you can set the html part of the message. It should say the same thing as the plain-text part. Charset is the charset of your content. Another popular example is "utf-8". Encoding is 7 or 8 bit. Use 8 Bit in case of doubt. If you set html content before setting text content, the class sets a text-only representation automatically (this is the "strip_tags" result of the html content).
If you want to use a inline image, refer to it by it's CID. I.e. <img src='cid:img1'>

function addBinaryFileAsAttachment($file, $type, $name, $ContentID = "")

Attach a binary file to the email. The ContentID parameter is only used for inline images, else leave it empty. "name" is what the mail client will report as the attachments name, "type" is the mime-type. Useful mime-types are: image/jpg, application/pdf, appication/ms-word, image/png etc. Internally this function uses "php-fopen()". So if your wrappers are configured accordingly, you may also use an url to attach binary objects. "file" is the filename and path relative to the scripts execution position or absolute from your webservers root.

function addBinaryStringAsAttachment($string, $type, $name, $ContentID = "")

Attach binary data to the email. The ContentID parameter is only used for inline images, else leave it empty. "name" is what the mail client will report as the attachments name, "type" is the mime-type. Useful mime-types are: image/jpg, application/pdf, appication/ms-word, image/png etc. Internally this function uses "php-fopen()". So if your wrappers are configured accordingly, you may also use an url to attach binary objects. "string" is the data to attach.

function setSubject($subject)

Set the subject of your mail.

function setReplyTo($repl)

Set the reply-to adress of your mail.

function setRecievers($rcvs)

Set the reciever or more recievers (use an array). Pay attention to the maximum lenght of the used MTA's. The class does not take care about this.

function setCCRecievers($rcvs)

Set the carbon copy (CC) reciever or more CC recievers (use an array). Pay attention to the maximum lenght of the used MTA's. The class does not take care about this.

function setBCCRecievers($rcvs)

Set the blind carbon copy (BCC) reciever or more BCC recievers (use an array). Pay attention to the maximum lenght of the used MTA's. The class does not take care about this.

function setFromHeader($from)

Set the sender of this mail.

function sendMail($dump = false)

Send the mail by using the php-mail() command. If you set $dump to true, the mail will not be sent but the mime-code result will be returned (for teaching or debugging purposes). If you need special SMTP parameters set them in your php.ini file.
Last Update: April 2007