The expMail class
package |
Subsystems |
---|
__construct(array $params = array())
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
can specify how you would like to send mail, overriding the system default. //Here you are using the system default, whether it is smtp, php mail, sendmail, exim, native, or rotator. $emailItem = new expMail(); //Here you are trying different types of connections: $emailItem = new expMail(array('method'=>'smtp')); $emailItem = new expMail(array('method'=>'sendmail'); $emailItem = new expMail(array('method'=>'exim'); $emailItem = new expMail(array('method'=>'native'); $emailItem = new expMail(array('method'=>'rotator'); |
todo |
add support for telling the constructor where the system specific Mail Transit Authority is: i.e. where sendmail or exim is if not in the default /usr/sbin drop support for passing in custom "connections", a Swift 3.x relic that we do not need. add further documentation for using settings other than the system default |
array
You can specify which method by which you would like to send mail.
__destruct()
addBcc(string $email, string $name = null)
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
will send a basic message, looping through an array of email addresses add adding them to the BCC list. $emailItem = new expMail(); $emailItem->addText('My Text '); $emailItem->addText('Line Two '); $emailItem->addText('Line Three '); $bccs = array('a@website.com'=>'Mr A.', 'b@website.com'=>'Mr B.', 'c@website.com'=>'Mr C.', 'd@website.com'=>'Mr D.', 'e@website.com'=>'Mr E.', 'f@website.com'=>'Mr F.'); //add multiple bcc recipients to the email foreach ($bccs as $email => $name) { $emailItem->addBcc($email, $name); } $emailItem->addTo(array('myemail@mysite.com', 'secondemail@website.com', 'third@emailsite.com')); $emailItem->addFrom('from@sender.com'); //setting the From field using just the email. $emailItem->subject('Hello World!'); $emailItem->send(); |
string
This is the email address for the BCC.
string
This is the name associated with the above email address.
addCc(string $email, string $name = null)
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
will send a basic message, looping through an array of email addresses add adding them to the CC list. $emailItem = new expMail(); $emailItem->addText('My Text '); $emailItem->addText('Line Two '); $emailItem->addText('Line Three '); $ccs = array('a@website.com'=>'Mr A.', 'b@website.com'=>'Mr B.', 'c@website.com'=>'Mr C.', 'd@website.com'=>'Mr D.', 'e@website.com'=>'Mr E.', 'f@website.com'=>'Mr F.'); //add multiple cc recipients to the email foreach ($ccs as $email => $name) { $emailItem->addCc($email, $name); } $emailItem->addTo(array('myemail@mysite.com', 'secondemail@website.com', 'third@emailsite.com')); $emailItem->addFrom('from@sender.com'); //setting the From field using just the email. $emailItem->subject('Hello World!'); $emailItem->send(); |
string
This is the email address for the CC.
string
This is the name associated with the above email address.
addFrom(string $email = null)
It also sets the private var from with whatever you desire. This is a relic from the Swift 3.x days and should be gutted out the next time someone upgrades the mailer.
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
will send a basic message, but you can see how the subject line works. $emailItem = new expMail(); $emailItem->addText('My Text '); $emailItem->addText('Line Two '); $emailItem->addText('Line Three '); $emailItem->addTo(array('myemail@mysite.com', 'secondemail@website.com', 'third@emailsite.com')); $emailItem->addFrom('from@sender.com'); //setting the From field using just the email. $emailItem->addFrom('from@sender.com', 'Mr. Sender'); //resetting the From field using the email and the name. $emailItem->subject('Hello World!'); $emailItem->send(); |
string
This is the email address you want to use as the sender.
addHeaders(array $headers)
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
will include the passed HTML and will set it as an addition to the message body. $emailItem = new expMail(); $emailItem->addHTML(' My Text'); //This adds an alternate version if your email in HTML format$emailItem->addTo('myemail@mysite.com'); $emailItem->addFrom('from@sender.com'); $emailItem->subject('Hello World!'); $headersToAdd = array('Your-Header-Name' => 'the header value', 'SecondHeader-Name' => '2nd header value'); $emailItem->addHeaders($headersToAdd); $emailItem->send(); |
todo |
add support for other types of headers mentioned below, and a second pass in value/switch to specify what kind headers you are adding Text Headers
Parameterized Headers
Date Headers
Mailbox (e-mail address) Headers
ID Headers
Path Headers
|
array
Array of text headers to add to the message
addHTML(string $html)
setHTMLBody is to be preferred as the default for setting the body of the email.
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
will include the passed HTML and will set it as an addition to the message body. $emailItem = new expMail(); $emailItem->addHTML(' My Text'); //This adds an alternate version if your email in HTML format$emailItem->addTo('myemail@mysite.com'); $emailItem->addFrom('from@sender.com'); $emailItem->subject('Hello World!'); $emailItem->send(); You can also call the addHTML multiple times to append to the message: $emailItem = new expMail(); $emailItem->addHTML('My HTML $emailItem->addTo('myemail@mysite.com'); $emailItem->addFrom('from@sender.com'); $emailItem->subject('Hello World!'); $emailItem->send(); |
string
This is the html that you want added to the message.
addRaw( $body)
addSubject(string $subj)
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
will send a basic message, but you can see how the subject line works. $emailItem = new expMail(); $emailItem->addText('My Text '); $emailItem->addText('Line Two '); $emailItem->addText('Line Three ');
$emailItem->addFrom('from@sender.com'); $emailItem->subject('Hello World!'); $emailItem->send(); |
string
This is the string that you want to be used as the subject for the message, it must be plain text.
addText(string $text)
Every email send out should have an HTML version and a TEXT version.
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
will set the message body in HTML and also include a text counterpart in case the recipient cannot view HTML. $emailItem = new expMail(); $emailItem->setHTMLBody('My Text '); //This is an HTML version of the message $emailItem->addText('My Text '); //This adds a Text version in case they cannot read HTML $emailItem->addTo('myemail@mysite.com'); $emailItem->addFrom('from@sender.com'); $emailItem->subject('Hello World!'); $emailItem->send(); |
string
This is the text version of the email you are sending along with the HTML
addTo(array|string $email = null)
If the first variable passed is an array, it assumes you are sending messages to multiple people. If you want to add people with their names associated with the email, you must use an outside for loop. This function does not yet support the parsing of associative arrays for a quick add to the To recipient list.
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
will send a basic message, looping through an array of email addresses add adding them to the BCC list. $emailItem = new expMail(); $emailItem->addText('My Text '); $emailItem->addText('Line Two '); $emailItem->addText('Line Three '); $to_array = array('a@website.com'=>'Mr A.', 'b@website.com'=>'Mr B.', 'c@website.com'=>'Mr C.', 'd@website.com'=>'Mr D.', 'e@website.com'=>'Mr E.', 'f@website.com'=>'Mr F.'); //add multiple bcc recipients to the email foreach ($to_array as $email => $name) { $emailItem->addBcc($email, $name); } $emailItem->addFrom('from@sender.com'); $emailItem->subject('Hello World!'); $emailItem->send(); //You can also just specify the email without the name, like so: $emailItem = new expMail(); $emailItem->addText('My Text '); $emailItem->addText('Line Two '); $emailItem->addText('Line Three '); $emailItem->addTo('bob@smith.com'); $emailItem->addFrom('from@sender.com'); $emailItem->subject('Hello World!'); $emailItem->send(); //You can also send an array of email addresses as the first argument, like so: $emailItem = new expMail(); $emailItem->addText('My Text '); $emailItem->addText('Line Two '); $emailItem->addText('Line Three '); $emailItem->addTo(array('myemail@mysite.com', 'secondemail@website.com', 'third@emailsite.com')); $emailItem->addFrom('from@sender.com'); $emailItem->subject('Hello World!'); $emailItem->send(); |
todo |
A nice future feature addition would be to allow the passing in of associative arrays like so: $emailsToSendTo = array('bob@smith.com'=>'Bob Smith', 'mary@smith.com'=>'Mary Smith'); $emailItem->addTo($emailsToSendTo); OR $emailItem->addTo('array('myemail@mysite.com'=>'Website Owner', 'secondemail@website.com'=>'Frank Jones'); Actually, cleanup should be done so that this function only takes associative arrays, and nothing else. |
array|string
This is the string or array to send email to
attach_file_on_disk(string $file_to_attach, string $file_type)
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
will show three different ways to attach files, two from a path on disk, and one from a url. //Create the attachment // * Note that you can technically leave the content-type parameter out $attachment = Swift_Attachment::fromPath('/path/to/image.jpg', 'image/jpeg');
|
string
This is the path to the file that you want to attach to the message
string
This is the MIME type of the file that you are attaching
batchSend() : void
This should probably be taken out as it look like a failed attempt to use the old-school AntiFlood plugin This is leftover code from Swift 3.x
todo |
Update this section to use batch processing properly |
---|---|
author |
Tyler Smart tyleresmart@gmail.com |
clearBody()
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
flushRecipients()
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
will set some recipients and then clear them $emailItem = new expMail(); $emailItem->addText('My Text '); $emailItem->addText('Line Two '); $emailItem->addText('Line Three '); $emailItem->addTo('bob@smith.com', 'Bob Smith'); $emailItem->addTo('bob2@smith.com', 'Bob2 Smith'); $emailItem->addTo('bob3@smith.com', 'Bob3 Smith'); $emailItem->flushRecipients(); $emailItem->addTo('whataboutbob@smith.com', 'Frank Smith'); $emailItem->send(); |
quickBatchSend(array $params = array()) : boolean|integer
quickSend(array $params = array()) : integer
todo |
May add allowing a string param to be passed as the message (text_message) using all defaults to mail it. |
---|---|
author |
Tyler Smart tyleresmart@gmail.com |
example |
will send a quick message, showing you what basic fields are required. $body = "My body."; $tos = explode(',', str_replace(' ', '', COMMENTS_NOTIFICATION_EMAIL)); //pull list of CSV emails from the site config $subject = "My subject"; $mail = new expMail(); $mail->quickSend(array( 'html_message'=>$body, 'to'=>$tos, 'from'=>trim(SMTP_FROMADDRESS), //pull EMAIL from site config 'subject'=>$subject, )); (or even simpler) $mail = new expMail(); $mail->quickSend(array('html_message'=>'Hello')); |
array
This is the associative array required to send the email. The minimum basics for sending an email are: -html_message or -text_message If a from or a to is not specified, the send method will pull the default SMTP_FROMADDRESS from the site config. Usable parameters include: -to -from -subject -html_message -text_message -headers
integer
number of recipients to which the email was successfully sent.
send()
setHTMLBody(string $html)
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
will set the message body to the HTML that is passed in. This is the standard way to set the email message body. $emailItem = new expMail(); $emailItem->setHTMLBody(' My Text'); //This sets the body to be an HTML version$emailItem->addTo('myemail@mysite.com'); $emailItem->addFrom('from@sender.com'); $emailItem->subject('Hello World!'); $emailItem->send(); |
string
This is the HTML that you want set as the body
setTextBody(string $text)
author |
Tyler Smart tyleresmart@gmail.com |
---|---|
example |
will set the message body to plain text. Usually people do this because the recipient cannot read HTML email. $emailItem = new expMail(); $emailItem->setTextBody('My Text '); //This adds a Text version in case they cannot read HTML $emailItem->addTo('myemail@mysite.com'); $emailItem->addFrom('from@sender.com'); $emailItem->subject('Hello World!'); $emailItem->send(); |
string
This is the text version of the email you are sending
test()
todo |
Update this section to use more error checking |
---|---|
to :
from :
cc :
bcc :
subject :
log :
errStack :
transport :
mailer :
precallfunction :
precalldata :
postcallfunction :
postcalldata :