Reference Manuals

Emailer

Emailer — This is a generic emailer implementation for multipart MIME e-mail.

Emailer is part of the Emailer package.

Synopsis

class Emailer {
        private        array               $addresses
        private        array               $attachments
        private        array               $attachments_inline
        private        string              $extra_headers
        private        string              $from
        private        string              $message
        private        string              $message_html
        private        string              $message_text
        private        string              $mime_boundary_alternative
        private        string              $mime_boundary_mixed
        private        string              $mime_boundary_related
        private        string              $reply_to
        private        string              $smtp_from
        private        string              $smtp_host
        private        string              $smtp_pass
        private        string              $smtp_user
        private        string              $subject

        public         Emailer             __construct               ( string $smtp_host,
                                                                       string $smtp_from,
                                                                       string $smtp_user,
                                                                       string $smtp_pass );
        private        void                add_addresses             ( mixed $addresses,
                                                                       string $type );
        public         bool                attach                    ( string $file,
                                                                       string $mimetype,
                                                                       string $content,
                                                                       bool $inline );
        public         void                bcc                       ( mixed $address );
        public         void                cc                        ( mixed $address );
        public         void                clear                     ( void );
        public         void                extra_headers             ( string $headers );
        public         void                from                      ( string $address );
        public         void                message                   ( string $text,
                                                                       string $html );
        public         void                reply_to                  ( string $address );
        public         mixed               send                      ( void );
        private        mixed               server_parse              ( handle $socket,
                                                                       string $response,
                                                                       int $line );
        private        mixed               smtpmail                  ( void );
        public         void                subject                   ( string $subject );
        public         void                to                        ( mixed $address );
}

Object Hierarchy

Emailer

Description

This is a generic emailer implementation for multipart MIME e-mail.

It allows for simple messages as well as multipart/related (text/html) MIME messages. It also supports inline attachemnts and regular attachments. To top it off it carries it's own SMTP interface so you can use a remote SMTP server and bypass whatever PHP's mail() is trying to use. Convenient to escape a poorly configured host.Heavily based off phpBB's e-mail class which was Copyright 1999-2005 phpBB Group which is available under the GPL 2 or later.

Attribute Details

$addresses

private        array          $addresses

A two-dimensional array containing all the addresses in $addresses['to'], $addresses['cc'] and $addresses['bcc']


$attachments

private        array          $attachments

A list of attachments


$attachments_inline

private        array          $attachments_inline

A list of inline attachments


$extra_headers

private        string         $extra_headers

Extra e-mail headers


$from

private        string         $from

The From: address


$message

private        string         $message

The composed e-mail in multipart MIME


$message_html

private        string         $message_html

The e-mail message in text/html


$message_text

private        string         $message_text

The e-mail message in text/plain


$mime_boundary_alternative

private        string         $mime_boundary_alternative

The MIME-boundary used for multipart messages


$mime_boundary_mixed

private        string         $mime_boundary_mixed

The MIME-boundary used for multipart messages


private        string         $mime_boundary_related

The MIME-boundary used for multipart messages


$reply_to

private        string         $reply_to

The Reply-to: address


$smtp_from

private        string         $smtp_from

A username that is used as the From: field when senting over SMTP. Some SMTP servers check this


$smtp_host

private        string         $smtp_host

The SMTP hostname. If empty, the mailer will use PHP's built-in mail() command.


$smtp_pass

private        string         $smtp_pass

The password for SASL authentication


$smtp_user

private        string         $smtp_user

The username used for SASL authentication. Empty is SASL should not be used


$subject

private        string         $subject

The e-mail subject

Method Details

__construct()

public         Emailer        __construct               ( string $smtp_host,
                                                          string $smtp_from,
                                                          string $smtp_user,
                                                          string $smtp_pass );

Create a new Emailer object

$smtp_host
The SMTP server's hostname. Leave blank to use PHP's built-in mail() command.
$smtp_from
A username that is used as the From: field when senting over SMTP. Some SMTP servers check this
$smtp_user
A username used for SASL authentication against the SMTP server. Leave empty to disable SASL authentication
$smtp_pass
The password for SASL authentication

add_addresses()

private        void           add_addresses             ( mixed $addresses,
                                                          string $type );

Add an (array of) addresses to the e-mail.

$addresses
The addresses to ad. Can be a single string or an array.
$type
The type of addresses to add. Should be any of 'to', 'cc' or 'bcc'

attach()

public         bool           attach                    ( string $file,
                                                          string $mimetype,
                                                          string $content,
                                                          bool $inline );

Attach a regular or inline attachment to the e-mail message. To attach a file inline (embedded), set the $inline parameter to TRUE. If you do not supply the contents of the file, this function tries to open the file and read it's contents. In that case, the $file parameter should be a full path. If you do not supply a mimetype or if it is empty, the file will be attached as application/octetstream.

$file
The name of the file, or a full path to the file
$mimetype
The mimetype of the file
$content
The content of the file
$inline
Whether to attach the file inline or normally

bcc()

public         void           bcc                       ( mixed $address );

Add a single address or array of addresses

$address
A single e-mail address or array of addresses. Addresses can also be in the form '"Your Name" '

cc()

public         void           cc                        ( mixed $address );

Add a single address or array of addresses

$address
A single e-mail address or array of addresses. Addresses can also be in the form '"Your Name" '

clear()

public         void           clear                     ( void );

Clear all messages, attachments and e-mail addresses from the class, making it ready to be used again.


extra_headers()

public         void           extra_headers             ( string $headers );

Add extra e-mail headers to the message. Separate multiple headers with a \r\n linebreak

$headers
Extra headers for the e-mail message

from()

public         void           from                      ( string $address );

Set the From: address

$address
A single e-mail address

message()

public         void           message                   ( string $text,
                                                          string $html );

Set the message body in text/plain and text/html.

Beware that a lot of e-mail clients have poor HTML processing. Stick with basic HTML 4.01 and use inline styling instead of stylesheets. You can use inline images by attaching them with the attach() function and setting the $inline parameter to TRUE.

$text
The message in text/plain utf-8 format
$html
The message in text/html utf-8 format

reply_to()

public         void           reply_to                  ( string $address );

Set the Reply-to: address

$address
A single e-mail address

send()

public         mixed          send                      ( void );

Actually send the e-mail


server_parse()

private        mixed          server_parse              ( handle $socket,
                                                          string $response,
                                                          int $line );

Parse an SMTP response from the socket

This function has been modified as provided by SirSir to allow multiline responses when using SMTP Extensions.

$socket
The socket to the SMTP server
$response
The SMTP response code to look for
$line
The line where server_parse was called from. Used for error messages.

smtpmail()

private        mixed          smtpmail                  ( void );

Send the e-mail manually over SMTP instead of using PHP's mail() command


subject()

public         void           subject                   ( string $subject );

Set the subject of the e-mail

$subject
The subject of the e-mail

to()

public         void           to                        ( mixed $address );

Add a single address or array of addresses

$address
A single e-mail address or array of addresses. Addresses can also be in the form '"Your Name" '