The forge returns a new Email_Driver instance based on the config or input it receives.
Static |
Yes |
Parameters |
Param |
Type |
Default |
Description |
$setup |
mixed |
null
|
Supply null for default config, a setup group name, or a config array. |
$config |
mixed |
null
|
An additional config array to modify default configs on the fly. |
|
Returns |
a new Email_Driver instance |
Example |
$email = \Email::forge();
$email = \Email::forge('my_defaults');
$email = \Email::forge(array(
'driver' => 'smtp',
));
$email = \Email::forge('my_defaults', array(
'driver' => 'smtp',
));
|
Every driver that extends Email_Driver has these methods. They are all you need
to get up and running.
The body converts the input to string and sets the message body.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$body |
string |
required |
The message body. |
|
Returns |
$this |
Example |
$email->body('This is my message.');
$email->body(\View::forge('my/view', $data);
|
The alt_body converts the input to string and sets the message alternative body.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$alt_body |
string |
required |
The message body. |
|
Returns |
$this |
Example |
$email->alt_body('This is my alternative message.');
$email->alt_body(\View::forge('my/alt/view', $data);
|
The priority method sets the mail's priority.
Static |
No |
Parameters |
|
Returns |
$this |
Example |
$email->priority(\Email::P_HIGHEST);
|
The html_body method sets the message body and optionally generates the alt body from it. If specified the inline images will be attached inline automatically.
Please note: By default automatic attaching is on (via config). To turn this off, either supply false, or change the config setting.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$html |
string |
required |
The mail html. |
$generate_alt |
bool |
null
|
Boolean whether to generate an alternative message body, falls back to config default when null is supplied. |
$auto_attach |
bool |
null
|
Set to true or false to attach embedded images, falls back to config default when null is supplied. |
|
Returns |
$this |
Example |
$email->html_body(\View::forge('welcome/email', $data));
$email->html_body(\View::forge('welcome/email', $data), false);
$email->html_body(\View::forge('welcome/email', $data), true, false);
|
The from method sets from address and name.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$email |
string |
required |
The from email. |
$name |
string |
false
|
The from name. |
|
Returns |
$this |
Example |
$email->from('me@example.com', 'My Name');
|
The subject method sets the subject.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$subject |
string |
required |
The email subject. |
|
Returns |
$this |
Example |
$email->subject('This is my subject');
|
The to method adds an address or an array of addresses to the to recipient array.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$email |
string|array |
required |
The from email. |
$name |
string |
false
|
The from name, ignored when $email is an array. |
|
Returns |
$this |
Example |
$email->to('me@example.com', 'My Name');
$email->to(array(
'me@example.com',
'me@example.com' => 'His/Her name.',
));
|
The cc method adds an address or an array of addresses to the cc recipient array.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$email |
string|array |
required |
The from email. |
$name |
string |
false
|
The from name, ignored when $email is an array. |
|
Returns |
$this |
Example |
$email->cc('me@example.com', 'My Name');
$email->cc(array(
'me@example.com',
'me@example.com' => 'His/Her name.',
));
|
The bcc method adds an address or an array of addresses to the bcc recipient array.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$email |
string|array |
required |
The from email. |
$name |
string |
false
|
The from name, ignored when $email is an array. |
|
Returns |
$this |
Example |
$email->bcc('me@example.com', 'My Name');
$email->bcc(array(
'me@example.com',
'me@example.com' => 'His/Her name.',
));
|
The reply_to method adds an address or an array of addresses to the reply to recipient array.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$email |
string|array |
required |
The from email. |
$name |
string |
false
|
The from name, ignored when $email is an array. |
|
Returns |
$this |
Example |
$email->reply_to('me@example.com', 'My Name');
$email->reply_to(array(
'me@example.com',
'me@example.com' => 'His/Her name.',
));
|
The header method adds a custom header to you mail headers.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$header |
string|array |
required |
The header type or array of headers. |
$value |
string |
null
|
The header value. |
|
Returns |
$this |
Example |
$email->header('X-SMTPAP', 'XXXXXXXX');
$email->reply_to(array(
'X-SMTPAP' => 'XXXXXX',
'X-SMTPAP2' => 'XXXXXA',
));
|
The clear_recipients method empties the to, cc and bcc lists.
Static |
No |
Parameters |
None
|
Returns |
$this |
Example |
$email->bcc('me@example.com', 'My Name');
$email->to(array(
'me@example.com',
'me@example.com' => 'His/Her name.',
));
$email->clear_recipients();
|
The clear_addresses method empties the to, cc, bcc and reply to lists.
Static |
No |
Parameters |
None
|
Returns |
$this |
Example |
$email->reply_to('me@example.com', 'My Name');
$email->to(array(
'me@example.com',
'me@example.com' => 'His/Her name.',
));
$email->clear_addresses();
|
The clear_to method empties the to recipient list.
Static |
No |
Parameters |
None
|
Returns |
$this |
Example |
$email->to(array(
'me@example.com',
'me@example.com' => 'His/Her name.',
));
$email->clear_to();
|
The clear_cc method empties the cc recipient list.
Static |
No |
Parameters |
None
|
Returns |
$this |
Example |
$email->cc(array(
'me@example.com',
'me@example.com' => 'His/Her name.',
));
$email->clear_cc();
|
The clear_bcc method empties the bcc recipient list.
Static |
No |
Parameters |
None
|
Returns |
$this |
Example |
$email->bcc(array(
'me@example.com',
'me@example.com' => 'His/Her name.',
));
$email->clear_bcc();
|
The clear_reply_to method empties the reply to list.
Static |
No |
Parameters |
None
|
Returns |
$this |
Example |
$email->reply_to(array(
'me@example.com',
'me@example.com' => 'His/Her name.',
));
$email->clear_reply_to();
|
The attach method attaches a file.
This method will search for the file in the attachment paths set (config/email.php) in the attach_paths array
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$file |
string |
false
|
Path to the file to include. |
$inline |
bool |
false
|
Whether to attach the file inline. |
$cid |
string |
null
|
The content identifier. Used when attaching inline images. |
$mime |
string |
null
|
By default the mimetype is looked up in the core/config/mimes array, use this to overwrite it. |
$name |
string |
null
|
Attachment name overwrite. |
|
Returns |
$this |
Example |
$email->attach(DOCROOT.'attachments/report.pdf');
$email->attach(DOCROOT.'assets/img/mail/header.png', true, 'cid:headerimage');
|
The string_attach method attaches a file from a string input.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$contents |
string |
required |
The attachment contents. |
$filename |
string |
required |
The filename to use. |
$cid |
string |
null
|
The content identifier. Used when attaching inline images. |
$inline |
bool |
false
|
Whether to attach the file inline. |
$mime |
string |
null
|
By default the mimetype is looked up in the core/config/mimes array, use this to overwrite it. |
|
Returns |
$this |
Example |
$email->string_attach('This is a textfile', 'test.txt');
|
The clear_attachments method clears the attachments array.
Static |
No |
Parameters |
None
|
Returns |
$this |
Example |
$email->string_attach('This is a textfile', 'test.txt');
$email->attach(DOCROOT.'uploads/attach.pdf');
$email->clear_attachments();
|
The send method sends the mail.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$validate |
bool |
null
|
Whether to validate the addresses, falls back to config setting. |
|
Returns |
boolean |
Example |
try{
$email->send();
}
catch(\EmailSendingFailedException $e)
{
}
catch(\EmailValidationFailedException $e)
{
}
|
The get_invalid_addresses method returns the email addresses that did not pass validation.
Static |
No |
Parameters |
None
|
Returns |
$this |
Example |
try{
$email->send();
}
catch(\EmailSendingFailedException $e)
{
}
catch(\EmailValidationFailedException $e)
{
$these_failed = $email->get_invalid_addresses();
}
|
The return_path method sets return-path address.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$email |
string |
required |
The return-path email. |
|
Returns |
$this |
Example |
$email->return_path('bounces@example.com');
|
The pipelining method enables pipelining (sending multiple messages in one go). For drivers that
do not support this, this method is a NOOP. Pipelining is disabled by default.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$pipelining |
boolean |
true
|
Whether or not pipelining should be enabled. |
|
Returns |
$this |
Example |
$email->pipelining(true);
|
The get_from method returns the configured "from" address.
Static |
No |
Parameters |
None
|
Returns |
string |
Example |
$from = $email->get_from();
|
The get_to method returns the configured "to" addresses.
Static |
No |
Parameters |
None
|
Returns |
array |
Example |
$to = $email->get_to();
|
The get_cc method returns the configured "cc" addresses.
Static |
No |
Parameters |
None
|
Returns |
array |
Example |
$cc = $email->get_cc();
|
The get_bcc method returns the configured "bcc" addresses.
Static |
No |
Parameters |
None
|
Returns |
array |
Example |
$bcc = $email->get_bcc();
|
The get_reply_to method returns the configured "reply_to" address.
Static |
No |
Parameters |
None
|
Returns |
string |
Example |
$reply_to = $email->get_reply_to();
|
The get_body method returns the email body set.
Static |
No |
Parameters |
None
|
Returns |
string |
Example |
$text = $email->get_body();
|
The get_subject method returns the configured email "subject".
Static |
No |
Parameters |
None
|
Returns |
string |
Example |
$subject = $email->get_subject();
|