Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: 
  3: /*
  4:  * This file is part of SwiftMailer.
  5:  * (c) 2004-2009 Chris Corbyn
  6:  *
  7:  * For the full copyright and license information, please view the LICENSE
  8:  * file that was distributed with this source code.
  9:  */
 10: 
 11: /**
 12:  * Sends Messages using the mail() function.
 13:  *
 14:  * It is advised that users do not use this transport if at all possible
 15:  * since a number of plugin features cannot be used in conjunction with this
 16:  * transport due to the internal interface in PHP itself.
 17:  *
 18:  * The level of error reporting with this transport is incredibly weak, again
 19:  * due to limitations of PHP's internal mail() function.  You'll get an
 20:  * all-or-nothing result from sending.
 21:  *
 22:  * @package Swift
 23:  * @subpackage Transport
 24:  * @author Chris Corbyn
 25:  */
 26: class Swift_Transport_MailTransport implements Swift_Transport
 27: {
 28:     /** Addtional parameters to pass to mail() */
 29:     private $_extraParams = '-f%s';
 30: 
 31:     /** The event dispatcher from the plugin API */
 32:     private $_eventDispatcher;
 33: 
 34:     /** An invoker that calls the mail() function */
 35:     private $_invoker;
 36: 
 37:     /**
 38:      * Create a new MailTransport with the $log.
 39:      * @param Swift_Transport_Log $log
 40:      */
 41:     public function __construct(Swift_Transport_MailInvoker $invoker, Swift_Events_EventDispatcher $eventDispatcher)
 42:     {
 43:         $this->_invoker = $invoker;
 44:         $this->_eventDispatcher = $eventDispatcher;
 45:     }
 46: 
 47:     /**
 48:      * Not used.
 49:      */
 50:     public function isStarted()
 51:     {
 52:         return false;
 53:     }
 54: 
 55:     /**
 56:      * Not used.
 57:      */
 58:     public function start()
 59:     {
 60:     }
 61: 
 62:     /**
 63:      * Not used.
 64:      */
 65:     public function stop()
 66:     {
 67:     }
 68: 
 69:     /**
 70:      * Set the additional parameters used on the mail() function.
 71:      *
 72:      * This string is formatted for sprintf() where %s is the sender address.
 73:      *
 74:      * @param  string                        $params
 75:      * @return Swift_Transport_MailTransport
 76:      */
 77:     public function setExtraParams($params)
 78:     {
 79:         $this->_extraParams = $params;
 80: 
 81:         return $this;
 82:     }
 83: 
 84:     /**
 85:      * Get the additional parameters used on the mail() function.
 86:      *
 87:      * This string is formatted for sprintf() where %s is the sender address.
 88:      *
 89:      * @return string
 90:      */
 91:     public function getExtraParams()
 92:     {
 93:         return $this->_extraParams;
 94:     }
 95: 
 96:     /**
 97:      * Send the given Message.
 98:      *
 99:      * Recipient/sender data will be retrieved from the Message API.
100:      * The return value is the number of recipients who were accepted for delivery.
101:      *
102:      * @param Swift_Mime_Message $message
103:      * @param string[] &$failedRecipients to collect failures by-reference
104:      * @return int
105:      */
106:     public function send(Swift_Mime_Message $message, &$failedRecipients = null)
107:     {
108:         $failedRecipients = (array) $failedRecipients;
109: 
110:         if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) {
111:             $this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
112:             if ($evt->bubbleCancelled()) {
113:                 return 0;
114:             }
115:         }
116: 
117:         $count = (
118:             count((array) $message->getTo())
119:             + count((array) $message->getCc())
120:             + count((array) $message->getBcc())
121:             );
122: 
123:         $toHeader = $message->getHeaders()->get('To');
124:         $subjectHeader = $message->getHeaders()->get('Subject');
125: 
126:         if (!$toHeader) {
127:             throw new Swift_TransportException(
128:                 'Cannot send message without a recipient'
129:                 );
130:         }
131:         $to = $toHeader->getFieldBody();
132:         $subject = $subjectHeader ? $subjectHeader->getFieldBody() : '';
133: 
134:         $reversePath = $this->_getReversePath($message);
135: 
136:         //Remove headers that would otherwise be duplicated
137:         $message->getHeaders()->remove('To');
138:         $message->getHeaders()->remove('Subject');
139: 
140:         $messageStr = $message->toString();
141: 
142:         $message->getHeaders()->set($toHeader);
143:         $message->getHeaders()->set($subjectHeader);
144: 
145:         //Separate headers from body
146:         if (false !== $endHeaders = strpos($messageStr, "\r\n\r\n")) {
147:             $headers = substr($messageStr, 0, $endHeaders) . "\r\n"; //Keep last EOL
148:             $body = substr($messageStr, $endHeaders + 4);
149:         } else {
150:             $headers = $messageStr . "\r\n";
151:             $body = '';
152:         }
153: 
154:         unset($messageStr);
155: 
156:         if ("\r\n" != PHP_EOL) {
157:             //Non-windows (not using SMTP)
158:             $headers = str_replace("\r\n", PHP_EOL, $headers);
159:             $body = str_replace("\r\n", PHP_EOL, $body);
160:         } else {
161:             //Windows, using SMTP
162:             $headers = str_replace("\r\n.", "\r\n..", $headers);
163:             $body = str_replace("\r\n.", "\r\n..", $body);
164:         }
165: 
166:         if ($this->_invoker->mail($to, $subject, $body, $headers,
167:             sprintf($this->_extraParams, $reversePath)))
168:         {
169:             if ($evt) {
170:                 $evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
171:                 $evt->setFailedRecipients($failedRecipients);
172:                 $this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
173:             }
174:         } else {
175:             $failedRecipients = array_merge(
176:                 $failedRecipients,
177:                 array_keys((array) $message->getTo()),
178:                 array_keys((array) $message->getCc()),
179:                 array_keys((array) $message->getBcc())
180:                 );
181: 
182:             if ($evt) {
183:                 $evt->setResult(Swift_Events_SendEvent::RESULT_FAILED);
184:                 $evt->setFailedRecipients($failedRecipients);
185:                 $this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
186:             }
187: 
188:             $message->generateId();
189: 
190:             $count = 0;
191:         }
192: 
193:         return $count;
194:     }
195: 
196:     /**
197:      * Register a plugin.
198:      *
199:      * @param Swift_Events_EventListener $plugin
200:      */
201:     public function registerPlugin(Swift_Events_EventListener $plugin)
202:     {
203:         $this->_eventDispatcher->bindEventListener($plugin);
204:     }
205: 
206:     // -- Private methods
207: 
208:     /** Determine the best-use reverse path for this message */
209:     private function _getReversePath(Swift_Mime_Message $message)
210:     {
211:         $return = $message->getReturnPath();
212:         $sender = $message->getSender();
213:         $from = $message->getFrom();
214:         $path = null;
215:         if (!empty($return)) {
216:             $path = $return;
217:         } elseif (!empty($sender)) {
218:             $keys = array_keys($sender);
219:             $path = array_shift($keys);
220:         } elseif (!empty($from)) {
221:             $keys = array_keys($from);
222:             $path = array_shift($keys);
223:         }
224: 
225:         return $path;
226:     }
227: }
228: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen