The Mailer class handles incoming and outoing E-mail messages. It can connect to a mailserver using the IMAP or POP3 protocols to customizable server ports. Sending mail is currently done using the PHP mail() function which by default uses the local sendmail daemon to send mail.
MAILER_IMAP | Constant for connecting using the IMAP protocol (default) |
MAILER_POP3 | Constant for connecting using the POP3 protocol |
Opening a Mailbox and fetching all the messages into an array of MailMessage instances:
try { $mailer = new Mailer( "myserver.mydomain.se", "myUsername", "myPassword" ); $messages = $mailer->fetchMail(); } catch( Exception $e ) { die ( $e->getMessage() ); } print_r( $messages );
Opening a mailbox, fetching the first ten messages and saving the first messages attachments to file:
try { $mailer = new Mailer( "myserver.mydomain.se", "myUserName", "myPassword" ); $messages = $mailer->fetchMail( 1,10 ); } catch( Exception $e ) { die( $e->getMessage() ); } foreach( $messages[0]->attachments AS $attachment ) { $attachment->saveFile(); }
Send a simple E-mail message:
$message = new MailMessage( "toaddress@mydomain.se", "Subject goes here","Body of message", "fromaddress@mydomain.se" ); $message->send();
Send an E-mail message with an attached file:
$message = new MailMessage( "toaddress@mydomain.se", "Subject goes here", "The text of the message", "fromaddress@mydomain.se" ); $message->attachments[] = new MailAttachment( "/path/to/attached/file.here" ); $message->send();