Public Member Functions | |
| __construct ($src, $encoding='UTF-8', $crlf="\n") | |
| setSubject ($subject) | |
| setTo ($email) | |
| addTextMessage ($msg) | |
| setReturnPath ($email) | |
| addHeaders ($hdrs) | |
| addHtmlMessage ($msg) | |
| addAttachment ($file, $ctype='text/plain') | |
| sendMail () | |
| close () | |
Public Attributes | |
| $headers = array() | |
| $message | |
| $encoding = 'utf-8' | |
| $crlf = "\n" | |
| $from = '' | |
Protected Attributes | |
| $backend = null | |
This class is just a small wrapper around the PEAR packages Mail and Mail/mime.
Class to easily generate multipart emails. It supports embedded images within the email. It can be used to send a text with possible attachments.
The encoding of the message is utf-8 by default.
Usage example: $email = new Pluf_Mail_Batch('from_email.com'); foreach($emails as $m) { $email->setSubject($m['subject']); $email->setTo($m['to']); $img_id = $email->addAttachment('/var/www/html/img/pic.jpg', 'image/jpg'); $email->addTextMessage($m['content']); $email->sendMail(); } $email->close();
The configuration parameters are the one for Mail::factory with the 'mail_' prefix not to conflict with the other parameters.
'mail_backend' - 'mail', 'smtp' or 'sendmail' (default 'mail').
List of parameter for the backends:
mail backend --------------
If safe mode is disabled, an array with all the 'mail_*' parameters excluding 'mail_backend' will be passed as the fifth argument to the PHP mail() function. The elements will be joined as a space-delimited string.
sendmail backend ------------------
'mail_sendmail_path' - The location of the sendmail program on the filesystem. Default is /usr/bin/sendmail 'sendmail_args' - Additional parameters to pass to the sendmail. Default is -i
smtp backend --------------
'mail_host' - The server to connect. Default is localhost 'mail_port' - The port to connect. Default is 25 'mail_auth' - Whether or not to use SMTP authentication. Default is FALSE
'mail_username' - The username to use for SMTP authentication. 'mail_password' - The password to use for SMTP authentication. 'mail_localhost' - The value to give when sending EHLO or HELO. Default is localhost 'mail_timeout' - The SMTP connection timeout. Default is NULL (no timeout) 'mail_verp' - Whether to use VERP or not. Default is FALSE 'mail_debug' - Whether to enable SMTP debug mode or not. Default is FALSE 'mail_persist' - Will automatically be set to true.
If you are doing some testing, you should use the smtp backend together with fakemail: http://www.lastcraft.com/fakemail.php
| Pluf_Mail_Batch::__construct | ( | $ | src, | |
| $ | encoding = 'UTF-8', |
|||
| $ | crlf = "\n" | |||
| ) |
Construct the base email.
| string | The email of the sender. | |
| string | Encoding of the message ('UTF-8') | |
| string | End of line type ("\n") |
| Pluf_Mail_Batch::setSubject | ( | $ | subject | ) |
Set the subject of the email.
| string | Subject |
| Pluf_Mail_Batch::setTo | ( | $ | ) |
Set the recipient of the email.
| string | Recipient email |
| Pluf_Mail_Batch::addTextMessage | ( | $ | msg | ) |
Add the base plain text message to the email.
| string | The message |
| Pluf_Mail_Batch::setReturnPath | ( | $ | ) |
Set the return path for the email.
| string |
| Pluf_Mail_Batch::addHeaders | ( | $ | hdrs | ) |
Add headers to an email.
| array | Array of headers |
| Pluf_Mail_Batch::addHtmlMessage | ( | $ | msg | ) |
Add the alternate HTML message to the email.
| string | The HTML message |
| Pluf_Mail_Batch::addAttachment | ( | $ | file, | |
| $ | ctype = 'text/plain' | |||
| ) |
Add an attachment to the message.
The file to attach must be available on disk and you need to provide the mimetype of the attachment manually.
| string | Path to the file to be added. | |
| string | Mimetype of the file to be added ('text/plain'). |
| Pluf_Mail_Batch::sendMail | ( | ) |
Effectively sends the email.
| Pluf_Mail_Batch::close | ( | ) |
| Pluf_Mail_Batch::$headers = array() |
| Pluf_Mail_Batch::$message |
| Pluf_Mail_Batch::$encoding = 'utf-8' |
| Pluf_Mail_Batch::$crlf = "\n" |
| Pluf_Mail_Batch::$from = '' |
Pluf_Mail_Batch::$backend = null [protected] |