Class CakeEmail
Cake e-mail class.
This class is used for handling Internet Message Format based based on the standard outlined in http://www.rfc-editor.org/rfc/rfc2822.txt
Copyright: Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: Cake/Network/Email/CakeEmail.php
Constants summary
Properties summary
-
$_appCharset
publicstring
The application wide charset, used to encode headers and body -
$_attachments
protectedarray
List of files that should be attached to the email. -
$_bcc
protectedarray
Blind Carbon Copy -
$_boundary
protectedstring
If set, boundary to use for multipart mime messages -
$_cc
protectedarray
Carbon Copy -
$_charset8bit
protectedarray
8Bit character sets -
$_config
protectedmixed
Configuration to transport -
$_emailFormat
protectedstring
What format should the email be sent in -
$_emailFormatAvailable
protectedarray
Available formats to be sent. -
$_from
protectedarray
The mail which the email is sent from -
$_headers
protectedarray
Associative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
-
$_helpers
protectedarray
Helpers to be used in the render -
$_htmlMessage
protectedstring
Html message -
$_layout
protectedstring
Layout for the View -
$_message
protectedarray
Final message to send -
$_messageId
protectedmixed
Message ID -
$_readReceipt
protectedarray
The read receipt email -
$_replyTo
protectedarray
The email the recipient will reply to -
$_returnPath
protectedarray
The mail that will be used in case of any errors like - Remote mailserver down - Remote user has exceeded his quota - Unknown user
-
$_sender
protectedarray();
The sender email -
$_subject
protectedstring
The subject of the email -
$_template
protectedstring
Template for the view -
$_textMessage
protectedstring
Text message -
$_to
protectedarray
Recipient of the email -
$_transportClass
protectedInstance of transport class -
$_transportName
protectedstring
What method should the email be sent -
$_viewRender
protectedstring
View for render -
$_viewVars
protectedarray
Vars to sent to render -
$charset
publicstring
Charset the email body is sent in -
$headerCharset
publicstring
Charset the email header is sent in If null, the $charset property will be used as default
Method Summary
-
__construct() public
Constructor -
_addEmail() protected
Add email -
_applyConfig() protected
Apply the config to an instance -
_attachFiles() protected
Attach non-embedded files by adding file contents inside boundaries. -
_attachInlineFiles() protected
Attach inline/embedded files to the message. -
_createBoundary() protected
Create unique boundary identifier -
_encode() protected
Encode the specified string using the current charset -
_encodeString() protected
Translates a string for one charset to another if the App.encoding value differs and the mb_convert_encoding function exists
-
_formatAddress() protected
Format addresses -
_getContentTransferEncoding() protected
Return the Content-Transfer Encoding value based on the set charset -
_getTypes() protected
Gets the text body types that are in this email message -
_readFile() protected
Read the file contents and return a base64 version of the file contents. -
_render() protected
Render the body of the email. -
_renderTemplates() protected
Build and set all the view properties needed to render the templated emails. If there is no template set, the $content will be returned in a hash of the text content types for the email.
-
_setEmail() protected
Set email -
_setEmailSingle() protected
Set only 1 email -
_wrap() protected
Wrap the message to follow the RFC 2822 - 2.1.1 -
addAttachments() public
Add attachments -
addBcc() public
Add Bcc -
addCc() public
Add Cc -
addHeaders() public
Add header for the message -
addTo() public
Add To -
attachments() public
Add attachments to the email message -
bcc() public
Bcc -
cc() public
Cc -
config() public
Configuration to use when send email -
deliver() public static
Static method to fast create an instance of CakeEmail -
emailFormat() public
Email format -
from() public
From -
getHeaders() public
Get list of headers -
helpers() public
Helpers to be used in render -
message() public
Get generated message (used by transport classes) -
messageId() public
Message-ID -
readReceipt() public
Read Receipt (Disposition-Notification-To header) -
replyTo() public
Reply-To -
reset() public
Reset all EmailComponent internal variables to be able to send out a new email. -
returnPath() public
Return Path -
send() public
Send an email using the specified content, template and layout -
sender() public
Sender -
setHeaders() public
Sets headers for the message -
subject() public
Get/Set Subject. -
template() public
Template and layout -
to() public
To -
transport() public
Transport name -
transportClass() public
Return the transport class -
viewRender() public
View class for render -
viewVars() public
Variables to be set on render
Method Detail
__construct() public ¶
__construct( mixed $config = null )
Constructor
Parameters
- mixed $config optional null
- Array of configs, or string to load configs from email.php
_addEmail() protected ¶
_addEmail( string $varName , mixed $email , mixed $name )
Add email
Parameters
- string $varName
- mixed $email
- mixed $name
Returns
Throws
_attachFiles() protected ¶
_attachFiles( string $boundary = null )
Attach non-embedded files by adding file contents inside boundaries.
Parameters
- string $boundary optional null
- Boundary to use. If null, will default to $this->_boundary
Returns
An array of lines to add to the message
_attachInlineFiles() protected ¶
_attachInlineFiles( string $boundary = null )
Attach inline/embedded files to the message.
Parameters
- string $boundary optional null
- Boundary to use. If null, will default to $this->_boundary
Returns
An array of lines to add to the message
_encode() protected ¶
_encode( string $text )
Encode the specified string using the current charset
Parameters
- string $text
- String to encode
Returns
Encoded string
_encodeString() protected ¶
_encodeString( string $text , string $charset )
Translates a string for one charset to another if the App.encoding value differs and the mb_convert_encoding function exists
Parameters
- string $text
- The text to be converted
- string $charset
- the target encoding
Returns
_formatAddress() protected ¶
_formatAddress( array $address )
Format addresses
Parameters
- array $address
Returns
_getContentTransferEncoding() protected ¶
_getContentTransferEncoding( )
Return the Content-Transfer Encoding value based on the set charset
_getTypes() protected ¶
_getTypes( )
Gets the text body types that are in this email message
Returns
Array of types. Valid types are 'text' and 'html'
_readFile() protected ¶
_readFile( string $file )
Read the file contents and return a base64 version of the file contents.
Parameters
- string $file
- The file to read.
Returns
File contents in base64 encoding
_render() protected ¶
_render( string $content )
Render the body of the email.
Parameters
- string $content
- Content to render
Returns
Email body ready to be sent
_renderTemplates() protected ¶
_renderTemplates( string $content )
Build and set all the view properties needed to render the templated emails. If there is no template set, the $content will be returned in a hash of the text content types for the email.
Parameters
- string $content
- The content passed in from send() in most cases.
Returns
The rendered content with html and text keys.
_setEmail() protected ¶
_setEmail( string $varName , mixed $email , mixed $name )
Set email
Parameters
- string $varName
- mixed $email
- mixed $name
Returns
Throws
_setEmailSingle() protected ¶
_setEmailSingle( string $varName , mixed $email , string $name , string $throwMessage )
Set only 1 email
Parameters
- string $varName
- mixed $email
- string $name
- string $throwMessage
Returns
Throws
_wrap() protected ¶
_wrap( string $message )
Wrap the message to follow the RFC 2822 - 2.1.1
Parameters
- string $message
- Message to wrap
Returns
Wrapped message
addAttachments() public ¶
addAttachments( mixed $attachments )
Add attachments
Parameters
- mixed $attachments
- String with the filename or array with filenames
Returns
Throws
addBcc() public ¶
addBcc( mixed $email , string $name = null )
Add Bcc
Parameters
- mixed $email
- String with email, Array with email as key, name as value or email as value (without name)
- string $name optional null
Returns
addCc() public ¶
addCc( mixed $email , string $name = null )
Add Cc
Parameters
- mixed $email
- String with email, Array with email as key, name as value or email as value (without name)
- string $name optional null
Returns
addTo() public ¶
addTo( mixed $email , string $name = null )
Add To
Parameters
- mixed $email
- String with email, Array with email as key, name as value or email as value (without name)
- string $name optional null
Returns
attachments() public ¶
attachments( mixed $attachments = null )
Add attachments to the email message
Attachments can be defined in a few forms depending on how much control you need:
Attach a single file:
{{{ $email->attachments('path/to/file'); }}}
Attach a file with a different filename:
{{{ $email->attachments(array('custom_name.txt' => 'path/to/file.txt')); }}}
Attach a file and specify additional properties:
{{{ $email->attachments(array('custom_name.png' => array( 'file' => 'path/to/file', 'mimetype' => 'image/png', 'contentId' => 'abc123' )); }}}
The contentId
key allows you to specify an inline attachment. In your email text, you
can use <img src="cid:abc123" />
to display the image inline.
Parameters
- mixed $attachments optional null
- String with the filename or array with filenames
Returns
Either the array of attachments when getting or $this when setting.
Throws
bcc() public ¶
bcc( mixed $email = null , string $name = null )
Bcc
Parameters
- mixed $email optional null
- String with email, Array with email as key, name as value or email as value (without name)
- string $name optional null
Returns
cc() public ¶
cc( mixed $email = null , string $name = null )
Cc
Parameters
- mixed $email optional null
- String with email, Array with email as key, name as value or email as value (without name)
- string $name optional null
Returns
config() public ¶
config( mixed $config = null )
Configuration to use when send email
Parameters
- mixed $config optional null
- String with configuration name (from email.php), array with config or null to return current config
Returns
deliver() public static ¶
deliver( mixed $to = null , mixed $subject = null , mixed $message = null , mixed $transportConfig = 'fast' , boolean $send = true )
Static method to fast create an instance of CakeEmail
Parameters
- mixed $to optional null
- Address to send (see CakeEmail::to()). If null, will try to use 'to' from transport config
- mixed $subject optional null
- String of subject or null to use 'subject' from transport config
- mixed $message optional null
- String with message or array with variables to be used in render
- mixed $transportConfig optional 'fast'
- String to use config from EmailConfig or array with configs
- boolean $send optional true
- Send the email or just return the instance pre-configured
Returns
Throws
from() public ¶
from( mixed $email = null , string $name = null )
From
Parameters
- mixed $email optional null
- string $name optional null
Returns
Throws
getHeaders() public ¶
getHeaders( array $include = array() )
Get list of headers
Includes:
from
replyTo
readReceipt
returnPath
to
cc
bcc
subject
Parameters
- array $include optional array()
Returns
helpers() public ¶
helpers( array $helpers = null )
Helpers to be used in render
Parameters
- array $helpers optional null
Returns
message() public ¶
message( mixed $type = null )
Get generated message (used by transport classes)
Parameters
- mixed $type optional null
- Use MESSAGE_* constants or null to return the full message as array
Returns
String if have type, array if type is null
messageId() public ¶
messageId( mixed $message = null )
Message-ID
Parameters
- mixed $message optional null
- True to generate a new Message-ID, False to ignore (not send in email), String to set as Message-ID
Returns
Throws
readReceipt() public ¶
readReceipt( mixed $email = null , string $name = null )
Read Receipt (Disposition-Notification-To header)
Parameters
- mixed $email optional null
- string $name optional null
Returns
Throws
replyTo() public ¶
replyTo( mixed $email = null , string $name = null )
Reply-To
Parameters
- mixed $email optional null
- string $name optional null
Returns
Throws
reset() public ¶
reset( )
Reset all EmailComponent internal variables to be able to send out a new email.
Returns
returnPath() public ¶
returnPath( mixed $email = null , string $name = null )
Return Path
Parameters
- mixed $email optional null
- string $name optional null
Returns
Throws
sender() public ¶
sender( mixed $email = null , string $name = null )
Sender
Parameters
- mixed $email optional null
- string $name optional null
Returns
Throws
setHeaders() public ¶
setHeaders( array $headers )
Sets headers for the message
Parameters
- array $headers
- Associative array containing headers to be set.
Returns
Throws
subject() public ¶
subject( null|string $subject = null )
Get/Set Subject.
Parameters
- null|string $subject optional null
Returns
template() public ¶
template( mixed $template = false , mixed $layout = false )
Template and layout
Parameters
- mixed $template optional false
- Template name or null to not use
- mixed $layout optional false
- Layout name or null to not use
Returns
to() public ¶
to( mixed $email = null , string $name = null )
To
Parameters
- mixed $email optional null
- Null to get, String with email, Array with email as key, name as value or email as value (without name)
- string $name optional null
Returns
transport() public ¶
transport( string $name = null )
Transport name
Parameters
- string $name optional null
Returns
viewRender() public ¶
viewRender( string $viewClass = null )
View class for render
Parameters
- string $viewClass optional null
Returns
viewVars() public ¶
viewVars( array $viewVars = null )
Variables to be set on render
Parameters
- array $viewVars optional null
Returns
Properties detail
$_attachments ¶
List of files that should be attached to the email.
Only absolute paths
array()
$_bcc ¶
Blind Carbon Copy
List of email's that should receive a copy of the email. The Recipient WILL NOT be able to see this list
array()
$_cc ¶
Carbon Copy
List of email's that should receive a copy of the email. The Recipient WILL be able to see this list
array()
$_emailFormatAvailable ¶
Available formats to be sent.
array('text', 'html', 'both')
$_headers ¶
Associative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
array()
$_returnPath ¶
The mail that will be used in case of any errors like - Remote mailserver down - Remote user has exceeded his quota - Unknown user
array()
$headerCharset ¶
Charset the email header is sent in If null, the $charset property will be used as default
null