2006-09-11 20:06:01 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
2006-09-11 20:06:01 +00:00
|
|
|
* 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
|
2007-02-02 10:39:45 +00:00
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-09-11 20:06:01 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.controller.components
|
2007-02-02 10:39:45 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.3467
|
2006-09-11 20:06:01 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.controller.components
|
|
|
|
*
|
|
|
|
*/
|
2007-07-24 19:34:35 +00:00
|
|
|
class EmailComponent extends Object{
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* Recipient of the email
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2006-09-11 20:37:13 +00:00
|
|
|
var $to = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* The mail which the email is sent from
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2006-09-11 20:37:13 +00:00
|
|
|
var $from = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* The email the recipient will reply to
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $replyTo = null;
|
2007-10-19 02:31:25 +00:00
|
|
|
/**
|
|
|
|
* The read receipt email
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $readReceipt = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* The mail that will be used in case of any errors like
|
|
|
|
* - Remote mailserver down
|
|
|
|
* - Remote user has exceeded his quota
|
|
|
|
* - Unknown user
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $return = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* Carbon Copy
|
|
|
|
*
|
|
|
|
* List of email's that should receive a copy of the email.
|
|
|
|
* The Recipient WILL be able to see this list
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 19:34:35 +00:00
|
|
|
* @var array
|
2006-12-25 10:51:08 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $cc = array();
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* 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
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 19:34:35 +00:00
|
|
|
* @var array
|
2006-12-25 10:51:08 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $bcc = array();
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* The subject of the email
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2006-09-11 20:37:13 +00:00
|
|
|
var $subject = null;
|
2007-07-07 23:33:22 +00:00
|
|
|
/**
|
2007-07-24 19:34:35 +00:00
|
|
|
* Associative array of a user defined headers
|
|
|
|
* Keys will be prefixed 'X-' as per RFC822 Section 4.7.5
|
2007-07-07 23:33:22 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var array
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2007-07-07 23:33:22 +00:00
|
|
|
*/
|
|
|
|
var $headers = array();
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* List of additional headers
|
|
|
|
*
|
|
|
|
* These will NOT be used if you are using safemode and mail()
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 19:34:35 +00:00
|
|
|
* @var string
|
2006-12-25 10:51:08 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2006-12-25 06:39:02 +00:00
|
|
|
var $additionalParams = null;
|
2007-04-03 01:15:24 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* Layout for the View
|
2007-04-03 01:15:24 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2007-04-03 01:15:24 +00:00
|
|
|
*/
|
|
|
|
var $layout = 'default';
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* Template for the view
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2007-07-07 23:33:22 +00:00
|
|
|
var $template = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* What format should the email be sent in
|
|
|
|
*
|
|
|
|
* Supported formats:
|
|
|
|
* - text
|
|
|
|
* - html
|
|
|
|
* - both
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2007-07-24 20:02:14 +00:00
|
|
|
var $sendAs = 'text';
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* What method should the email be sent by
|
|
|
|
*
|
|
|
|
* Supported methods:
|
|
|
|
* - mail
|
|
|
|
* - smtp
|
|
|
|
* - debug
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2007-07-24 20:02:14 +00:00
|
|
|
var $delivery = 'mail';
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* charset the email is sent in
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2007-10-19 02:31:25 +00:00
|
|
|
var $charset = 'utf-8';
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* List of files that should be attached to the email.
|
|
|
|
*
|
|
|
|
* Can be both absolute and relative paths
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var array
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $attachments = array();
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* What mailer should EmailComponent identify itself as
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 19:34:35 +00:00
|
|
|
* @var string
|
2006-12-25 10:51:08 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2007-07-24 19:34:35 +00:00
|
|
|
var $xMailer = 'CakePHP Email Component';
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* The list of paths to search if an attachment isnt absolute
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 19:34:35 +00:00
|
|
|
* @var array
|
2006-12-25 10:51:08 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2007-07-24 19:34:35 +00:00
|
|
|
var $filePaths = array();
|
2007-06-25 21:17:09 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* List of options to use for smtp mail method
|
|
|
|
*
|
|
|
|
* Options is:
|
|
|
|
* - port
|
|
|
|
* - host
|
|
|
|
* - timeout
|
2007-10-19 02:31:25 +00:00
|
|
|
* - username
|
|
|
|
* - password
|
2007-06-25 21:17:09 +00:00
|
|
|
*
|
2007-07-24 19:34:35 +00:00
|
|
|
* @var array
|
2007-06-25 21:17:09 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2007-07-24 19:34:35 +00:00
|
|
|
var $smtpOptions = array('port'=> 25,
|
|
|
|
'host' => 'localhost',
|
|
|
|
'timeout' => 30);
|
2007-06-26 20:29:38 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* Placeholder for any errors that might happen with the
|
|
|
|
* smtp mail methods
|
2007-06-26 20:29:38 +00:00
|
|
|
*
|
2007-07-24 19:34:35 +00:00
|
|
|
* @var string
|
2007-06-26 20:29:38 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2007-07-24 19:34:35 +00:00
|
|
|
var $smtpError = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* If set to true, the mail method will be auto-set to 'debug'
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 19:34:35 +00:00
|
|
|
* @var string
|
2006-12-25 10:51:08 +00:00
|
|
|
* @access protected
|
|
|
|
*/
|
2006-09-11 20:37:13 +00:00
|
|
|
var $_debug = false;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 19:34:35 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
2006-12-25 10:51:08 +00:00
|
|
|
* @access protected
|
|
|
|
*/
|
2006-09-11 20:37:13 +00:00
|
|
|
var $_error = false;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 20:02:14 +00:00
|
|
|
* New lines char
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access protected
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2007-02-01 20:11:28 +00:00
|
|
|
var $_newLine = "\n";
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 19:34:35 +00:00
|
|
|
* Enter description here...
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var integer
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access protected
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2007-04-29 04:16:43 +00:00
|
|
|
var $_lineLength = 70;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 19:34:35 +00:00
|
|
|
* Enter description here...
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access private
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $__header = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 19:34:35 +00:00
|
|
|
* Enter description here...
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access private
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $__boundary = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 19:34:35 +00:00
|
|
|
* Enter description here...
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-07-24 17:54:38 +00:00
|
|
|
* @var string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access private
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2006-09-12 01:55:32 +00:00
|
|
|
var $__message = null;
|
2007-06-27 15:12:48 +00:00
|
|
|
/**
|
2007-07-24 19:34:35 +00:00
|
|
|
* Variable that holds SMTP connection
|
2007-06-27 15:12:48 +00:00
|
|
|
*
|
2007-07-24 19:34:35 +00:00
|
|
|
* @var resource
|
2007-06-27 15:12:48 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
var $__smtpConnection = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Startup component
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @param object $controller Instantiating controller
|
2006-12-25 10:51:08 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function startup(&$controller) {
|
2007-04-03 01:15:24 +00:00
|
|
|
$this->Controller = & $controller;
|
2006-12-25 06:39:02 +00:00
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Send an email using the specified content, template and layout
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @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
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access public
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2007-07-07 23:33:22 +00:00
|
|
|
function send($content = null, $template = null, $layout = null) {
|
2006-12-25 06:39:02 +00:00
|
|
|
$this->__createHeader();
|
2007-03-28 22:57:07 +00:00
|
|
|
$this->subject = $this->__encode($this->subject);
|
2006-09-12 00:26:50 +00:00
|
|
|
|
2007-07-24 19:34:35 +00:00
|
|
|
if ($template) {
|
2007-07-07 23:33:22 +00:00
|
|
|
$this->template = $template;
|
|
|
|
}
|
|
|
|
|
2007-07-24 19:34:35 +00:00
|
|
|
if ($layout) {
|
2007-07-07 23:33:22 +00:00
|
|
|
$this->layout = $layout;
|
|
|
|
}
|
|
|
|
|
2007-10-19 02:31:25 +00:00
|
|
|
if (is_array($content)) {
|
|
|
|
$message = null;
|
|
|
|
foreach ($content as $key => $value) {
|
|
|
|
$message .= $value . $this->_newLine;
|
2006-09-12 01:55:32 +00:00
|
|
|
}
|
2007-10-19 02:31:25 +00:00
|
|
|
} else {
|
|
|
|
$message = $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($template === null && $this->template === null) {
|
2006-12-25 06:39:02 +00:00
|
|
|
$this->__formatMessage($message);
|
2006-09-12 00:26:50 +00:00
|
|
|
} else {
|
2007-10-19 02:31:25 +00:00
|
|
|
$message = $this->__wrap($message);
|
|
|
|
$this->__message = $this->__renderTemplate($message);
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!empty($this->attachments)) {
|
2006-09-12 00:26:50 +00:00
|
|
|
$this->__attachFiles();
|
|
|
|
}
|
2006-12-25 06:39:02 +00:00
|
|
|
|
2007-07-24 19:34:35 +00:00
|
|
|
if (!is_null($this->__boundary)) {
|
|
|
|
$this->__message .= $this->_newLine .'--' . $this->__boundary . '--' . $this->_newLine . $this->_newLine;
|
|
|
|
}
|
|
|
|
|
2007-06-20 07:51:52 +00:00
|
|
|
if ($this->_debug) {
|
2007-10-22 16:20:07 +00:00
|
|
|
return $this->__debug();
|
2006-12-25 06:39:02 +00:00
|
|
|
}
|
2006-09-12 00:26:50 +00:00
|
|
|
$__method = '__'.$this->delivery;
|
2007-07-24 19:34:35 +00:00
|
|
|
return $this->$__method();
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Reset all EmailComponent internal variables to be able to send out a new email.
|
2007-07-24 19:34:35 +00:00
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Render the contents using the current layout and template.
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @param string $content Content to render
|
|
|
|
* @return string Email ready to be sent
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access private
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2006-12-25 06:39:02 +00:00
|
|
|
function __renderTemplate($content) {
|
2007-10-19 02:31:25 +00:00
|
|
|
$viewClass = $this->Controller->view;
|
|
|
|
|
|
|
|
if ($viewClass != 'View') {
|
|
|
|
if (strpos($viewClass, '.') !== false) {
|
|
|
|
list($plugin, $viewClass) = explode('.', $viewClass);
|
|
|
|
}
|
|
|
|
$viewClass = $viewClass . 'View';
|
|
|
|
loadView($this->Controller->view);
|
|
|
|
}
|
2007-10-22 23:52:12 +00:00
|
|
|
$View = new $viewClass($this->Controller, false);
|
2007-04-03 01:15:24 +00:00
|
|
|
$View->layout = $this->layout;
|
2007-10-19 02:31:25 +00:00
|
|
|
$msg = null;
|
2007-07-07 23:33:22 +00:00
|
|
|
|
2007-06-20 07:51:52 +00:00
|
|
|
if ($this->sendAs === 'both') {
|
2007-03-25 18:16:24 +00:00
|
|
|
$htmlContent = $content;
|
2007-10-22 17:14:49 +00:00
|
|
|
if (!empty($this->attachments)) {
|
|
|
|
$msg .= '--' . $this->__boundary . $this->_newLine;
|
|
|
|
$msg .= 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"' . $this->_newLine . $this->_newLine;
|
|
|
|
}
|
2007-10-19 02:31:25 +00:00
|
|
|
$msg .= '--alt-' . $this->__boundary . $this->_newLine;
|
2006-12-25 06:39:02 +00:00
|
|
|
$msg .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
|
2007-10-19 02:31:25 +00:00
|
|
|
$msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
|
|
|
|
|
2007-02-02 02:47:53 +00:00
|
|
|
$content = $View->renderElement('email' . DS . 'text' . DS . $this->template, array('content' => $content), true);
|
2007-02-01 20:11:28 +00:00
|
|
|
$View->layoutPath = 'email' . DS . 'text';
|
|
|
|
$msg .= $View->renderLayout($content) . $this->_newLine;
|
|
|
|
|
2007-10-19 02:31:25 +00:00
|
|
|
$msg .= $this->_newLine. '--alt-' . $this->__boundary . $this->_newLine;
|
2007-02-01 20:11:28 +00:00
|
|
|
$msg .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
|
2007-10-19 02:31:25 +00:00
|
|
|
$msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
|
|
|
|
|
2007-03-25 18:16:24 +00:00
|
|
|
$content = $View->renderElement('email' . DS . 'html' . DS . $this->template, array('content' => $htmlContent), true);
|
2006-12-25 06:39:02 +00:00
|
|
|
$View->layoutPath = 'email' . DS . 'html';
|
2007-10-19 02:31:25 +00:00
|
|
|
$msg .= $View->renderLayout($content) . $this->_newLine . $this->_newLine;
|
|
|
|
$msg .= '--alt-' . $this->__boundary . '--' . $this->_newLine . $this->_newLine;
|
2007-07-24 19:34:35 +00:00
|
|
|
return $msg;
|
2007-10-19 02:31:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-10-22 17:14:49 +00:00
|
|
|
if (!empty($this->attachments)) {
|
|
|
|
if ($this->sendAs === 'html') {
|
|
|
|
$msg .= $this->_newLine. '--' . $this->__boundary . $this->_newLine;
|
|
|
|
$msg .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
|
|
|
|
$msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
|
|
|
|
} else {
|
|
|
|
$msg .= '--' . $this->__boundary . $this->_newLine;
|
|
|
|
$msg .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
|
|
|
|
$msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
|
|
|
|
}
|
2006-12-25 06:39:02 +00:00
|
|
|
}
|
2007-10-19 02:31:25 +00:00
|
|
|
|
|
|
|
$content = $View->renderElement('email' . DS . $this->sendAs . DS . $this->template, array('content' => $content), true);
|
|
|
|
$View->layoutPath = 'email' . DS . $this->sendAs;
|
|
|
|
$msg .= $View->renderLayout($content) . $this->_newLine;
|
|
|
|
return $msg;
|
2006-12-25 06:39:02 +00:00
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Create unique boundary identifier
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __createBoundary() {
|
2007-07-24 19:34:35 +00:00
|
|
|
$this->__boundary = md5(uniqid(time()));
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Create emails headers including (but not limited to) from email address, reply to,
|
|
|
|
* bcc and cc.
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __createHeader() {
|
2007-10-19 04:08:50 +00:00
|
|
|
$this->__header = 'From: ' . $this->__formatAddress($this->from) . $this->_newLine;
|
2007-07-07 23:33:22 +00:00
|
|
|
|
2007-05-01 18:01:48 +00:00
|
|
|
if (!empty($this->replyTo)) {
|
|
|
|
$this->__header .= 'Reply-To: ' . $this->__formatAddress($this->replyTo) . $this->_newLine;
|
|
|
|
}
|
|
|
|
if (!empty($this->return)) {
|
|
|
|
$this->__header .= 'Return-Path: ' . $this->__formatAddress($this->return) . $this->_newLine;
|
|
|
|
}
|
2007-10-19 02:31:25 +00:00
|
|
|
if (!empty($this->readReceipt)) {
|
|
|
|
$this->__header .= 'Disposition-Notification-To: ' . $this->__formatAddress($this->readReceipt) . $this->_newLine;
|
|
|
|
}
|
2007-07-24 17:54:38 +00:00
|
|
|
$addresses = null;
|
2007-07-24 19:34:35 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!empty($this->cc)) {
|
2006-09-12 00:26:50 +00:00
|
|
|
foreach ($this->cc as $cc) {
|
2007-07-07 23:33:22 +00:00
|
|
|
$addresses .= ', ' . $this->__formatAddress($cc);
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2007-07-07 23:33:22 +00:00
|
|
|
$this->__header .= 'cc: ' . substr($addresses, 2) . $this->_newLine;
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2007-07-24 17:54:38 +00:00
|
|
|
$addresses = null;
|
2007-07-24 19:34:35 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!empty($this->bcc)) {
|
2006-09-12 00:26:50 +00:00
|
|
|
foreach ($this->bcc as $bcc) {
|
2007-07-07 23:33:22 +00:00
|
|
|
$addresses .= ', ' . $this->__formatAddress($bcc);
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2007-07-07 23:33:22 +00:00
|
|
|
$this->__header .= 'Bcc: ' . substr($addresses, 2) . $this->_newLine;
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2007-07-24 19:34:35 +00:00
|
|
|
$this->__header .= 'X-Mailer: ' . $this->xMailer . $this->_newLine;
|
2006-09-12 00:26:50 +00:00
|
|
|
|
2007-07-07 23:33:22 +00:00
|
|
|
if (!empty($this->headers)) {
|
|
|
|
foreach ($this->headers as $key => $val) {
|
|
|
|
$this->__header .= 'X-'.$key.': '.$val . $this->_newLine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-19 02:31:25 +00:00
|
|
|
if (!empty($this->attachments)) {
|
2007-07-24 19:34:35 +00:00
|
|
|
$this->__createBoundary();
|
2006-09-12 00:26:50 +00:00
|
|
|
$this->__header .= 'MIME-Version: 1.0' . $this->_newLine;
|
2007-07-24 19:34:35 +00:00
|
|
|
$this->__header .= 'Content-Type: multipart/mixed; boundary="' . $this->__boundary . '"' . $this->_newLine;
|
2007-10-22 17:14:49 +00:00
|
|
|
$this->__header .= 'This part of the E-mail should never be seen. If' . $this->_newLine;
|
|
|
|
$this->__header .= 'you are reading this, consider upgrading your e-mail' . $this->_newLine;
|
|
|
|
$this->__header .= 'client to a MIME-compatible client.' . $this->_newLine;
|
2007-09-16 20:36:28 +00:00
|
|
|
} elseif ($this->sendAs === 'text') {
|
|
|
|
$this->__header .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif ($this->sendAs === 'html') {
|
2007-10-19 02:31:25 +00:00
|
|
|
$this->__header .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
|
2007-10-22 17:14:49 +00:00
|
|
|
} elseif ($this->sendAs === 'both') {
|
|
|
|
$this->__header .= 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"' . $this->_newLine . $this->_newLine;
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2007-10-19 02:31:25 +00:00
|
|
|
|
2007-11-06 04:39:23 +00:00
|
|
|
$this->__header .= 'Content-Transfer-Encoding: 7bit';
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Format the message by seeing if it has attachments.
|
2007-07-24 17:54:38 +00:00
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @param string $message Message to format
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access private
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __formatMessage($message) {
|
2007-10-19 02:31:25 +00:00
|
|
|
if (!empty($this->attachments)) {
|
|
|
|
$this->__message .= '--' . $this->__boundary . $this->_newLine;
|
2006-09-21 08:49:18 +00:00
|
|
|
$this->__message .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
|
2007-10-19 02:31:25 +00:00
|
|
|
$this->__message .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2007-10-19 02:31:25 +00:00
|
|
|
$message = $this->__wrap($message);
|
|
|
|
$this->__message .= $message . $this->_newLine;
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Attach files by adding file contents inside boundaries.
|
2007-07-24 17:54:38 +00:00
|
|
|
*
|
2006-12-25 10:51:08 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __attachFiles() {
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($this->attachments as $attachment) {
|
2007-10-22 21:03:47 +00:00
|
|
|
$file = $this->__findFiles($attachment);
|
|
|
|
if (!empty($file)) {
|
|
|
|
$files[] = $file;
|
|
|
|
}
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($files as $file) {
|
2006-09-12 00:26:50 +00:00
|
|
|
$handle = fopen($file, 'rb');
|
|
|
|
$data = fread($handle, filesize($file));
|
|
|
|
$data = chunk_split(base64_encode($data)) ;
|
2007-10-19 02:31:25 +00:00
|
|
|
$info = pathinfo($file);
|
|
|
|
$filetype = 'unknown';
|
|
|
|
if (isset($info['extension'])) {
|
|
|
|
$filetype = $info['extension'];
|
|
|
|
}
|
2006-09-12 00:26:50 +00:00
|
|
|
|
2007-07-24 19:34:35 +00:00
|
|
|
$this->__message .= '--' . $this->__boundary . $this->_newLine;
|
2007-05-01 00:44:19 +00:00
|
|
|
$this->__message .= 'Content-Type: ' . $filetype . '; name="' . basename($file) . '"' . $this->_newLine;
|
2006-09-12 01:55:32 +00:00
|
|
|
$this->__message .= 'Content-Transfer-Encoding: base64' . $this->_newLine;
|
2007-05-01 00:44:19 +00:00
|
|
|
$this->__message .= 'Content-Disposition: attachment; filename="' . basename($file) . '"' . $this->_newLine . $this->_newLine;
|
2006-09-12 01:55:32 +00:00
|
|
|
$this->__message .= $data . $this->_newLine . $this->_newLine;
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Find the specified attachment in the list of file paths
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @param string $attachment Attachment file name to find
|
|
|
|
* @return string Path to located file
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access private
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __findFiles($attachment) {
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($this->filePaths as $path) {
|
2006-09-12 00:26:50 +00:00
|
|
|
if (file_exists($path . DS . $attachment)) {
|
|
|
|
$file = $path . DS . $attachment;
|
|
|
|
return $file;
|
|
|
|
}
|
|
|
|
}
|
2007-10-22 21:03:47 +00:00
|
|
|
return null;
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Wrap the message using EmailComponet::$_lineLength
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @param string $message Message to wrap
|
|
|
|
* @return string Wrapped message
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access private
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2006-09-12 01:55:32 +00:00
|
|
|
function __wrap($message) {
|
2007-07-07 23:33:22 +00:00
|
|
|
$message = $this->__strip($message, true);
|
2007-10-19 02:31:25 +00:00
|
|
|
$message = str_replace(array("\r\n","\r"), "\n", $message);
|
|
|
|
$words = explode("\n", $message);
|
2006-09-21 08:49:18 +00:00
|
|
|
$formated = null;
|
2007-07-07 23:33:22 +00:00
|
|
|
|
2006-09-12 01:55:32 +00:00
|
|
|
foreach ($words as $word) {
|
2007-10-19 02:31:25 +00:00
|
|
|
$formated .= wordwrap($word, $this->_lineLength, $this->_newLine, true);
|
|
|
|
$formated .= $this->_newLine;
|
2006-09-12 01:55:32 +00:00
|
|
|
}
|
|
|
|
return $formated;
|
|
|
|
}
|
2007-03-28 22:57:07 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Encode the specified string using the current charset
|
2007-03-28 22:57:07 +00:00
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @param string $subject String to encode
|
|
|
|
* @return string Encoded string
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access private
|
2007-03-28 22:57:07 +00:00
|
|
|
*/
|
2007-07-24 19:34:35 +00:00
|
|
|
function __encode($subject) {
|
|
|
|
$subject = $this->__strip($subject);
|
2007-07-07 23:33:22 +00:00
|
|
|
|
2007-10-19 02:31:25 +00:00
|
|
|
if (low($this->charset) !== 'utf-8') {
|
2007-03-28 22:57:07 +00:00
|
|
|
$start = "=?" . $this->charset . "?B?";
|
|
|
|
$end = "?=";
|
|
|
|
$spacer = $end . "\n " . $start;
|
|
|
|
|
|
|
|
$length = 75 - strlen($start) - strlen($end);
|
|
|
|
$length = $length - ($length % 4);
|
|
|
|
|
2007-07-24 19:34:35 +00:00
|
|
|
$subject = base64_encode($subject);
|
|
|
|
$subject = chunk_split($subject, $length, $spacer);
|
2007-03-28 22:57:07 +00:00
|
|
|
$spacer = preg_quote($spacer);
|
2007-07-24 19:34:35 +00:00
|
|
|
$subject = preg_replace("/" . $spacer . "$/", "", $subject);
|
|
|
|
$subject = $start . $subject . $end;
|
2007-03-28 22:57:07 +00:00
|
|
|
}
|
2007-07-24 19:34:35 +00:00
|
|
|
return $subject;
|
2007-03-28 22:57:07 +00:00
|
|
|
}
|
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Format a string as an email address
|
2007-03-28 22:57:07 +00:00
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @param string $string String representing an email address
|
|
|
|
* @return string Email address suitable for email headers
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access private
|
2007-03-28 22:57:07 +00:00
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __formatAddress($string) {
|
|
|
|
if (strpos($string, '<') !== false) {
|
2007-03-28 22:57:07 +00:00
|
|
|
$value = explode('<', $string);
|
|
|
|
$string = $this->__encode($value[0]) . ' <' . $value[1];
|
|
|
|
}
|
2007-07-07 23:33:22 +00:00
|
|
|
return $this->__strip($string);
|
|
|
|
}
|
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Remove certain elements (such as bcc:, to:, %0a) from given value
|
2007-07-07 23:33:22 +00:00
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @param string $value Value to strip
|
|
|
|
* @param boolean $message Set to true to indicate main message content
|
|
|
|
* @return string Stripped value
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access private
|
2007-07-07 23:33:22 +00:00
|
|
|
*/
|
|
|
|
function __strip($value, $message = false) {
|
|
|
|
$search = array('/%0a/i', '/%0d/i', '/Content-Type\:/i',
|
2007-07-24 19:34:35 +00:00
|
|
|
'/charset\=/i', '/mime-version\:/i', '/multipart\/mixed/i',
|
|
|
|
'/bcc\:/i','/to\:/i','/cc\:/i', '/\\r/i', '/\\n/i');
|
2007-07-07 23:33:22 +00:00
|
|
|
|
2007-07-24 20:02:14 +00:00
|
|
|
if ($message === true) {
|
|
|
|
$search = array_slice($search, 0, -2);
|
2007-07-07 23:33:22 +00:00
|
|
|
}
|
|
|
|
return preg_replace($search, '', $value);
|
2007-03-28 22:57:07 +00:00
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Wrapper for PHP mail function used for sending out emails
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @return bool Success
|
2006-12-25 10:51:08 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __mail() {
|
2007-07-07 23:33:22 +00:00
|
|
|
if (ini_get('safe_mode')) {
|
|
|
|
return @mail($this->to, $this->subject, $this->__message, $this->__header);
|
|
|
|
}
|
2006-12-25 06:39:02 +00:00
|
|
|
return @mail($this->to, $this->subject, $this->__message, $this->__header, $this->additionalParams);
|
2006-09-12 01:55:32 +00:00
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-07-24 19:34:35 +00:00
|
|
|
* Sends out email via SMTP
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @return bool Success
|
2006-12-25 10:51:08 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __smtp() {
|
2007-08-11 13:31:12 +00:00
|
|
|
$response = $this->__smtpConnect();
|
2007-09-16 19:19:52 +00:00
|
|
|
|
2007-08-11 13:31:12 +00:00
|
|
|
if ($response['errno'] != 0 && $response['status'] === false) {
|
2007-06-27 15:12:48 +00:00
|
|
|
$this->smtpError = "{$response['errno']}: {$response['errstr']}";
|
2007-06-26 20:29:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-08-11 13:31:12 +00:00
|
|
|
if (!$this->__sendData("HELO cake\r\n")) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-07-07 23:33:22 +00:00
|
|
|
|
2007-10-19 02:31:25 +00:00
|
|
|
if (isset($this->smtpOptions['username']) && isset($this->smtpOptions['password']) && !$this->__authenticate()){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-26 20:29:38 +00:00
|
|
|
if (!$this->__sendData("MAIL FROM: {$this->from}\r\n")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->__sendData("RCPT TO: {$this->to}\r\n")) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-11-06 06:09:06 +00:00
|
|
|
$this->__sendData("DATA\r\n", false);
|
|
|
|
$response = $this->__getSmtpResponse();
|
2007-06-26 20:29:38 +00:00
|
|
|
|
2007-11-06 06:09:06 +00:00
|
|
|
if (stristr($response, '354') === false){
|
|
|
|
$this->smtpError = $response;
|
|
|
|
return false;
|
|
|
|
}
|
2007-08-11 13:31:12 +00:00
|
|
|
|
2007-11-06 06:09:06 +00:00
|
|
|
if (!$this->__sendData("{$this->__header}\r\n{$this->__message}\r\n\r\n\r\n.\r\n")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$this->__sendData("QUIT\r\n", false);
|
2007-09-16 19:19:52 +00:00
|
|
|
return true;
|
2007-06-27 15:12:48 +00:00
|
|
|
}
|
2007-07-07 23:33:22 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Connect to an SMTP server
|
2007-07-07 23:33:22 +00:00
|
|
|
*
|
2007-07-24 19:34:35 +00:00
|
|
|
* @param array $options SMTP connection options
|
2007-10-22 21:03:47 +00:00
|
|
|
* @return array Indexed array with status information: 'status', 'errno', 'errstr'
|
2007-10-19 02:31:25 +00:00
|
|
|
* @access private
|
2007-07-07 23:33:22 +00:00
|
|
|
*/
|
2007-08-11 13:31:12 +00:00
|
|
|
function __smtpConnect() {
|
2007-06-27 15:12:48 +00:00
|
|
|
$status = true;
|
2007-08-11 13:31:12 +00:00
|
|
|
$this->__smtpConnection = @fsockopen($this->smtpOptions['host'],
|
|
|
|
$this->smtpOptions['port'],
|
|
|
|
$errno,
|
|
|
|
$errstr,
|
|
|
|
$this->smtpOptions['timeout']);
|
2007-07-07 23:33:22 +00:00
|
|
|
|
2007-06-27 15:12:48 +00:00
|
|
|
if ($this->__smtpConnection == false) {
|
|
|
|
$status = false;
|
2007-06-25 21:17:09 +00:00
|
|
|
}
|
2007-08-11 13:31:12 +00:00
|
|
|
$response = $this->__getSmtpResponse();
|
2007-09-16 19:19:52 +00:00
|
|
|
|
2007-06-27 15:12:48 +00:00
|
|
|
return array('status' => $status,
|
2007-07-24 19:34:35 +00:00
|
|
|
'errno' => $errno,
|
|
|
|
'errstr' => $errstr);
|
2007-06-26 20:29:38 +00:00
|
|
|
}
|
2007-07-07 23:33:22 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Get SMTP response
|
|
|
|
*
|
|
|
|
* @return string SMTP server response
|
2007-10-19 02:31:25 +00:00
|
|
|
* @access private
|
2007-07-07 23:33:22 +00:00
|
|
|
*/
|
2007-06-26 20:29:38 +00:00
|
|
|
function __getSmtpResponse() {
|
2007-06-27 15:12:48 +00:00
|
|
|
$response = @fgets($this->__smtpConnection, 512);
|
2007-06-26 20:29:38 +00:00
|
|
|
return $response;
|
|
|
|
}
|
2007-07-07 23:33:22 +00:00
|
|
|
/**
|
2007-07-24 19:34:35 +00:00
|
|
|
* Private method for sending data to SMTP connection
|
2007-07-07 23:33:22 +00:00
|
|
|
*
|
2007-07-24 19:34:35 +00:00
|
|
|
* @param string $data data to be sent to SMTP server
|
2007-10-22 16:54:36 +00:00
|
|
|
* @param boolean $check check for response from server
|
2007-10-22 21:03:47 +00:00
|
|
|
* @return bool Success
|
2007-10-19 02:31:25 +00:00
|
|
|
* @access private
|
2007-07-07 23:33:22 +00:00
|
|
|
*/
|
2007-06-27 15:12:48 +00:00
|
|
|
function __sendData($data, $check = true) {
|
|
|
|
@fwrite($this->__smtpConnection, $data);
|
2007-09-16 19:19:52 +00:00
|
|
|
|
2007-11-06 06:09:06 +00:00
|
|
|
if ($check === true) {
|
|
|
|
$response = $this->__getSmtpResponse();
|
|
|
|
|
2007-08-11 13:31:12 +00:00
|
|
|
if (stristr($response, '250') === false) {
|
|
|
|
$this->smtpError = $response;
|
|
|
|
return false;
|
|
|
|
}
|
2007-06-26 20:29:38 +00:00
|
|
|
}
|
2007-10-19 02:31:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* SMTP authentication
|
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @return bool Success
|
2007-10-19 02:31:25 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function __authenticate(){
|
|
|
|
@fwrite($this->__smtpConnection, "AUTH LOGIN\r\n");
|
|
|
|
$response = $this->__getSmtpResponse();
|
|
|
|
|
|
|
|
if (stristr($response, '334') === false){
|
|
|
|
$this->smtpError = $response;
|
|
|
|
return false;
|
|
|
|
}
|
2007-09-16 19:19:52 +00:00
|
|
|
|
2007-10-19 02:31:25 +00:00
|
|
|
@fwrite($this->__smtpConnection, base64_encode($this->smtpOptions['username'])."\r\n");
|
|
|
|
$response = $this->__getSmtpResponse();
|
|
|
|
|
|
|
|
if (stristr($response, '334') === false){
|
|
|
|
$this->smtpError = $response;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@fwrite($this->__smtpConnection, base64_encode($this->smtpOptions['password'])."\r\n");
|
|
|
|
$response = $this->__getSmtpResponse();
|
|
|
|
|
2007-11-06 06:09:06 +00:00
|
|
|
if (stristr($response, '235') === false){
|
2007-10-19 02:31:25 +00:00
|
|
|
$this->smtpError = $response;
|
|
|
|
return false;
|
|
|
|
}
|
2007-06-27 15:12:48 +00:00
|
|
|
return true;
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
2007-10-22 21:03:47 +00:00
|
|
|
* Set as controller flash message a debug message showing current settings in component
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
2007-10-22 21:03:47 +00:00
|
|
|
* @return boolean Success
|
2007-07-24 19:34:35 +00:00
|
|
|
* @access private
|
2006-12-25 10:51:08 +00:00
|
|
|
*/
|
2006-12-25 06:39:02 +00:00
|
|
|
function __debug() {
|
|
|
|
$fm = '<pre>';
|
2007-07-07 23:33:22 +00:00
|
|
|
|
2007-06-26 20:29:38 +00:00
|
|
|
if ($this->delivery == 'smtp') {
|
2007-09-16 19:19:52 +00:00
|
|
|
$fm .= sprintf("%s %s\n", 'Host:', $this->smtpOptions['host']);
|
|
|
|
$fm .= sprintf("%s %s\n", 'Port:', $this->smtpOptions['port']);
|
|
|
|
$fm .= sprintf("%s %s\n", 'Timeout:', $this->smtpOptions['timeout']);
|
2007-06-26 20:29:38 +00:00
|
|
|
}
|
2007-09-16 19:19:52 +00:00
|
|
|
$fm .= sprintf("%s %s\n", 'To:', $this->to);
|
|
|
|
$fm .= sprintf("%s %s\n", 'From:', $this->from);
|
|
|
|
$fm .= sprintf("%s %s\n", 'Subject:', $this->subject);
|
|
|
|
$fm .= sprintf("%s\n\n%s", 'Header:', $this->__header);
|
|
|
|
$fm .= sprintf("%s\n\n%s", 'Parameters:', $this->additionalParams);
|
|
|
|
$fm .= sprintf("%s\n\n%s", 'Message:', $this->__message);
|
2006-12-25 06:39:02 +00:00
|
|
|
$fm .= '</pre>';
|
|
|
|
|
|
|
|
$this->Controller->Session->setFlash($fm, 'default', null, 'email');
|
|
|
|
return true;
|
|
|
|
}
|
2006-09-11 20:06:01 +00:00
|
|
|
}
|
2007-10-19 02:31:25 +00:00
|
|
|
?>
|