-
Notifications
You must be signed in to change notification settings - Fork 1
The email library allows you to easily send HTML emails to one person or a group of people. To load the email library manually you may do this:
load::library('email');
- Basic Usage
- Multiple Recipients
- Attachments
###Basic Usage Sending an email to one person is pretty straight forward:
$mail = new email();
$mail->to('xxx@xxx.com');
$mail->from('Your Name <yyy@yyy.com>');
$mail->subject('Testing');
$mail->content('<strong>Hello, World!</strong>');
$mail->send();
###Multiple Recipients Sending an email to many persons is pretty easy as well:
$mail = new email();
$mail->to('aaa@aaa.com');
$mail->to('xxx@xxx.com');
$mail->to('zzz@zzz.com');
$mail->from('Your Name <yyy@yyy.com>');
$mail->subject('Testing');
$mail->content('<strong>Hello, World!</strong>');
$mail->send();
The email library sends a seperate email to each recipient, so there is no limit as to how many people you can send one email to and you do not have to worry about other people seeing each others email addresses.
The above three to()
methods can also be combined into one:
$mail = new email();
$mail->to('aaa@aaa.com','xxx@xxx.com','zzz@zzz.com');
$mail->from('Your Name <yyy@yyy.com>');
$mail->subject('Testing');
$mail->content('<strong>Hello, World!</strong>');
$mail->send();
And if you want to get really fancy you could format the above code like so:
$mail = new email();
$mail->to('aaa@aaa.com','xxx@xxx.com','zzz@zzz.com')
->from('Your Name <yyy@yyy.com>')
->subject('Testing')
->content('<strong>Hello, World!</strong>')
->send();
###Attachments You can easily attach multiple files to an e-mail.
$mail = new email();
$mail->to('xxx@xxx.com');
$mail->from('Your Name <yyy@yyy.com>');
$mail->subject('Testing');
$mail->content('<strong>Hello, World!</strong>');
$mail->attachment('file.jpg');
$mail->attachment('another.zip','application/octet-stream','new-name.zip');
$mail->send();
The first argument is the local file that you want to attach. The second argument is the content MIME type and the default value is application/octet-stream
. The last argument allows you to specify a new file name for the attached file.