Mail_mime

Mail_mime -- create multipart messages

Description

A class to enable easy creation of complex multipart emails. If what you're after is a simple API for creating such emails, then this class will probably suffice. If on the other hand you're after a higher degree of control over the email, then you might want to look at using mimePart

Mail_mime::Mail_mime()

Mail_mime Mail_mime ([string $crlf = "\r\n"])

Description

returns a new instance of Mail_mime

Parameter

Notes

Normaly, it isn't necessary to set the $crlf-Parameter.

Mail_mime::setTxtBody()

mixed setTxtBody (string $data [, boolean $isfile = false])

Description

Sets the plain text part of the email.

Parameter

Return value

Mail_mime::setHTMLBody()

mixed setHTMLBody (string $data [, boolean $isfile = false])

Description

Sets the html part of the email.

Parameter

Return value

Mail_mime::addHTMLImage()

mixed addHTMLImage (string $data, string [$c_type = 'application/octet-stream'] [, string $name = '' [, boolean $isfile = true]])

Description

If sending an HTML email with embedded images, use this function to add the image.

Parameter

Return value

Mail_mime::addAttachment()

mixed addAttachment (string $data, string [$c_type = 'application/octet-stream'], string [$name = ''], boolean [$isfile = true], string [$encoding = 'base64'])

Description

Adds an attachment to the email.

Parameter

Return value

Mail_mime::&get()

string &get (array [$param = null])

Description

This function should be called once you have added the text/html/images/attachments. It builds the email and returns it. It does not send it. To send what this function returns (in conjunction with the headers() function) you would need to use the Mail_*::send() -function

Parameter

Return value

Mail_mime::&headers()

array &headers ([array $headerEx = null])

Description

Returns an array with the headers needed to prepend to the email (MIME-Version and Content-Type). Please note that the function get() has to be called before calling headers().

Parameter

Return value

Example

<?php
include('Mail.php');
include('Mail/mime.php');

$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = '/home/richard/example.php';
$crlf = "\r\n";
$hdrs = array(
              'From'    => 'you@yourdomain.com',
              'Subject' => 'Test mime message'
              );

$mime = new Mail_mime($crlf);

$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file, 'text/plain');

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory('mail');
$mail->send('postmaster@localhost', $hdrs, $body);
?>