email.php

Go to the documentation of this file.
00001 <?php
00002 /* SVN FILE: $Id: email_8php-source.html 580 2008-07-01 14:45:49Z gwoo $ */
00003 /**
00004  * Short description for file.
00005  *
00006  * Long description for file
00007  *
00008  * PHP versions 4 and 5
00009  *
00010  * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
00011  * Copyright 2005-2008, Cake Software Foundation, Inc.
00012  *                      1785 E. Sahara Avenue, Suite 490-204
00013  *                      Las Vegas, Nevada 89104
00014  *
00015  * Licensed under The MIT License
00016  * Redistributions of files must retain the above copyright notice.
00017  *
00018  * @filesource
00019  * @copyright       Copyright 2005-2008, Cake Software Foundation, Inc.
00020  * @link            http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
00021  * @package         cake
00022  * @subpackage      cake.cake.libs.controller.components
00023  * @since           CakePHP(tm) v 1.2.0.3467
00024  * @version         $Revision: 580 $
00025  * @modifiedby      $LastChangedBy: gwoo $
00026  * @lastmodified    $Date: 2008-07-01 09:45:49 -0500 (Tue, 01 Jul 2008) $
00027  * @license         http://www.opensource.org/licenses/mit-license.php The MIT License
00028  */
00029 /**
00030  * EmailComponent
00031  *
00032  * This component is used for handling Internet Message Format based
00033  * based on the standard outlined in http://www.rfc-editor.org/rfc/rfc2822.txt
00034  *
00035  * @package     cake
00036  * @subpackage  cake.cake.libs.controller.components
00037  *
00038  */
00039 class EmailComponent extends Object{
00040 /**
00041  * Recipient of the email
00042  *
00043  * @var string
00044  * @access public
00045  */
00046     var $to = null;
00047 /**
00048  * The mail which the email is sent from
00049  *
00050  * @var string
00051  * @access public
00052  */
00053     var $from = null;
00054 /**
00055  * The email the recipient will reply to
00056  *
00057  * @var string
00058  * @access public
00059  */
00060     var $replyTo = null;
00061 /**
00062  * The read receipt email
00063  *
00064  * @var string
00065  * @access public
00066  */
00067     var $readReceipt = null;
00068 /**
00069  * The mail that will be used in case of any errors like
00070  * - Remote mailserver down
00071  * - Remote user has exceeded his quota
00072  * - Unknown user
00073  *
00074  * @var string
00075  * @access public
00076  */
00077     var $return = null;
00078 /**
00079  * Carbon Copy
00080  *
00081  * List of email's that should receive a copy of the email.
00082  * The Recipient WILL be able to see this list
00083  *
00084  * @var array
00085  * @access public
00086  */
00087     var $cc = array();
00088 /**
00089  * Blind Carbon Copy
00090  *
00091  * List of email's that should receive a copy of the email.
00092  * The Recipient WILL NOT be able to see this list
00093  *
00094  * @var array
00095  * @access public
00096  */
00097     var $bcc = array();
00098 /**
00099  * The subject of the email
00100  *
00101  * @var string
00102  * @access public
00103  */
00104     var $subject = null;
00105 /**
00106  * Associative array of a user defined headers
00107  * Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
00108  *
00109  * @var array
00110  * @access public
00111  */
00112     var $headers = array();
00113 /**
00114  * List of additional headers
00115  *
00116  * These will NOT be used if you are using safemode and mail()
00117  *
00118  * @var string
00119  * @access public
00120  */
00121     var $additionalParams = null;
00122 /**
00123  * Layout for the View
00124  *
00125  * @var string
00126  * @access public
00127  */
00128     var $layout = 'default';
00129 /**
00130  * Template for the view
00131  *
00132  * @var string
00133  * @access public
00134  */
00135     var $template = null;
00136 /**
00137  * as per RFC2822 Section 2.1.1
00138  *
00139  * @var integer
00140  * @access public
00141  */
00142     var $lineLength = 70;
00143 /**
00144  * @deprecated see lineLength
00145  */
00146     var $_lineLength = null;
00147 /**
00148  * What format should the email be sent in
00149  *
00150  * Supported formats:
00151  * - text
00152  * - html
00153  * - both
00154  *
00155  * @var string
00156  * @access public
00157  */
00158     var $sendAs = 'text';
00159 /**
00160  * What method should the email be sent by
00161  *
00162  * Supported methods:
00163  * - mail
00164  * - smtp
00165  * - debug
00166  *
00167  * @var string
00168  * @access public
00169  */
00170     var $delivery = 'mail';
00171 /**
00172  * charset the email is sent in
00173  *
00174  * @var string
00175  * @access public
00176  */
00177     var $charset = 'utf-8';
00178 /**
00179  * List of files that should be attached to the email.
00180  *
00181  * Can be both absolute and relative paths
00182  *
00183  * @var array
00184  * @access public
00185  */
00186     var $attachments = array();
00187 /**
00188  * What mailer should EmailComponent identify itself as
00189  *
00190  * @var string
00191  * @access public
00192  */
00193     var $xMailer = 'CakePHP Email Component';
00194 /**
00195  * The list of paths to search if an attachment isnt absolute
00196  *
00197  * @var array
00198  * @access public
00199  */
00200     var $filePaths = array();
00201 /**
00202  * List of options to use for smtp mail method
00203  *
00204  * Options is:
00205  * - port
00206  * - host
00207  * - timeout
00208  * - username
00209  * - password
00210  *
00211  * @var array
00212  * @access public
00213  */
00214     var $smtpOptions = array(
00215         'port'=> 25, 'host' => 'localhost', 'timeout' => 30
00216     );
00217 /**
00218  * Placeholder for any errors that might happen with the
00219  * smtp mail methods
00220  *
00221  * @var string
00222  * @access public
00223  */
00224     var $smtpError = null;
00225 /**
00226  * If set to true, the mail method will be auto-set to 'debug'
00227  *
00228  * @var string
00229  * @access protected
00230  */
00231     var $_debug = false;
00232 /**
00233  * Enter description here...
00234  *
00235  * @var string
00236  * @access protected
00237  */
00238     var $_error = false;
00239 /**
00240  * New lines char
00241  *
00242  * @var string
00243  * @access protected
00244  */
00245     var $_newLine = "\n";
00246 /**
00247  * Enter description here...
00248  *
00249  * @var string
00250  * @access private
00251  */
00252     var $__header = null;
00253 /**
00254  * Enter description here...
00255  *
00256  * @var string
00257  * @access private
00258  */
00259     var $__boundary = null;
00260 /**
00261  * Enter description here...
00262  *
00263  * @var string
00264  * @access private
00265  */
00266     var $__message = null;
00267 /**
00268  * Variable that holds SMTP connection
00269  *
00270  * @var resource
00271  * @access private
00272  */
00273     var $__smtpConnection = null;
00274 /**
00275  * Startup component
00276  *
00277  * @param object $controller Instantiating controller
00278  * @access public
00279  */
00280     function startup(&$controller) {
00281         $this->Controller =& $controller;
00282         if (Configure::read('App.encoding') !== null) {
00283             $this->charset = Configure::read('App.encoding');
00284         }
00285     }
00286 /**
00287  * Send an email using the specified content, template and layout
00288  *
00289  * @param mixed $content Either an array of text lines, or a string with contents
00290  * @param string $template Template to use when sending email
00291  * @param string $layout Layout to use to enclose email body
00292  * @return boolean Success
00293  * @access public
00294  */
00295     function send($content = null, $template = null, $layout = null) {
00296         $this->__createHeader();
00297 
00298         if ($template) {
00299             $this->template = $template;
00300         }
00301 
00302         if ($layout) {
00303             $this->layout = $layout;
00304         }
00305 
00306         if (is_array($content)) {
00307             $message = null;
00308             foreach ($content as $key => $value) {
00309                 $message .= $value . $this->_newLine;
00310             }
00311         } else {
00312             $message = $content;
00313         }
00314 
00315         if ($template === null && $this->template === null) {
00316             $this->__formatMessage($message);
00317         } else {
00318             $message = $this->__wrap($message);
00319             $this->__message = $this->__renderTemplate($message);
00320         }
00321 
00322         if (!empty($this->attachments)) {
00323             $this->__attachFiles();
00324         }
00325 
00326         if (!is_null($this->__boundary)) {
00327             $this->__message .= $this->_newLine .'--' . $this->__boundary . '--' . $this->_newLine . $this->_newLine;
00328         }
00329 
00330         if ($this->_debug) {
00331             return $this->__debug();
00332         }
00333         $__method = '__'.$this->delivery;
00334         $sent = $this->$__method();
00335 
00336         $this->__header = '';
00337         $this->__message = '';
00338 
00339         return $sent;
00340     }
00341 /**
00342  * Reset all EmailComponent internal variables to be able to send out a new email.
00343  *
00344  * @access public
00345  */
00346     function reset() {
00347         $this->template = null;
00348         $this->to = null;
00349         $this->from = null;
00350         $this->replyTo = null;
00351         $this->return = null;
00352         $this->cc = array();
00353         $this->bcc = array();
00354         $this->subject = null;
00355         $this->additionalParams = null;
00356         $this->__header = null;
00357         $this->__boundary = null;
00358         $this->__message = null;
00359     }
00360 /**
00361  * Render the contents using the current layout and template.
00362  *
00363  * @param string $content Content to render
00364  * @return string Email ready to be sent
00365  * @access private
00366  */
00367     function __renderTemplate($content) {
00368         $viewClass = $this->Controller->view;
00369 
00370         if ($viewClass != 'View') {
00371             if (strpos($viewClass, '.') !== false) {
00372                 list($plugin, $viewClass) = explode('.', $viewClass);
00373             }
00374             $viewClass = $viewClass . 'View';
00375             App::import('View', $this->Controller->view);
00376         }
00377         $View = new $viewClass($this->Controller, false);
00378         $View->layout = $this->layout;
00379         $msg = null;
00380 
00381         if ($this->sendAs === 'both') {
00382             $htmlContent = $content;
00383             if (!empty($this->attachments)) {
00384                 $msg .= '--' . $this->__boundary . $this->_newLine;
00385                 $msg .= 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"' . $this->_newLine . $this->_newLine;
00386             }
00387             $msg .= '--alt-' . $this->__boundary . $this->_newLine;
00388             $msg .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
00389             $msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
00390 
00391             $content = $View->element('email' . DS . 'text' . DS . $this->template, array('content' => $content), true);
00392             $View->layoutPath = 'email' . DS . 'text';
00393             $msg .= $View->renderLayout($content) . $this->_newLine;
00394 
00395             $msg .= $this->_newLine. '--alt-' . $this->__boundary . $this->_newLine;
00396             $msg .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
00397             $msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
00398 
00399             $content = $View->element('email' . DS . 'html' . DS . $this->template, array('content' => $htmlContent), true);
00400             $View->layoutPath = 'email' . DS . 'html';
00401             $msg .= $View->renderLayout($content) . $this->_newLine . $this->_newLine;
00402             $msg .= '--alt-' . $this->__boundary . '--' . $this->_newLine . $this->_newLine;
00403             return $msg;
00404 
00405         }
00406 
00407         if (!empty($this->attachments)) {
00408             if ($this->sendAs === 'html') {
00409                 $msg .= $this->_newLine. '--' . $this->__boundary . $this->_newLine;
00410                 $msg .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
00411                 $msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
00412             } else {
00413                 $msg .= '--' . $this->__boundary . $this->_newLine;
00414                 $msg .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
00415                 $msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
00416             }
00417         }
00418 
00419         $content = $View->element('email' . DS . $this->sendAs . DS . $this->template, array('content' => $content), true);
00420         $View->layoutPath = 'email' . DS . $this->sendAs;
00421         $msg .= $View->renderLayout($content) . $this->_newLine;
00422         return $msg;
00423     }
00424 /**
00425  * Create unique boundary identifier
00426  *
00427  * @access private
00428  */
00429     function __createBoundary() {
00430         $this->__boundary = md5(uniqid(time()));
00431     }
00432 /**
00433  * Create emails headers including (but not limited to) from email address, reply to,
00434  * bcc and cc.
00435  *
00436  * @access private
00437  */
00438     function __createHeader() {
00439         if ($this->delivery == 'smtp') {
00440             $this->_newLine = "\r\n";
00441             $this->__header = 'To: ' . $this->__formatAddress($this->to) . $this->_newLine;
00442         }
00443         $this->__header .= 'From: ' . $this->__formatAddress($this->from) . $this->_newLine;
00444 
00445         if (!empty($this->replyTo)) {
00446             $this->__header .= 'Reply-To: ' . $this->__formatAddress($this->replyTo) . $this->_newLine;
00447         }
00448         if (!empty($this->return)) {
00449             $this->__header .= 'Return-Path: ' . $this->__formatAddress($this->return) . $this->_newLine;
00450         }
00451         if (!empty($this->readReceipt)) {
00452             $this->__header .= 'Disposition-Notification-To: ' . $this->__formatAddress($this->readReceipt) . $this->_newLine;
00453         }
00454         $addresses = null;
00455 
00456         if (!empty($this->cc)) {
00457             foreach ($this->cc as $cc) {
00458                 $addresses .= ', ' . $this->__formatAddress($cc);
00459             }
00460             $this->__header .= 'cc: ' . substr($addresses, 2) . $this->_newLine;
00461         }
00462         $addresses = null;
00463 
00464         if (!empty($this->bcc)) {
00465             foreach ($this->bcc as $bcc) {
00466                 $addresses .= ', ' . $this->__formatAddress($bcc);
00467             }
00468             $this->__header .= 'Bcc: ' . substr($addresses, 2) . $this->_newLine;
00469         }
00470         if ($this->delivery == 'smtp') {
00471             $this->__header .= 'Subject: ' . $this->__encode($this->subject) . $this->_newLine;
00472         }
00473         $this->__header .= 'X-Mailer: ' . $this->xMailer . $this->_newLine;
00474 
00475         if (!empty($this->headers)) {
00476             foreach ($this->headers as $key => $val) {
00477                 $this->__header .= 'X-'.$key.': '.$val . $this->_newLine;
00478             }
00479         }
00480 
00481         if (!empty($this->attachments)) {
00482             $this->__createBoundary();
00483             $this->__header .= 'MIME-Version: 1.0' . $this->_newLine;
00484             $this->__header .= 'Content-Type: multipart/mixed; boundary="' . $this->__boundary . '"' . $this->_newLine;
00485             $this->__header .= 'This part of the E-mail should never be seen. If' . $this->_newLine;
00486             $this->__header .= 'you are reading this, consider upgrading your e-mail' . $this->_newLine;
00487             $this->__header .= 'client to a MIME-compatible client.' . $this->_newLine;
00488         } elseif ($this->sendAs === 'text') {
00489             $this->__header .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
00490         } elseif ($this->sendAs === 'html') {
00491             $this->__header .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
00492         } elseif ($this->sendAs === 'both') {
00493             $this->__header .= 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"' . $this->_newLine . $this->_newLine;
00494         }
00495 
00496         $this->__header .= 'Content-Transfer-Encoding: 7bit';
00497     }
00498 /**
00499  * Format the message by seeing if it has attachments.
00500  *
00501  * @param string $message Message to format
00502  * @access private
00503  */
00504     function __formatMessage($message) {
00505         if (!empty($this->attachments)) {
00506             $this->__message .= '--' . $this->__boundary . $this->_newLine;
00507             $this->__message .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
00508             $this->__message .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
00509         }
00510         $message = $this->__wrap($message);
00511         $this->__message .= $message . $this->_newLine;
00512     }
00513 /**
00514  * Attach files by adding file contents inside boundaries.
00515  *
00516  * @access private
00517  */
00518     function __attachFiles() {
00519         $files = array();
00520         foreach ($this->attachments as $attachment) {
00521             $file = $this->__findFiles($attachment);
00522             if (!empty($file)) {
00523                 $files[] = $file;
00524             }
00525         }
00526 
00527         foreach ($files as $file) {
00528             $handle = fopen($file, 'rb');
00529             $data = fread($handle, filesize($file));
00530             $data = chunk_split(base64_encode($data)) ;
00531             fclose($handle);
00532 
00533             $this->__message .= '--' . $this->__boundary . $this->_newLine;
00534             $this->__message .= 'Content-Type: application/octet-stream' . $this->_newLine;
00535             $this->__message .= 'Content-Transfer-Encoding: base64' . $this->_newLine;
00536             $this->__message .= 'Content-Disposition: attachment; filename="' . basename($file) . '"' . $this->_newLine . $this->_newLine;
00537             $this->__message .= $data . $this->_newLine . $this->_newLine;
00538         }
00539     }
00540 /**
00541  * Find the specified attachment in the list of file paths
00542  *
00543  * @param string $attachment Attachment file name to find
00544  * @return string Path to located file
00545  * @access private
00546  */
00547     function __findFiles($attachment) {
00548         if (file_exists($attachment)) {
00549             return $attachment;
00550         }
00551         foreach ($this->filePaths as $path) {
00552             if (file_exists($path . DS . $attachment)) {
00553                 $file = $path . DS . $attachment;
00554                 return $file;
00555             }
00556         }
00557         return null;
00558     }
00559 /**
00560  * Wrap the message using EmailComponent::$lineLength
00561  *
00562  * @param string $message Message to wrap
00563  * @return string Wrapped message
00564  * @access private
00565  */
00566     function __wrap($message) {
00567         $message = $this->__strip($message, true);
00568         $message = str_replace(array("\r\n","\r"), "\n", $message);
00569         $lines = explode("\n", $message);
00570         $formatted = null;
00571 
00572         if ($this->_lineLength !== null) {
00573             trigger_error('_lineLength cannot be accessed please use lineLength', E_USER_WARNING);
00574             $this->lineLength = $this->_lineLength;
00575         }
00576 
00577         foreach ($lines as $line) {
00578             if(substr($line, 0, 1) == '.') {
00579                 $line = '.' . $line;
00580             }
00581             $formatted .= wordwrap($line, $this->lineLength, $this->_newLine, true);
00582             $formatted .= $this->_newLine;
00583         }
00584         return $formatted;
00585     }
00586 /**
00587  * Encode the specified string using the current charset
00588  *
00589  * @param string $subject String to encode
00590  * @return string Encoded string
00591  * @access private
00592  */
00593     function __encode($subject) {
00594         $subject = $this->__strip($subject);
00595 
00596         if (strtolower($this->charset) !== 'iso-8859-15') {
00597             $start = "=?" . $this->charset . "?B?";
00598             $end = "?=";
00599             $spacer = $end . $this->_newLine . $start;
00600 
00601             $length = 75 - strlen($start) - strlen($end);
00602             $length = $length - ($length % 4);
00603 
00604             $subject = base64_encode($subject);
00605             $subject = chunk_split($subject, $length, $spacer);
00606             $spacer = preg_quote($spacer);
00607             $subject = preg_replace("/" . $spacer . "$/", "", $subject);
00608             $subject = $start . $subject . $end;
00609         }
00610         return $subject;
00611     }
00612 /**
00613  * Format a string as an email address
00614  *
00615  * @param string $string String representing an email address
00616  * @return string Email address suitable for email headers or smtp pipe
00617  * @access private
00618  */
00619     function __formatAddress($string, $smtp = false) {
00620         if (strpos($string, '<') !== false) {
00621             $value = explode('<', $string);
00622             if ($smtp) {
00623                 $string = '<' . $value[1];
00624             } else {
00625                 $string = $this->__encode($value[0]) . ' <' . $value[1];
00626             }
00627         }
00628         return $this->__strip($string);
00629     }
00630 /**
00631  * Remove certain elements (such as bcc:, to:, %0a) from given value
00632  *
00633  * @param string $value Value to strip
00634  * @param boolean $message Set to true to indicate main message content
00635  * @return string Stripped value
00636  * @access private
00637  */
00638     function __strip($value, $message = false) {
00639         $search = array(
00640             '/%0a/i', '/%0d/i', '/Content-Type\:/i', '/charset\=/i', '/mime-version\:/i',
00641             '/multipart\/mixed/i', '/bcc\:.*/i','/to\:.*/i','/cc\:.*/i', '/Content-Transfer-Encoding\:/i',
00642             '/\\r/i', '/\\n/i'
00643         );
00644 
00645         if ($message === true) {
00646             $search = array_slice($search, 0, -2);
00647         }
00648 
00649         foreach ($search as $key) {
00650             while (preg_match($key, $value)) {
00651                 $value = preg_replace($key, '', $value);
00652             }
00653         }
00654         return preg_replace($search, '', $value);
00655     }
00656 /**
00657  * Wrapper for PHP mail function used for sending out emails
00658  *
00659  * @return bool Success
00660  * @access private
00661  */
00662     function __mail() {
00663         if (ini_get('safe_mode')) {
00664             return @mail($this->to, $this->__encode($this->subject), $this->__message, $this->__header);
00665         }
00666         return @mail($this->to, $this->__encode($this->subject), $this->__message, $this->__header, $this->additionalParams);
00667     }
00668 /**
00669  * Sends out email via SMTP
00670  *
00671  * @return bool Success
00672  * @access private
00673  */
00674     function __smtp() {
00675         App::import('Core', array('Socket'));
00676 
00677         $this->__smtpConnection =& new CakeSocket(array_merge(array('protocol'=>'smtp'), $this->smtpOptions));
00678 
00679         if (!$this->__smtpConnection->connect()) {
00680             $this->smtpError = $this->__smtpConnection->lastError();
00681             return false;
00682         } elseif (!$this->__smtpSend(null, '220')) {
00683             return false;
00684         }
00685 
00686         if (!$this->__smtpSend('HELO cake', '250')) {
00687             return false;
00688         }
00689 
00690         if (isset($this->smtpOptions['username']) && isset($this->smtpOptions['password'])) {
00691             if (!$this->__smtpSend('AUTH LOGIN', '334')) {
00692                 return false;
00693             }
00694             if (!$this->__smtpSend(base64_encode($this->smtpOptions['username']), '334')) {
00695                 return false;
00696             }
00697             if (!$this->__smtpSend(base64_encode($this->smtpOptions['password']), '235')) {
00698                 return false;
00699             }
00700         }
00701 
00702         if (!$this->__smtpSend('MAIL FROM: ' . $this->__formatAddress($this->from, true))) {
00703             return false;
00704         }
00705 
00706         if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($this->to, true))) {
00707             return false;
00708         }
00709 
00710         foreach ($this->cc as $cc) {
00711             if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($cc, true))) {
00712                 return false;
00713             }
00714         }
00715         foreach ($this->bcc as $bcc) {
00716             if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($bcc, true))) {
00717                 return false;
00718             }
00719         }
00720 
00721         if (!$this->__smtpSend('DATA', '354')) {
00722             return false;
00723         }
00724 
00725         if (!$this->__smtpSend($this->__header . "\r\n\r\n" . $this->__message . "\r\n\r\n\r\n.")) {
00726             return false;
00727         }
00728         $this->__smtpSend('QUIT', false);
00729 
00730         $this->__smtpConnection->disconnect();
00731         return true;
00732     }
00733 /**
00734  * Private method for sending data to SMTP connection
00735  *
00736  * @param string $data data to be sent to SMTP server
00737  * @param mixed $checkCode code to check for in server response, false to skip
00738  * @return bool Success
00739  * @access private
00740  */
00741     function __smtpSend($data, $checkCode = '250') {
00742         if (!is_null($data)) {
00743             $this->__smtpConnection->write($data . "\r\n");
00744         }
00745         if ($checkCode !== false) {
00746             $response = '';
00747 
00748             while ($str = $this->__smtpConnection->read()) {
00749                 $response .= $str;
00750 
00751                 if ($str[3] == ' ') {
00752                     break;
00753                 }
00754             }
00755 
00756             if (stristr($response, $checkCode) === false) {
00757                 $this->smtpError = $response;
00758                 return false;
00759             }
00760         }
00761         return true;
00762     }
00763 /**
00764  * Set as controller flash message a debug message showing current settings in component
00765  *
00766  * @return boolean Success
00767  * @access private
00768  */
00769     function __debug() {
00770         $nl = $this->_newLine;
00771         $fm = '<pre>';
00772 
00773         if ($this->delivery == 'smtp') {
00774             $fm .= sprintf('%s %s%s', 'Host:', $this->smtpOptions['host'], $nl);
00775             $fm .= sprintf('%s %s%s', 'Port:', $this->smtpOptions['port'], $nl);
00776             $fm .= sprintf('%s %s%s', 'Timeout:', $this->smtpOptions['timeout'], $nl);
00777         }
00778         $fm .= sprintf('%s %s%s', 'To:', $this->to, $nl);
00779         $fm .= sprintf('%s %s%s', 'From:', $this->from, $nl);
00780         $fm .= sprintf('%s %s%s', 'Subject:', $this->subject, $nl);
00781         $fm .= sprintf('%s%3$s%3$s%s', 'Header:', $this->__header, $nl);
00782         $fm .= sprintf('%s%3$s%3$s%s', 'Parameters:', $this->additionalParams, $nl);
00783         $fm .= sprintf('%s%3$s%3$s%s', 'Message:', $this->__message, $nl);
00784         $fm .= '</pre>';
00785 
00786         $this->Controller->Session->setFlash($fm, 'default', null, 'email');
00787         return true;
00788     }
00789 }
00790 ?>