[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/joomla/mail/ -> mail.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: mail.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla.Framework
   5   * @subpackage    Mail
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant
   9   * to the GNU General Public License, and as distributed it includes or
  10   * is derivative of works licensed under the GNU General Public License or
  11   * other free or open source software licenses.
  12   * See COPYRIGHT.php for copyright notices and details.
  13   */
  14  
  15  // Check to ensure this file is within the rest of the framework
  16  defined('JPATH_BASE') or die();
  17  
  18  jimport('phpmailer.phpmailer');
  19  jimport('joomla.mail.helper');
  20  
  21  /**
  22   * E-Mail Class.  Provides a common interface to send e-mail from the Joomla! Framework
  23   *
  24   * @package     Joomla.Framework
  25   * @subpackage        Mail
  26   * @since        1.5
  27   */
  28  class JMail extends PHPMailer
  29  {
  30  
  31      /**
  32       * Constructor
  33       *
  34       */
  35  	function JMail()
  36      {
  37           // phpmailer has an issue using the relative path for it's language files
  38           $this->SetLanguage('joomla', JPATH_LIBRARIES.DS.'phpmailer'.DS.'language'.DS);
  39      }
  40  
  41      /**
  42       * Returns a reference to a global e-mail object, only creating it
  43       * if it doesn't already exist.
  44       *
  45       * This method must be invoked as:
  46       *         <pre>  $mail =& JMail::getInstance();</pre>
  47       *
  48       * NOTE: If you need an instance to use that does not have the global configuration
  49       * values, use an id string that is not 'Joomla'.
  50       *
  51       * @static
  52       * @access public
  53       * @param string $id The id string for the JMail instance [optional]
  54       * @return object The global JMail object
  55       * @since 1.5
  56       */
  57      function & getInstance($id = 'Joomla')
  58      {
  59          static $instances;
  60  
  61          if (!isset ($instances)) {
  62              $instances = array ();
  63          }
  64  
  65          if (empty ($instances[$id])) {
  66              $instances[$id] = new JMail();
  67          }
  68  
  69          return $instances[$id];
  70      }
  71  
  72      /**
  73       * @return mixed True if successful, a JError object otherwise
  74       */
  75      function &Send()
  76      {
  77          if ( ( $this->Mailer == 'mail' ) && ! function_exists('mail') )
  78          {
  79              return JError::raiseNotice( 500, JText::_('MAIL_FUNCTION_DISABLED') );
  80          }
  81  
  82          @ $result = parent::Send();
  83  
  84          if ($result == false)
  85          {
  86              // TODO: Set an appropriate error number
  87              $result =& JError::raiseNotice( 500, JText::_($this->ErrorInfo) );
  88          }
  89          return $result;
  90      }
  91  
  92      /**
  93       * Set the E-Mail sender
  94       *
  95       * @access public
  96       * @param array $from E-Mail address and Name of sender
  97       *         <pre>
  98       *             array( [0] => E-Mail Address [1] => Name )
  99       *         </pre>
 100       * @return void
 101       * @since 1.5
 102       */
 103  	function setSender($from)
 104      {
 105          // If $from is an array we assume it has an address and a name
 106          if (is_array($from))
 107          {
 108              $this->From     = JMailHelper::cleanLine( $from[0] );
 109              $this->FromName = JMailHelper::cleanLine( $from[1] );
 110          // If it is a string we assume it is just the address
 111          } elseif (is_string($from)) {
 112              $this->From = JMailHelper::cleanLine( $from );
 113          // If it is neither, we throw a warning
 114          } else {
 115              JError::raiseWarning( 0, "JMail::  Invalid E-Mail Sender: $from", "JMail::setSender($from)");
 116          }
 117      }
 118  
 119      /**
 120       * Set the E-Mail subject
 121       *
 122       * @access public
 123       * @param string $subject Subject of the e-mail
 124       * @return void
 125       * @since 1.5
 126       */
 127  	function setSubject($subject) {
 128          $this->Subject = JMailHelper::cleanLine( $subject );
 129      }
 130  
 131      /**
 132       * Set the E-Mail body
 133       *
 134       * @access public
 135       * @param string $content Body of the e-mail
 136       * @return void
 137       * @since 1.5
 138       */
 139  	function setBody($content)
 140      {
 141          /*
 142           * Filter the Body
 143           * TODO: Check for XSS
 144           */
 145          $this->Body = JMailHelper::cleanText( $content );
 146      }
 147  
 148      /**
 149       * Add recipients to the email
 150       *
 151       * @access public
 152       * @param mixed $recipient Either a string or array of strings [e-mail address(es)]
 153       * @return void
 154       * @since 1.5
 155       */
 156  	function addRecipient($recipient)
 157      {
 158          // If the recipient is an aray, add each recipient... otherwise just add the one
 159          if (is_array($recipient))
 160          {
 161              foreach ($recipient as $to) {
 162                  $to = JMailHelper::cleanLine( $to );
 163                  $this->AddAddress($to);
 164              }
 165          } else {
 166              $recipient = JMailHelper::cleanLine( $recipient );
 167              $this->AddAddress($recipient);
 168          }
 169      }
 170  
 171      /**
 172       * Add carbon copy recipients to the email
 173       *
 174       * @access public
 175       * @param mixed $cc Either a string or array of strings [e-mail address(es)]
 176       * @return void
 177       * @since 1.5
 178       */
 179  	function addCC($cc)
 180      {
 181          //If the carbon copy recipient is an aray, add each recipient... otherwise just add the one
 182          if (isset ($cc))
 183          {
 184              if (is_array($cc)) {
 185                  foreach ($cc as $to) {
 186                      $to = JMailHelper::cleanLine( $to );
 187                      parent::AddCC($to);
 188                  }
 189              } else {
 190                  $cc = JMailHelper::cleanLine( $cc );
 191                  parent::AddCC($cc);
 192              }
 193          }
 194      }
 195  
 196      /**
 197       * Add blind carbon copy recipients to the email
 198       *
 199       * @access public
 200       * @param mixed $cc Either a string or array of strings [e-mail address(es)]
 201       * @return void
 202       * @since 1.5
 203       */
 204  	function addBCC($bcc)
 205      {
 206          // If the blind carbon copy recipient is an aray, add each recipient... otherwise just add the one
 207          if (isset ($bcc))
 208          {
 209              if (is_array($bcc)) {
 210                  foreach ($bcc as $to) {
 211                      $to = JMailHelper::cleanLine( $to );
 212                      parent::AddBCC($to);
 213                  }
 214              } else {
 215                  $bcc = JMailHelper::cleanLine( $bcc );
 216                  parent::AddBCC($bcc);
 217              }
 218          }
 219      }
 220  
 221      /**
 222       * Add file attachments to the email
 223       *
 224       * @access public
 225       * @param mixed $attachment Either a string or array of strings [filenames]
 226       * @return void
 227       * @since 1.5
 228       */
 229  	function addAttachment($attachment)
 230      {
 231          // If the file attachments is an aray, add each file... otherwise just add the one
 232          if (isset ($attachment))
 233          {
 234              if (is_array($attachment)) {
 235                  foreach ($attachment as $file) {
 236                      parent::AddAttachment($file);
 237                  }
 238              } else {
 239                  parent::AddAttachment($attachment);
 240              }
 241          }
 242      }
 243  
 244      /**
 245       * Add Reply to e-mail address(es) to the e-mail
 246       *
 247       * @access public
 248       * @param array $reply Either an array or multi-array of form
 249       *         <pre>
 250       *             array( [0] => E-Mail Address [1] => Name )
 251       *         </pre>
 252       * @return void
 253       * @since 1.5
 254       */
 255  	function addReplyTo($replyto)
 256      {
 257          // Take care of reply email addresses
 258          if (is_array($replyto[0]))
 259          {
 260              foreach ($replyto as $to) {
 261                  $to0 = JMailHelper::cleanLine( $to[0] );
 262                  $to1 = JMailHelper::cleanLine( $to[1] );
 263                  parent::AddReplyTo($to0, $to1);
 264              }
 265          } else {
 266              $replyto0 = JMailHelper::cleanLine( $replyto[0] );
 267              $replyto1 = JMailHelper::cleanLine( $replyto[1] );
 268              parent::AddReplyTo($replyto0, $replyto1);
 269          }
 270      }
 271  
 272      /**
 273       * Use sendmail for sending the e-mail
 274       *
 275       * @access public
 276       * @param string $sendmail Path to sendmail [optional]
 277       * @return boolean True on success
 278       * @since 1.5
 279       */
 280  	function useSendmail($sendmail = null)
 281      {
 282          $this->Sendmail = $sendmail;
 283  
 284          if (!empty ($this->Sendmail)) {
 285              $this->IsSendmail();
 286              return true;
 287          } else {
 288              $this->IsMail();
 289              return false;
 290          }
 291      }
 292  
 293      /**
 294       * Use SMTP for sending the e-mail
 295       *
 296       * @access public
 297       * @param string $auth SMTP Authentication [optional]
 298       * @param string $host SMTP Host [optional]
 299       * @param string $user SMTP Username [optional]
 300       * @param string $pass SMTP Password [optional]
 301       * @param string $secure SMTP Secure ssl,tls [optinal]
 302       * @param string $port SMTP Port [optional]
 303       * @return boolean True on success
 304       * @since 1.5
 305       */
 306  	function useSMTP($auth = null, $host = null, $user = null, $pass = null,$secure = null, $port = 25)
 307      {
 308          $this->SMTPAuth = $auth;
 309          $this->Host     = $host;
 310          $this->Username = $user;
 311          $this->Password = $pass;
 312          $this->Port     = $port;
 313          if ($secure == 'ssl' || $secure == 'tls') {
 314              $this->SMTPSecure = $secure;
 315          }
 316  
 317          if ($this->SMTPAuth !== null && $this->Host !== null && $this->Username !== null && $this->Password !== null) {
 318              $this->IsSMTP();
 319          }
 320      }
 321  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1