Emailer — This is a generic emailer implementation for multipart MIME e-mail.
Emailer is part of the Emailer package.
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 ); }
Emailer
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.
private array $addresses
A two-dimensional array containing all the addresses in $addresses['to'], $addresses['cc'] and $addresses['bcc']
private array $attachments
A list of attachments
private array $attachments_inline
A list of inline attachments
private string $extra_headers
Extra e-mail headers
private string $from
The From: address
private string $message
The composed e-mail in multipart MIME
private string $message_html
The e-mail message in text/html
private string $message_text
The e-mail message in text/plain
private string $mime_boundary_alternative
The MIME-boundary used for multipart messages
private string $mime_boundary_mixed
The MIME-boundary used for multipart messages
private string $mime_boundary_related
The MIME-boundary used for multipart messages
private string $reply_to
The Reply-to: address
private string $smtp_from
A username that is used as the From: field when senting over SMTP. Some SMTP servers check this
private string $smtp_host
The SMTP hostname. If empty, the mailer will use PHP's built-in mail() command.
private string $smtp_pass
The password for SASL authentication
private string $smtp_user
The username used for SASL authentication. Empty is SASL should not be used
private string $subject
The e-mail subject
public Emailer __construct ( string $smtp_host, string $smtp_from, string $smtp_user, string $smtp_pass );
Create a new Emailer object
private void add_addresses ( mixed $addresses, string $type );
Add an (array of) addresses to the e-mail.
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.
public void bcc ( mixed $address );
Add a single address or array of addresses
public void cc ( mixed $address );
Add a single address or array of addresses
public void clear ( void );
Clear all messages, attachments and e-mail addresses from the class, making it ready to be used again.
public void extra_headers ( string $headers );
Add extra e-mail headers to the message. Separate multiple headers with a \r\n linebreak
public void from ( string $address );
Set the From: address
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.
public void reply_to ( string $address );
Set the Reply-to: address
public mixed send ( void );
Actually send the e-mail
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.
private mixed smtpmail ( void );
Send the e-mail manually over SMTP instead of using PHP's mail() command
public void subject ( string $subject );
Set the subject of the e-mail
public void to ( mixed $address );
Add a single address or array of addresses