Class EmailComponent
Object class, allowing __construct and __destruct in PHP4.
Also includes methods for logging and the special method RequestAction, to call other Controllers' Actions from anywhere.
- Object
- 
			 EmailComponent EmailComponent
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: The MIT License
Location: controller/components/email.php
Properties summary
- 
			$__boundarypublicstringIf set, boundary to use for multipart mime messages
- 
			$__headerpublicarrayTemporary store of message header lines
- 
			$__messagepublicarrayTemporary store of message lines
- 
			$__smtpConnectionpublicresourceVariable that holds SMTP connection
- 
			$_debugpublicstringIf set to true, the mail method will be auto-set to 'debug'
- 
			$_lineLengthpublic
- 
			$additionalParamspublicstringList of additional headers
- 
			$attachmentspublicarrayList of files that should be attached to the email.
- 
			$bccpublicarrayBlind Carbon Copy
- 
			$ccpublicarrayCarbon Copy
- 
			$charsetpublicstringcharset the email is sent in
- 
			$datepublicstringThe 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. 
- 
			$deliverypublicstringWhat method should the email be sent by
- 
			$filePathspublicarrayThe list of paths to search if an attachment isnt absolute
- 
			$frompublicstringThe mail which the email is sent from
- 
			$headerspublicarrayAssociative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5 
- 
			$layoutpublicstringLayout for the View
- 
			$lineFeedpublicstringLine feed character(s) to be used when sending using mail() function If null 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). 
- 
			$lineLengthpublicintegeras per RFC2822 Section 2.1.1
- 
			$readReceiptpublicstringThe read receipt email
- 
			$replyTopublicstringThe email the recipient will reply to
- 
			$returnpublicstringThe mail that will be used in case of any errors like - Remote mailserver down - Remote user has exceeded his quota - Unknown user 
- 
			$sendAspublicstringWhat format should the email be sent in
- 
			$smtpErrorpublicstringPlaceholder for any errors that might happen with the smtp mail methods 
- 
			$smtpOptionspublicarrayList of options to use for smtp mail method
- 
			$subjectpublicstringThe subject of the email
- 
			$templatepublicstringTemplate for the view
- 
			$topublicstringRecipient of the email
- 
			$xMailerpublicstringWhat mailer should EmailComponent identify itself as
Inherited Properties
Method Summary
- 
			__attachFiles() publicAttach files by adding file contents inside boundaries.
- 
			__createBoundary() publicCreate unique boundary identifier
- 
			__createHeader() publicCreate emails headers including (but not limited to) from email address, reply to, bcc and cc. 
- 
			__debug() publicSet as controller flash message a debug message showing current settings in component
- 
			__encode() publicEncode the specified string using the current charset
- 
			__findFiles() publicFind the specified attachment in the list of file paths
- 
			__formatAddress() publicFormat a string as an email address
- 
			__formatMessage() publicFormat the message by seeing if it has attachments.
- 
			__mail() publicWrapper for PHP mail function used for sending out emails
- 
			__renderTemplate() publicRender the contents using the current layout and template.
- 
			__smtp() publicSends out email via SMTP
- 
			__smtpSend() publicPrivate method for sending data to SMTP connection
- 
			__strip() publicRemove certain elements (such as bcc:, to:, %0a) from given value. Helps prevent header injection / mainipulation on user content. 
- 
			__wrap() publicWrap the message using EmailComponent::$lineLength
- 
			_getSocket() publicHelper method to get socket, overridden in tests
- 
			initialize() publicInitialize component
- 
			reset() publicReset all EmailComponent internal variables to be able to send out a new email.
- 
			send() publicSend an email using the specified content, template and layout
- 
			startup() publicStartup 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
__mail() public ¶
__mail( )
Wrapper for PHP mail function used for sending out emails
Returns
Success
__renderTemplate() public ¶
__renderTemplate( 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' )
Private 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 )
Wrap the message using EmailComponent::$lineLength
Parameters
- string $message
- Message to wrap
Returns
Wrapped message
_getSocket() public ¶
_getSocket( array $config )
Helper method to get socket, overridden in tests
Parameters
- array $config
- Config data for the socket.
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.
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
- 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.
Parameters
- array $properties optional array()
- An associative array containing properties and corresponding values.
_stop() public ¶
_stop( $status = 0 )
Stop execution of the current script
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, and improves performance by using straight method calls in most cases.
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 )
API for logging events.
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.
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 If null 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).
null
			$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
array( 'port'=> 25, 'host' => 'localhost', 'timeout' => 30 )
