It consists of two major classes:
Both classes are based on eiseMail_base class that contains some handful utilities.
In case of exception, class methods are throwing eiseMailException object with mail message queue in its actual state so you can trace what messages were sent and what were not.
PHP version: >5.1
License: GNU Public License http://opensource.org/licenses/gpl-license.php
Uses: : OpenSSL, IMAP
Version: : 1.0
Author: : Ilya Eliseev ie@e-ise.com, contributors: Dmitry Zakharov, Igor Zhuravlev
Sponsors: Yusen Logistics Rus LLC, Russia
Class for mail sending and communications via SMTP. In difference with other mail utilities in PHP, it is aimed for batch mailing to various recipients with a little adaptation of mail message to each recipient. Message body, header, footer, subject can be set on main configuration options and then implemented in each mail in batch.
It can be used in the following way:
send() method uses sockets to connect to SMTP server. It supports host authentication and TLS channel encryption. It pushes the message queue to the server right after connection is established, channel encrypted and authentication succeeded.
Being executed with ['flagAddToSentItems'] = true
send() method will make an attempt to save message in sender’s “Sent Items” folder.
Class has been tested for proper communication with the following SMTP servers:
Actual example can be found in eiseMail_demo.php script attached to this package.
Constructor just initializes the object and covers password for possible verbose mode.
Parameters:
Default mail message fields can be set here also:
See more at eiseSMTP::addMessage() description.
This method adds message to message queue. Also it prepares all mandatory SMTP headers like mail from:
and rcpt to:
basing on From, To, Cc and Bcc fields.
Category: Mail send
Parameters:
$this->conf['From']
. If not set, it will be taken from login field.Example:
$sender->addMessage(array('From'=> '"John Doe" <john.doe@acme.com>'
, 'To' => '"Bar, Foo" <foo.bar@sukaba.com>'
, 'Subject' => 'Message with 2 kinds of attachments'
, 'Text' => 'Hello there'
, 'Attachments' => array(
array ('filename'=>'file1.txt'
, 'content'=>"Hello\r\nfrom the text file"
, 'Content-Type'=>'text/plain')
, array ('filename'=>'file2.txt'
, 'content'=>"Hello\r\nfrom the text file again"
, 'Content-Type'=>'text/plain')
, array ('filename'=>'welcome_to_the_internet.jpg'
, 'content'=>file_get_contents('welcome_to_the_internet.jpg')
, 'Content-Type'=>'image/jpeg')
)
);
This method performs connection to SMTP server and sends all message queue.
Then it converts each message from $arrMessages to string, performs base64-encoding, chunk-splitting of the attachemtns and send each message to anyone in To, Cc and Bcc messages.
In case of failure it throws eiseMailException object with message queue. If you need to analyze what message were sent or not, you can walk through eiseMailException $arrMessages array. Each member of this array will be updated with the following members:
Category: Mail send
Parameters:
This function returns source of a partiqular message in queue, its number (index) is specified by $ixToGet parameter. If this parameter is omitted, first message source is returned. This method uses msg2String private method.
Parameters:
Returns: string Message source.
This function prepares message for sending: it converts it to string with headers and message parts
Parameters:
Returns: string Ready-to-send message data after SMTP DATA command.
This function transmits data to SMTP server
Parameters:
Returns: void
This function listens for reply from SMTP server
Parameters:
Returns: string $data - string with SMTP reply to last transmission
This function analyze reply from SMTP server and, in case of unexpected reply, it throws the exception
Parameters:
Returns: void
Mail message queue to send.
Class to handle messages from IMAP/POP3 server
Uses PHP IMAP extension function
Link: http://php.net/manual/en/ref.imap.php
Object constructor. Receives configuration array as parameter and merges it with the default one.
Parameters:
This method establishes connection with IMAP server.
Category: Mail receive
This method retrieves messages from the remote server as an associative array.
Category: Mail receive
Returns: Message array in the same manner as source for eiseSMTP function.
This function converts mail headers to unicode and updates $overview object that returned by imap_fetch_overview() PHP function and updates the object with corresponding fields with _utf8 suffix: $overview->to_uft8 $overview->from_uft8 $overview->subject_utf8
Category: Message processing
Parameters:
Returns: $overview object
Function that allows to filter mail by its overview. If function returns true, mail attachments will be dowloaded also. This is interface function, to be overridden in extending class. By default it returns true, i.e. all messages will be returned with attachments.
Parameters:
Returns: variant - When it returns false if message will be skipped. If any other value - message will be completely fetched from the server
Callback function to handle current messages stored in $this->msg object
Returns: boolean - If it returns true, receive() method sets flags for it specified in $conf[‘set_flags_on_handle’]
This function saves message in specified IMAP mailbox. It was used in this library to save sent mail to “Sent Items” in function eiseSMTP::send().
Parameters:
Function recursively walks through all $part object and picks up any attachment.
This object is returned by imap_fetchstructure() PHP IMAP function.
There can be 3 cases:
Category: Mail receive
Parameters:
Default configuration associative array:
imap_open()
PHP function , default ‘/imap/ssl’This extension of Exception class should allow us to pass back messages array in its actual state
Receives user message and $messages array
Parameters:
Receives user message and $messages array
Parameters:
$arrMessages {array} array of messages that can be set as an attemp to save unsent / unhandled messages in case of exception.
function __construct($usrMsg, $arrMessages=array()){ parent::__construct($usrMsg); $this->arrMessages = $arrMessages; }
/* This function should be used in ‘catch’ block after eiseMail::send() activation to obtain eiseMail::arrMessages array in its actual state
This class contains basic functions to handle mails/addresses/flow etc
In order to prevent uncovered password display in verbose mode, this function offers partial password coverage. Number of symbols to show is set by eiseMail_base::passSymbolsToShow
. Default value is 3.
Password will be shown with first eiseMail_base::passSymbolsToShow
, all the rest will be replaced with asterisks. Example: echo eiseMail::coverPassword('qwerty'); // will print 'qwe***'
Category: Utilities
Explodes address list according to RFC2822:
"Name Surname" <mailbox@host.domain>
, "Surname, Name" <mailbox1@host.domain>
etc to array. Ordinary explode() will not work, because comma (“,”) can be a part of personal information.
E.g. "John Smith, Mr" <john.smith@domain.com>
Category: Message processing
Parameters:
Returns: array of strings with addresses
Retrieves exact unique addresses from list matching according to RFC2822: “Name Surname” mailbox@host.domain, “Surname, Name” mailbox1@host.domain etc
Category: Message processing
Parameters:
Returns: array of strings with addresses w/o personal info
Gets RFC-compliant mail address to be used with ‘MAIL FROM:’ and ‘RCPT TO:’ SMPT commands
Category: Message processing
Parameters:
Returns: false if $addr contains something wrong. Otherwise removes personal information from the address and returns address like ‘mailbox@domain.com’
It replaces escaped statements (e.g. ##Sender## or ##orderHref##) in $text with values from $arrReplacements array (e.g ‘Sender’ => ‘John Doe’, ‘orderHref’ => ‘http://mysite.com/orders/12345’)
Category: Message processing
Parameters:
Returns: string corrected text
This function retrieves raw message subject from text representation of mail message.
Category: Message processing
Parameters:
Returns: string with subject
This function echoes if ‘verbose’ configuration flag is on.
Category: Utilities
Parameters:
Returns: void