Email class methods
forge($setup = null, array $config = array())
The forge returns a new Email_Driver instance based on the config or input it receives.
Static |
Yes |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$arr |
mixed |
null
|
Supply null for default config, a setup group name, or a config array. |
$arr |
mixed |
null
|
An additional config array to modify default configs on the fly. |
|
返り値 |
a new Email_Driver instance |
例 |
// Plain an simple:
$email = \Email::forge();
// Config loaded from a group
$email = \Email::forge('my_defaults');
// Config supplied
$email = \Email::forge(array(
'driver' => 'smtp',
));
// Loaded config from group with an dynamic overwrite
$email = \Email::forge('my_defaults', array(
'driver' => 'smtp',
));
|
Email driver methods
Every driver that extends Email_Driver has these methods. They are all you need
to get up and running.
body($body)
The body converts the input to string and sets the message body.
Static |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$arr |
string |
required |
The message body. |
|
返り値 |
$this |
例 |
$email->body('This is my message.');
//or pass it a View
$email->body(\View::forge('my/view', $data);
|
alt_body($alt_body)
The alt_body converts the input to string and sets the message alternative body.
Static |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$arr |
string |
required |
The message body. |
|
返り値 |
$this |
例 |
$email->alt_body('This is my alternative message.');
//or pass it a View
$email->alt_body(\View::forge('my/alt/view', $data);
|
priority($priority)
The priority method sets the mail's priority.
Static |
No |
パラメータ |
|
返り値 |
$this |
例 |
$email->priority(\Email::P_HIGHEST);
|
html_body($html, $generate_alt = null, $auto_attach = null)
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 |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$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. |
|
返り値 |
$this |
例 |
$email->html_body(\View::forge('welcome/email', $data));
// Don't generate the alt body
$email->html_body(\View::forge('welcome/email', $data), false);
// Do generate the alt body, but don't auto attach images.
$email->html_body(\View::forge('welcome/email', $data), true, false);
|
from($email, $name = false)
The from method sets from address and name.
Static |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$email |
string |
required |
The from email. |
$name |
string |
false
|
The from name. |
|
返り値 |
$this |
例 |
$email->from('me@example.com', 'My Name');
|
subject($subject)
The subject method sets the subject.
Static |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$subject |
string |
required |
The email subject. |
|
返り値 |
$this |
例 |
$email->subject('This is my subject');
|
to($email, $name = false)
The to method adds an address or an array of addresses to the to recipient array.
Static |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$email |
string|array |
required |
The from email. |
$name |
string |
false
|
The from name, ignored when $email is an array. |
|
返り値 |
$this |
例 |
// Add a single address
$email->to('me@example.com', 'My Name');
// Add multiple addresses
$email->to(array(
'me@example.com',
// with a name
'me@example.com' => 'His/Her name.',
));
|
cc($email, $name = false)
The cc method adds an address or an array of addresses to the cc recipient array.
Static |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$email |
string|array |
required |
The from email. |
$name |
string |
false
|
The from name, ignored when $email is an array. |
|
返り値 |
$this |
例 |
// Add a single address
$email->cc('me@example.com', 'My Name');
// Add multiple addresses
$email->cc(array(
'me@example.com',
// with a name
'me@example.com' => 'His/Her name.',
));
|
bcc($email, $name = false)
The bcc method adds an address or an array of addresses to the bcc recipient array.
Static |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$email |
string|array |
required |
The from email. |
$name |
string |
false
|
The from name, ignored when $email is an array. |
|
返り値 |
$this |
例 |
// Add a single address
$email->bcc('me@example.com', 'My Name');
// Add multiple addresses
$email->bcc(array(
'me@example.com',
// with a name
'me@example.com' => 'His/Her name.',
));
|
reply_to($email, $name = false)
The reply_to method adds an address or an array of addresses to the reply to recipient array.
Static |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$email |
string|array |
required |
The from email. |
$name |
string |
false
|
The from name, ignored when $email is an array. |
|
返り値 |
$this |
例 |
// Add a single address
$email->reply_to('me@example.com', 'My Name');
// Add multiple addresses
$email->reply_to(array(
'me@example.com',
// with a name
'me@example.com' => 'His/Her name.',
));
|
The header method adds a custom header to you mail headers.
Static |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$header |
string|array |
required |
The header type or array of headers. |
$value |
string |
null
|
The header value. |
|
返り値 |
$this |
例 |
// Add a single address
$email->header('X-SMTPAP', 'XXXXXXXX');
// Add multiple addresses
$email->reply_to(array(
'X-SMTPAP' => 'XXXXXX',
'X-SMTPAP2' => 'XXXXXA',
));
|
clear_recipients()
The clear_recipients method empties the to, cc and bcc lists.
Static |
No |
パラメータ |
None
|
返り値 |
$this |
例 |
// Add a single address
$email->bcc('me@example.com', 'My Name');
// Add multiple addresses
$email->to(array(
'me@example.com',
// with a name
'me@example.com' => 'His/Her name.',
));
// Reset them
$email->clear_recipients();
|
clear_addresses()
The clear_addresses method empties the to, cc, bcc and reply to lists.
Static |
No |
パラメータ |
None
|
返り値 |
$this |
例 |
// Add a single address
$email->reply_to('me@example.com', 'My Name');
// Add multiple addresses
$email->to(array(
'me@example.com',
// with a name
'me@example.com' => 'His/Her name.',
));
// Reset them
$email->clear_addresses();
|
clear_to()
The clear_to method empties the to recipient list.
Static |
No |
パラメータ |
None
|
返り値 |
$this |
例 |
// Add multiple addresses
$email->to(array(
'me@example.com',
// with a name
'me@example.com' => 'His/Her name.',
));
// Reset them
$email->clear_to();
|
clear_cc()
The clear_cc method empties the cc recipient list.
Static |
No |
パラメータ |
None
|
返り値 |
$this |
例 |
// Add multiple addresses
$email->cc(array(
'me@example.com',
// with a name
'me@example.com' => 'His/Her name.',
));
// Reset them
$email->clear_cc();
|
clear_bcc()
The clear_bcc method empties the bcc recipient list.
Static |
No |
パラメータ |
None
|
返り値 |
$this |
例 |
// Add multiple addresses
$email->bcc(array(
'me@example.com',
// with a name
'me@example.com' => 'His/Her name.',
));
// Reset them
$email->clear_bcc();
|
clear_reply_to()
The clear_reply_to method empties the reply to list.
Static |
No |
パラメータ |
None
|
返り値 |
$this |
例 |
// Add multiple addresses
$email->reply_to(array(
'me@example.com',
// with a name
'me@example.com' => 'His/Her name.',
));
// Reset them
$email->clear_reply_to();
|
attach($file, $inline = false, $cid = null, $mime = null)
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 |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$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. |
|
返り値 |
$this |
例 |
// Add an attachment
$email->attach(DOCROOT.'attachments/report.pdf');
// Attach an image inline
$email->attach(DOCROOT.'assets/img/mail/header.png', true, 'cid:headerimage');
// This image would be bound to <img src="cid:headerimage" />
|
string_attach($contents, $filename, $cid = null, $inline = false, $mime = null)
The string_attach method attaches a file from a string input.
Static |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$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. |
|
返り値 |
$this |
例 |
// Add an attachment
$email->string_attach('This is a textfile', 'test.txt');
|
clear_attachments()
The clear_attachments method clears the attachments array.
Static |
No |
パラメータ |
None
|
返り値 |
$this |
例 |
// Add some attachments
$email->string_attach('This is a textfile', 'test.txt');
$email->attach(DOCROOT.'uploads/attach.pdf');
// And empty the attachments
$email->clear_attachments();
|
send()
The send method sends the mail.
Static |
No |
パラメータ |
None
|
返り値 |
$this |
例 |
try{
$email->send();
}
catch(\EmailSendingFailedException $e)
{
// The driver could not send the mail.
}
catch(\EmailValidationFailedException $e)
{
// One or more email addresses failed validation.
}
|
get_invalid_addresses()
The get_invalid_addresses method returns the email addresses that did not pass validation.
Static |
No |
パラメータ |
None
|
返り値 |
$this |
例 |
try{
$email->send();
}
catch(\EmailSendingFailedException $e)
{
// The driver could not send the mail.
}
catch(\EmailValidationFailedException $e)
{
// One or more email addresses failed validation.
$these_failed = $email->get_invalid_addresses();
}
|
return_path($email)
The return_path method sets return-path address.
Static |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$email |
string |
required |
The return-path email. |
|
返り値 |
$this |
例 |
$email->return_path('bounces@example.com');
|