Class EmailComponent
EmailComponent
This component is used for handling Internet Message Format based based on the standard outlined in http://www.rfc-editor.org/rfc/rfc2822.txt
- Object
- EmailComponent
Link: http://book.cakephp.org/1.3/en/The-Manual/Core-Components/Email.html
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: controller/components/email.php
Properties summary
-
$__boundary
publicstring
If set, boundary to use for multipart mime messages -
$__header
publicarray
Temporary store of message header lines -
$__message
publicarray
Temporary store of message lines -
$__smtpConnection
publicresource
Variable that holds SMTP connection -
$_lineLength
public -
$additionalParams
publicstring
List of additional headers -
$attachments
publicarray
List of files that should be attached to the email. -
$bcc
publicarray
Blind Carbon Copy -
$cc
publicarray
Carbon Copy -
$charset
publicstring
charset the email is sent in -
$date
publicstring
The date to put in the Date: header. This should be a date conformant with the RFC2822 standard. Leave null, to have today's date generated.
-
$delivery
publicstring
What method should the email be sent by -
$filePaths
publicarray
The list of paths to search if an attachment isnt absolute -
$from
publicstring
The mail which the email is sent from -
$headers
publicarray
Associative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
-
$htmlMessage
publicstring
Contains the rendered HTML message if one was sent. -
$layout
publicstring
Layout for the View -
$lineFeed
publicstring
Line feed character(s) to be used when sending using mail() function By default PHP_EOL is used. RFC2822 requires it to be CRLF but some Unix mail transfer agents replace LF by CRLF automatically (which leads to doubling CR if CRLF is used).
-
$lineLength
publicinteger
as per RFC2822 Section 2.1.1 -
$messageId
publicmixed
Whether to generate a Message-ID header for the e-mail. True to generate a Message-ID, False to let it be handled by sendmail (or similar) or a string to completely override the Message-ID.
-
$readReceipt
publicstring
The read receipt email -
$replyTo
publicstring
The email the recipient will reply to -
$return
publicstring
The mail that will be used in case of any errors like - Remote mailserver down - Remote user has exceeded his quota - Unknown user
-
$sendAs
publicstring
What format should the email be sent in -
$smtpError
publicstring
Placeholder for any errors that might happen with the smtp mail methods
-
$smtpOptions
publicarray
List of options to use for smtp mail method -
$subject
publicstring
The subject of the email -
$template
publicstring
Template for the view -
$textMessage
publicstring
Contains the rendered plain text message if one was sent. -
$to
publicstring
Recipient of the email -
$xMailer
publicstring
What mailer should EmailComponent identify itself as
Method Summary
-
_attachFiles() public
Attach files by adding file contents inside boundaries. -
_createHeader() public
Create emails headers including (but not limited to) from email address, reply to, bcc and cc.
-
_createboundary() public
Create unique boundary identifier -
_debug() public
Set as controller flash message a debug message showing current settings in component -
_encode() public
Encode the specified string using the current charset -
_findFiles() public
Find the specified attachment in the list of file paths -
_formatAddress() public
Format a string as an email address -
_formatMessage() public
Format the message by seeing if it has attachments. -
_getSocket() public
Helper method to get socket, overridden in tests -
_mail() public
Wrapper for PHP mail function used for sending out emails -
_render() public
Render the contents using the current layout and template. -
_smtp() public
Sends out email via SMTP -
_smtpSend() public
Protected method for sending data to SMTP connection -
_strip() public
Remove certain elements (such as bcc:, to:, %0a) from given value. Helps prevent header injection / mainipulation on user content.
-
_wrap() public
Wrap the message using EmailComponent::$lineLength -
header() public
Sets headers for the message -
initialize() public
Initialize component -
reset() public
Reset all EmailComponent internal variables to be able to send out a new email. -
send() public
Send an email using the specified content, template and layout -
startup() public
Startup component
Method Detail
_attachFiles() public ¶
_attachFiles( )
Attach files by adding file contents inside boundaries.
Todo:
_createHeader() public ¶
_createHeader( )
Create emails headers including (but not limited to) from email address, reply to, bcc and cc.
_debug() public ¶
_debug( )
Set as controller flash message a debug message showing current settings in component
Returns
Success
_encode() public ¶
_encode( string $subject )
Encode the specified string using the current charset
Parameters
- string $subject
- String to encode
Returns
Encoded string
_findFiles() public ¶
_findFiles( string $attachment )
Find the specified attachment in the list of file paths
Parameters
- string $attachment
- Attachment file name to find
Returns
Path to located file
_formatAddress() public ¶
_formatAddress( string $string , $smtp = false )
Format a string as an email address
Parameters
- string $string
- String representing an email address
- $smtp optional false
Returns
Email address suitable for email headers or smtp pipe
_formatMessage() public ¶
_formatMessage( string $message )
Format the message by seeing if it has attachments.
Parameters
- string $message
- Message to format
_getSocket() public ¶
_getSocket( array $config )
Helper method to get socket, overridden in tests
Parameters
- array $config
- Config data for the socket.
_mail() public ¶
_mail( )
Wrapper for PHP mail function used for sending out emails
Returns
Success
_render() public ¶
_render( string $content )
Render the contents using the current layout and template.
Parameters
- string $content
- Content to render
Returns
Email ready to be sent
_smtpSend() public ¶
_smtpSend( string $data , mixed $checkCode = '250' )
Protected method for sending data to SMTP connection
Parameters
- string $data
- data to be sent to SMTP server
- mixed $checkCode optional '250'
- code to check for in server response, false to skip
Returns
Success
_strip() public ¶
_strip( string $value , boolean $message = false )
Remove certain elements (such as bcc:, to:, %0a) from given value. Helps prevent header injection / mainipulation on user content.
Parameters
- string $value
- Value to strip
- boolean $message optional false
- Set to true to indicate main message content
Returns
Stripped value
_wrap() public ¶
_wrap( string $message , integer $lineLength = null )
Wrap the message using EmailComponent::$lineLength
Parameters
- string $message
- Message to wrap
- integer $lineLength optional null
- Max length of line
Returns
Wrapped message
header() public ¶
header( array $headers )
Sets headers for the message
Parameters
- array $headers
- array containing headers to be set.
initialize() public ¶
initialize( object $controller , $settings = array() )
Initialize component
Parameters
- object $controller
- Instantiating controller
- $settings optional array()
reset() public ¶
reset( )
Reset all EmailComponent internal variables to be able to send out a new email.
Link
send() public ¶
send( mixed $content = null , string $template = null , string $layout = null )
Send an email using the specified content, template and layout
Parameters
- mixed $content optional null
Either an array of text lines, or a string with contents If you are rendering a template this variable will be sent to the templates as
$content
- string $template optional null
- Template to use when sending email
- string $layout optional null
- Layout to use to enclose email body
Returns
Success
Methods inherited from Object
Object() public ¶
Object( )
A hack to support __construct() on PHP 4 Hint: descendant classes have no PHP4 class_name() constructors, so this constructor gets called first and calls the top-layer __construct() which (if present) should call parent::__construct()
Returns
__openPersistent() public ¶
__openPersistent( string $name , string $type = null )
Open the persistent class file for reading Used by Object::_persist()
Parameters
- string $name
- Name of persisted class
- string $type optional null
- Type of persistance (e.g: registry)
_persist() public ¶
_persist( string $name , string $return , $object , $type = null )
Checks for a persistent class file, if found file is opened and true returned If file is not found a file is created and false returned If used in other locations of the model you should choose a unique name for the persistent file There are many uses for this method, see manual for examples
Parameters
- string $name
- name of the class to persist
- string $return
- $object the object to persist
- $object
- $type optional null
Returns
Success
_savePersistent() public ¶
_savePersistent( string $name , object $object )
You should choose a unique name for the persistent file
There are many uses for this method, see manual for examples
Parameters
- string $name
- name used for object to cache
- object $object
- the object to persist
Returns
true on save, throws error if file can not be created
_set() public ¶
_set( array $properties = array() )
Allows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.
Parameters
- array $properties optional array()
- An associative array containing properties and corresponding values.
_stop() public ¶
_stop( $status = 0 )
Stop execution of the current script. Wraps exit() making testing easier.
Parameters
- $status optional 0
- http://php.net/exit for values
cakeError() public ¶
cakeError( string $method , array $messages = array() )
Used to report user friendly errors. If there is a file app/error.php or app/app_error.php this file will be loaded error.php is the AppError class it should extend ErrorHandler class.
Parameters
- string $method
- Method to be called in the error class (AppError or ErrorHandler classes)
- array $messages optional array()
- Message that is to be displayed by the error class
Returns
message
dispatchMethod() public ¶
dispatchMethod( string $method , array $params = array() )
Calls a method on this object with the given parameters. Provides an OO wrapper
for call_user_func_array
Parameters
- string $method
- Name of the method to call
- array $params optional array()
- Parameter list to use when calling $method
Returns
Returns the result of the method call
log() public ¶
log( string $msg , integer $type = LOG_ERROR )
Convience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
Parameters
- string $msg
- Log message
- integer $type optional LOG_ERROR
- Error type constant. Defined in app/config/core.php.
Returns
Success of log write
requestAction() public ¶
requestAction( mixed $url , array $extra = array() )
Calls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.
Parameters
- mixed $url
- String or array-based url.
- array $extra optional array()
- if array includes the key "return" it sets the AutoRender to true.
Returns
Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
toString() public ¶
toString( )
Object-to-string conversion. Each class can override this method as necessary.
Returns
The name of this class
Properties detail
$additionalParams ¶
List of additional headers
These will NOT be used if you are using safemode and mail()
null
$attachments ¶
List of files that should be attached to the email.
Can be both absolute and relative 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()
$date ¶
The date to put in the Date: header. This should be a date conformant with the RFC2822 standard. Leave null, to have today's date generated.
null
$delivery ¶
What method should the email be sent by
Supported methods: - mail - smtp - debug
'mail'
$headers ¶
Associative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
array()
$lineFeed ¶
Line feed character(s) to be used when sending using mail() function By default PHP_EOL is used. RFC2822 requires it to be CRLF but some Unix mail transfer agents replace LF by CRLF automatically (which leads to doubling CR if CRLF is used).
PHP_EOL
$messageId ¶
Whether to generate a Message-ID header for the e-mail. True to generate a Message-ID, False to let it be handled by sendmail (or similar) or a string to completely override the Message-ID.
If you are sending Email from a shell, be sure to set this value. As you could encounter delivery issues if you do not.
true
$return ¶
The mail that will be used in case of any errors like - Remote mailserver down - Remote user has exceeded his quota - Unknown user
null
$sendAs ¶
What format should the email be sent in
Supported formats: - text - html - both
'text'
$smtpError ¶
Placeholder for any errors that might happen with the smtp mail methods
null
$smtpOptions ¶
List of options to use for smtp mail method
Options is: - port - host - timeout - username - password - client
Link
array()