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
|
|
|
|
*
|
|
|
|
*/
|
2006-12-25 06:39:02 +00:00
|
|
|
class EmailComponent extends Object{
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-11 20:37:13 +00:00
|
|
|
var $to = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-11 20:37:13 +00:00
|
|
|
var $from = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $replyTo = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $return = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $cc = array();
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $bcc = array();
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-11 20:37:13 +00:00
|
|
|
var $subject = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-12-25 06:39:02 +00:00
|
|
|
var $additionalParams = null;
|
2007-04-03 01:15:24 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $layout = 'default';
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-11 20:37:13 +00:00
|
|
|
var $template = 'default';
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-12-25 06:39:02 +00:00
|
|
|
var $sendAs = 'text'; //html, text, both
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-12-25 06:39:02 +00:00
|
|
|
var $delivery = 'mail'; //mail, smtp, debug
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $charset = 'ISO-8859-15';
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $attachments = array();
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-12-25 06:39:02 +00:00
|
|
|
var $xMailer = 'CakePHP Email Component';
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $filePaths = array();
|
2007-06-25 21:17:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SMTP options variable
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $smtpOptions = array('port'=> 25,
|
|
|
|
'host' => 'localhost',
|
|
|
|
'timeout' => 30);
|
2007-06-26 04:28:24 +00:00
|
|
|
|
2007-06-26 20:29:38 +00:00
|
|
|
/**
|
|
|
|
* SMTP errors variable
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $smtpError = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access protected
|
|
|
|
*/
|
2006-09-11 20:37:13 +00:00
|
|
|
var $_debug = false;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access protected
|
|
|
|
*/
|
2006-09-11 20:37:13 +00:00
|
|
|
var $_error = false;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access protected
|
|
|
|
*/
|
2007-02-01 20:11:28 +00:00
|
|
|
var $_newLine = "\n";
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
* @access protected
|
|
|
|
*/
|
2007-04-29 04:16:43 +00:00
|
|
|
var $_lineLength = 70;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $__header = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-09-12 00:26:50 +00:00
|
|
|
var $__boundary = null;
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-09-12 01:55:32 +00:00
|
|
|
var $__message = null;
|
2007-06-25 21:17:09 +00:00
|
|
|
|
2007-06-27 15:12:48 +00:00
|
|
|
/**
|
|
|
|
* Variable that holds SMTP connection
|
|
|
|
*
|
|
|
|
* @var resource
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
var $__smtpConnection = null;
|
|
|
|
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $controller
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param mixed $content
|
|
|
|
* @return unknown
|
|
|
|
* @access public
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function send($content = 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-06-20 06:15:35 +00:00
|
|
|
if ($this->template === null) {
|
2007-06-20 07:51:52 +00:00
|
|
|
if (is_array($content)) {
|
2006-09-12 01:55:32 +00:00
|
|
|
$message = null;
|
2007-06-20 07:51:52 +00:00
|
|
|
foreach ($content as $key => $value) {
|
2006-09-12 01:55:32 +00:00
|
|
|
$message .= $value . $this->_newLine;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$message = $content;
|
|
|
|
}
|
2006-12-25 06:39:02 +00:00
|
|
|
$this->__formatMessage($message);
|
2006-09-12 00:26:50 +00:00
|
|
|
} else {
|
2006-12-25 06:39:02 +00:00
|
|
|
$this->__message = $this->__renderTemplate($content);
|
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-02-01 20:11:28 +00:00
|
|
|
if (!is_null($this->__boundary)) {
|
2007-03-08 02:01:29 +00:00
|
|
|
$this->__message .= $this->_newLine .'--' . $this->__boundary . '--' . $this->_newLine . $this->_newLine;
|
2007-02-01 20:11:28 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 07:51:52 +00:00
|
|
|
if ($this->_debug) {
|
2006-12-25 06:39:02 +00:00
|
|
|
$this->delivery = 'debug';
|
|
|
|
}
|
2006-09-12 00:26:50 +00:00
|
|
|
$__method = '__'.$this->delivery;
|
2007-03-27 02:59:22 +00:00
|
|
|
|
2006-12-25 06:39:02 +00:00
|
|
|
return $this->$__method();
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-09-23 23:35:22 +00:00
|
|
|
function reset() {
|
|
|
|
$this->to = null;
|
|
|
|
$this->from = null;
|
|
|
|
$this->replyTo = null;
|
|
|
|
$this->return = null;
|
|
|
|
$this->cc = array();
|
|
|
|
$this->bcc = array();
|
|
|
|
$this->subject = null;
|
2006-12-25 06:39:02 +00:00
|
|
|
$this->additionalParams = null;
|
2006-09-23 23:35:22 +00:00
|
|
|
$this->__header = null;
|
|
|
|
$this->__boundary = null;
|
|
|
|
$this->__message = null;
|
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param string $content
|
|
|
|
* @return unknown
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-12-25 06:39:02 +00:00
|
|
|
function __renderTemplate($content) {
|
|
|
|
$View = new View($this->Controller);
|
2007-04-03 01:15:24 +00:00
|
|
|
$View->layout = $this->layout;
|
2007-06-20 07:51:52 +00:00
|
|
|
if ($this->sendAs === 'both') {
|
2007-03-25 18:16:24 +00:00
|
|
|
$htmlContent = $content;
|
2006-12-25 06:39:02 +00:00
|
|
|
$msg = '--' . $this->__boundary . $this->_newLine;
|
|
|
|
$msg .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
|
2007-02-01 20:11:28 +00:00
|
|
|
$msg .= 'Content-Transfer-Encoding: 8bit' . $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-03-08 02:01:29 +00:00
|
|
|
$msg .= $this->_newLine. '--' . $this->__boundary . $this->_newLine;
|
2007-02-01 20:11:28 +00:00
|
|
|
$msg .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
|
2006-12-25 06:39:02 +00:00
|
|
|
$msg .= 'Content-Transfer-Encoding: 8bit' . $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';
|
|
|
|
$msg .= $View->renderLayout($content);
|
|
|
|
|
|
|
|
return $msg;
|
|
|
|
} else {
|
2007-02-02 02:47:53 +00:00
|
|
|
$content = $View->renderElement('email' . DS . $this->sendAs . DS . $this->template, array('content' => $content), true);
|
2006-12-25 06:39:02 +00:00
|
|
|
$View->layoutPath = 'email' . DS . $this->sendAs;
|
|
|
|
return $View->renderLayout($content);
|
|
|
|
}
|
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __createBoundary() {
|
2006-09-12 00:26:50 +00:00
|
|
|
$this->__boundary = md5(uniqid(time()));
|
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __createHeader() {
|
2007-03-28 22:57:07 +00:00
|
|
|
$this->__header .= 'From: ' . $this->__formatAddress($this->from) . $this->_newLine;
|
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;
|
|
|
|
}
|
2006-09-12 00:26:50 +00:00
|
|
|
|
|
|
|
$addresses = null;
|
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-03-28 22:57:07 +00:00
|
|
|
$addresses .= $this->__formatAddress($cc) . ', ';
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
|
|
|
$this->__header .= 'cc: ' . $addresses . $this->_newLine;
|
|
|
|
}
|
2007-04-04 07:46:04 +00:00
|
|
|
$addresses = null;
|
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-03-28 22:57:07 +00:00
|
|
|
$addresses .= $this->__formatAddress($bcc) . ', ';
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
|
|
|
$this->__header .= 'Bcc: ' . $addresses . $this->_newLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->__header .= 'X-Mailer: ' . $this->xMailer . $this->_newLine;
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!empty($this->attachments) && $this->sendAs === 'text') {
|
2007-02-01 20:11:28 +00:00
|
|
|
$this->__createBoundary();
|
2006-09-12 00:26:50 +00:00
|
|
|
$this->__header .= 'MIME-Version: 1.0' . $this->_newLine;
|
2007-02-01 20:11:28 +00:00
|
|
|
$this->__header .= 'Content-Type: multipart/mixed; boundary="' . $this->__boundary . '"' . $this->_newLine;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (!empty($this->attachments) && $this->sendAs === 'html') {
|
2007-02-01 20:11:28 +00:00
|
|
|
$this->__createBoundary();
|
2006-09-12 00:26:50 +00:00
|
|
|
$this->__header .= 'MIME-Version: 1.0' . $this->_newLine;
|
2007-02-01 20:11:28 +00:00
|
|
|
$this->__header .= 'Content-Type: multipart/related; boundary="' . $this->__boundary . '"' . $this->_newLine;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif ($this->sendAs === 'html') {
|
2007-02-01 20:11:28 +00:00
|
|
|
$this->__header .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
|
|
|
|
$this->__header .= 'Content-Transfer-Encoding: 8bit' . $this->_newLine;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif ($this->sendAs === 'both') {
|
2007-02-01 20:11:28 +00:00
|
|
|
$this->__createBoundary();
|
2006-09-12 00:26:50 +00:00
|
|
|
$this->__header .= 'MIME-Version: 1.0' . $this->_newLine;
|
2007-02-01 20:11:28 +00:00
|
|
|
$this->__header .= 'Content-Type: multipart/alternative; boundary="' . $this->__boundary . '"' . $this->_newLine;
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param string $message
|
|
|
|
* @access private
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __formatMessage($message) {
|
2006-09-12 01:55:32 +00:00
|
|
|
$message = $this->__wrap($message);
|
2006-09-12 00:26:50 +00:00
|
|
|
|
2007-06-20 07:51:52 +00:00
|
|
|
if ($this->sendAs === 'both') {
|
2006-09-21 08:49:18 +00:00
|
|
|
$this->__message = '--' . $this->__boundary . $this->_newLine;
|
|
|
|
$this->__message .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
|
|
|
|
$this->__message .= 'Content-Transfer-Encoding: 8bit' . $this->_newLine;
|
|
|
|
$this->__message .= 'If you are seeing this is because you may need to change your'.$this->_newLine;
|
|
|
|
$this->__message .= 'preferred message format from HTML to plain text.'.$this->_newLine.$this->_newLine;
|
2006-09-12 01:55:32 +00:00
|
|
|
$this->__message .= strip_tags($message) . $this->_newLine;
|
2006-09-21 08:49:18 +00:00
|
|
|
|
2006-12-25 06:39:02 +00:00
|
|
|
$this->__message .= '--' . $this->__boundary . $this->_newLine;
|
2006-09-12 01:55:32 +00:00
|
|
|
$this->__message .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
|
|
|
|
$this->__message .= 'Content-Transfer-Encoding: 8bit' . $this->_newLine;
|
|
|
|
$this->__message .= $message . $this->_newLine;
|
|
|
|
$this->__message .= $this->_newLine . $this->_newLine;
|
2006-09-12 00:26:50 +00:00
|
|
|
} else {
|
2006-09-12 01:55:32 +00:00
|
|
|
$this->__message .= $message . $this->_newLine;
|
2006-09-12 00:26:50 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @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) {
|
2006-09-12 00:26:50 +00:00
|
|
|
$files[] = $this->__findFiles($attachment);
|
|
|
|
}
|
|
|
|
|
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)) ;
|
|
|
|
$filetype = mime_content_type($file);
|
|
|
|
|
2006-09-12 01:55:32 +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
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param string $attachment
|
|
|
|
* @return unknown
|
|
|
|
* @access private
|
|
|
|
*/
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param string $message
|
|
|
|
* @return unknown
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-09-12 01:55:32 +00:00
|
|
|
function __wrap($message) {
|
2006-09-21 09:32:05 +00:00
|
|
|
$message = str_replace(array('\r','\n'), '\n', $message);
|
|
|
|
$words = explode('\n', $message);
|
2006-09-21 08:49:18 +00:00
|
|
|
$formated = null;
|
2006-09-12 01:55:32 +00:00
|
|
|
foreach ($words as $word) {
|
2007-04-29 04:16:43 +00:00
|
|
|
$formated .= wordwrap($word, $this->_lineLength, "\n", true);
|
2006-09-21 09:32:05 +00:00
|
|
|
$formated .= "\n";
|
2006-09-12 01:55:32 +00:00
|
|
|
}
|
|
|
|
return $formated;
|
|
|
|
}
|
2007-03-28 22:57:07 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param string $subject
|
|
|
|
* @return unknown
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function __encode($subject) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (low($this->charset) !== 'iso-8859-15') {
|
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);
|
|
|
|
|
|
|
|
$subject = base64_encode($subject);
|
|
|
|
$subject = chunk_split($subject, $length, $spacer);
|
|
|
|
$spacer = preg_quote($spacer);
|
|
|
|
$subject = preg_replace("/" . $spacer . "$/", "", $subject);
|
|
|
|
$subject = $start . $subject . $end;
|
|
|
|
}
|
2007-04-03 01:15:24 +00:00
|
|
|
|
2007-03-28 22:57:07 +00:00
|
|
|
return $subject;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param string $string
|
|
|
|
* @return unknown
|
|
|
|
* @access private
|
|
|
|
*/
|
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-04-03 01:08:49 +00:00
|
|
|
return $string;
|
2007-03-28 22:57:07 +00:00
|
|
|
}
|
2006-12-25 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
* @access private
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __mail() {
|
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-06-26 04:28:24 +00:00
|
|
|
* Sends out email via SMTP
|
2006-12-25 10:51:08 +00:00
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __smtp() {
|
2007-06-27 15:12:48 +00:00
|
|
|
$response = $this->__smtpConnect($this->smtpOptions);
|
|
|
|
|
|
|
|
if ($response['status'] == false) {
|
|
|
|
$this->smtpError = "{$response['errno']}: {$response['errstr']}";
|
2007-06-26 20:29:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-27 15:12:48 +00:00
|
|
|
$this->__sendData("HELO cake\r\n", 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-06-27 15:12:48 +00:00
|
|
|
$this->__sendData("DATA\r\n{$this->__header}\r\n{$this->__message}\r\n\r\n\r\n.\r\n", false);
|
|
|
|
$this->__sendData("QUIT\r\n", false);
|
|
|
|
return true;
|
|
|
|
}
|
2007-06-25 21:17:09 +00:00
|
|
|
|
2007-06-27 15:12:48 +00:00
|
|
|
/**
|
|
|
|
* Private method for connecting to an SMTP server
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @param array $options SMTP connection options
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function __smtpConnect($options) {
|
|
|
|
$status = true;
|
|
|
|
$this->__smtpConnection = @fsockopen($options['host'], $options['port'], $errno, $errstr, $options['timeout']);
|
|
|
|
|
|
|
|
if ($this->__smtpConnection == false) {
|
|
|
|
$status = false;
|
2007-06-25 21:17:09 +00:00
|
|
|
}
|
2006-09-12 01:55:32 +00:00
|
|
|
|
2007-06-27 15:12:48 +00:00
|
|
|
return array('status' => $status,
|
|
|
|
'errno' => $errno,
|
|
|
|
'errstr' => $errstr);
|
2007-06-26 20:29:38 +00:00
|
|
|
}
|
2007-06-27 15:12:48 +00:00
|
|
|
|
2007-06-26 20:29:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private method for getting SMTP response
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private method for sending data to SMTP connection
|
|
|
|
*
|
2007-06-27 15:12:48 +00:00
|
|
|
* @param string $data data to be sent to SMTP server
|
|
|
|
* @param boolean $check check for response from server
|
2007-06-26 20:29:38 +00:00
|
|
|
*/
|
2007-06-27 15:12:48 +00:00
|
|
|
function __sendData($data, $check = true) {
|
|
|
|
@fwrite($this->__smtpConnection, $data);
|
2007-06-26 20:29:38 +00:00
|
|
|
$response = $this->__getSmtpResponse();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If there is a 250 in the response code, that means
|
|
|
|
* everything went ok
|
|
|
|
*/
|
2007-06-27 15:12:48 +00:00
|
|
|
if ($check == true && !stristr($response, '250')) {
|
2007-06-26 20:29:38 +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
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-12-25 06:39:02 +00:00
|
|
|
function __debug() {
|
|
|
|
$fm = '<pre>';
|
2007-06-26 20:29:38 +00:00
|
|
|
|
|
|
|
if ($this->delivery == 'smtp') {
|
|
|
|
$fm .= sprintf('%s %s', 'Host:', $this->smtpOptions['host']);
|
|
|
|
$fm .= sprintf('%s %s', 'Port:', $this->smtpOptions['port']);
|
|
|
|
$fm .= sprintf('%s %s', 'Timeout:', $this->smtpOptions['timeout']);
|
|
|
|
}
|
|
|
|
|
2006-12-25 06:39:02 +00:00
|
|
|
$fm .= sprintf('%s %s', 'To:', $this->to);
|
2007-06-26 20:29:38 +00:00
|
|
|
$fm .= sprintf('%s %s', 'From:', $this->from);
|
2006-12-25 06:39:02 +00:00
|
|
|
$fm .= sprintf('%s %s', '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);
|
|
|
|
$fm .= '</pre>';
|
|
|
|
|
|
|
|
$this->Controller->Session->setFlash($fm, 'default', null, 'email');
|
|
|
|
return true;
|
|
|
|
}
|
2006-09-11 20:06:01 +00:00
|
|
|
}
|
2007-06-25 21:17:09 +00:00
|
|
|
?>
|