📄 email.php
字号:
<?php/* SVN FILE: $Id: email.php 7118 2008-06-04 20:49:29Z gwoo $ *//** * Short description for file. * * Long description for file * * PHP versions 4 and 5 * * CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/> * Copyright 2005-2008, Cake Software Foundation, Inc. * 1785 E. Sahara Avenue, Suite 490-204 * Las Vegas, Nevada 89104 * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @filesource * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project * @package cake * @subpackage cake.cake.libs.controller.components * @since CakePHP(tm) v 1.2.0.3467 * @version $Revision: 7118 $ * @modifiedby $LastChangedBy: gwoo $ * @lastmodified $Date: 2008-06-04 13:49:29 -0700 (Wed, 04 Jun 2008) $ * @license http://www.opensource.org/licenses/mit-license.php The MIT License *//** * 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 * * @package cake * @subpackage cake.cake.libs.controller.components * */class EmailComponent extends Object{/** * Recipient of the email * * @var string * @access public */ var $to = null;/** * The mail which the email is sent from * * @var string * @access public */ var $from = null;/** * The email the recipient will reply to * * @var string * @access public */ var $replyTo = null;/** * The read receipt email * * @var string * @access public */ var $readReceipt = null;/** * The mail that will be used in case of any errors like * - Remote mailserver down * - Remote user has exceeded his quota * - Unknown user * * @var string * @access public */ var $return = null;/** * Carbon Copy * * List of email's that should receive a copy of the email. * The Recipient WILL be able to see this list * * @var array * @access public */ var $cc = array();/** * 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 * * @var array * @access public */ var $bcc = array();/** * The subject of the email * * @var string * @access public */ var $subject = null;/** * Associative array of a user defined headers * Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5 * * @var array * @access public */ var $headers = array();/** * List of additional headers * * These will NOT be used if you are using safemode and mail() * * @var string * @access public */ var $additionalParams = null;/** * Layout for the View * * @var string * @access public */ var $layout = 'default';/** * Template for the view * * @var string * @access public */ var $template = null;/** * as per RFC2822 Section 2.1.1 * * @var integer * @access public */ var $lineLength = 70;/** * @deprecated see lineLength */ var $_lineLength = null;/** * What format should the email be sent in * * Supported formats: * - text * - html * - both * * @var string * @access public */ var $sendAs = 'text';/** * What method should the email be sent by * * Supported methods: * - mail * - smtp * - debug * * @var string * @access public */ var $delivery = 'mail';/** * charset the email is sent in * * @var string * @access public */ var $charset = 'utf-8';/** * List of files that should be attached to the email. * * Can be both absolute and relative paths * * @var array * @access public */ var $attachments = array();/** * What mailer should EmailComponent identify itself as * * @var string * @access public */ var $xMailer = 'CakePHP Email Component';/** * The list of paths to search if an attachment isnt absolute * * @var array * @access public */ var $filePaths = array();/** * List of options to use for smtp mail method * * Options is: * - port * - host * - timeout * - username * - password * * @var array * @access public */ var $smtpOptions = array( 'port'=> 25, 'host' => 'localhost', 'timeout' => 30 );/** * Placeholder for any errors that might happen with the * smtp mail methods * * @var string * @access public */ var $smtpError = null;/** * If set to true, the mail method will be auto-set to 'debug' * * @var string * @access protected */ var $_debug = false;/** * Enter description here... * * @var string * @access protected */ var $_error = false;/** * New lines char * * @var string * @access protected */ var $_newLine = "\r\n";/** * Enter description here... * * @var string * @access private */ var $__header = null;/** * Enter description here... * * @var string * @access private */ var $__boundary = null;/** * Enter description here... * * @var string * @access private */ var $__message = null;/** * Variable that holds SMTP connection * * @var resource * @access private */ var $__smtpConnection = null;/** * Startup component * * @param object $controller Instantiating controller * @access public */ function startup(&$controller) { $this->Controller =& $controller; if (Configure::read('App.encoding') !== null) { $this->charset = Configure::read('App.encoding'); } }/** * Send an email using the specified content, template and layout * * @param mixed $content Either an array of text lines, or a string with contents * @param string $template Template to use when sending email * @param string $layout Layout to use to enclose email body * @return boolean Success * @access public */ function send($content = null, $template = null, $layout = null) { $this->__createHeader(); if ($template) { $this->template = $template; } if ($layout) { $this->layout = $layout; } if (is_array($content)) { $message = null; foreach ($content as $key => $value) { $message .= $value . $this->_newLine; } } else { $message = $content; } if ($template === null && $this->template === null) { $this->__formatMessage($message); } else { $message = $this->__wrap($message); $this->__message = $this->__renderTemplate($message); } if (!empty($this->attachments)) { $this->__attachFiles(); } if (!is_null($this->__boundary)) { $this->__message .= $this->_newLine .'--' . $this->__boundary . '--' . $this->_newLine . $this->_newLine; } if ($this->_debug) { return $this->__debug(); } $__method = '__'.$this->delivery; return $this->$__method(); }/** * Reset all EmailComponent internal variables to be able to send out a new email. * * @access public */ function reset() { $this->template = null; $this->to = null; $this->from = null; $this->replyTo = null; $this->return = null; $this->cc = array(); $this->bcc = array(); $this->subject = null; $this->additionalParams = null; $this->__header = null; $this->__boundary = null; $this->__message = null; }/** * Render the contents using the current layout and template. * * @param string $content Content to render * @return string Email ready to be sent * @access private */ function __renderTemplate($content) { $viewClass = $this->Controller->view; if ($viewClass != 'View') { if (strpos($viewClass, '.') !== false) { list($plugin, $viewClass) = explode('.', $viewClass); } $viewClass = $viewClass . 'View'; App::import('View', $this->Controller->view); } $View = new $viewClass($this->Controller, false); $View->layout = $this->layout; $msg = null; if ($this->sendAs === 'both') { $htmlContent = $content; if (!empty($this->attachments)) { $msg .= '--' . $this->__boundary . $this->_newLine; $msg .= 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"' . $this->_newLine . $this->_newLine; } $msg .= '--alt-' . $this->__boundary . $this->_newLine; $msg .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine; $msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine; $content = $View->element('email' . DS . 'text' . DS . $this->template, array('content' => $content), true); $View->layoutPath = 'email' . DS . 'text'; $msg .= $View->renderLayout($content) . $this->_newLine; $msg .= $this->_newLine. '--alt-' . $this->__boundary . $this->_newLine; $msg .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine; $msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -