home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / class / mail / xoopsmultimailer.php < prev   
Encoding:
PHP Script  |  2007-12-05  |  9.3 KB  |  281 lines

  1. <?php
  2. // $Id: xoopsmultimailer.php 1150 2007-12-04 15:30:14Z phppp $
  3. //  ------------------------------------------------------------------------ //
  4. //                XOOPS - PHP Content Management System                      //
  5. //                    Copyright (c) 2000 XOOPS.org                           //
  6. //                       <http://www.xoops.org/>                             //
  7. //  ------------------------------------------------------------------------ //
  8. //  This program is free software; you can redistribute it and/or modify     //
  9. //  it under the terms of the GNU General Public License as published by     //
  10. //  the Free Software Foundation; either version 2 of the License, or        //
  11. //  (at your option) any later version.                                      //
  12. //                                                                           //
  13. //  You may not change or alter any portion of this comment or credits       //
  14. //  of supporting developers from this source code or any supporting         //
  15. //  source code which is considered copyrighted (c) material of the          //
  16. //  original comment or credit authors.                                      //
  17. //                                                                           //
  18. //  This program is distributed in the hope that it will be useful,          //
  19. //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
  20. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
  21. //  GNU General Public License for more details.                             //
  22. //                                                                           //
  23. //  You should have received a copy of the GNU General Public License        //
  24. //  along with this program; if not, write to the Free Software              //
  25. //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
  26. //  ------------------------------------------------------------------------ //
  27. // Author: Jochen Bⁿεnagel (job@buennagel.com)                               //
  28. // URL:  http://www.xoops.org                                                 //
  29. // Project: The XOOPS Project                                                //
  30. // ------------------------------------------------------------------------- //
  31. if (!defined("XOOPS_ROOT_PATH")) {
  32.     die("XOOPS root path not defined");
  33. }
  34. /**
  35.  * @package        class
  36.  * @subpackage    mail
  37.  * 
  38.  * @filesource 
  39.  *
  40.  * @author        Jochen Bⁿεnagel    <jb@buennagel.com>
  41.  * @copyright    copyright (c) 2000-2003 The XOOPS Project (http://www.xoops.org)
  42.  *
  43.  * @version        $Revision: 1150 $ - $Date: 2007-12-04 23:30:14 +0800 (Tue, 04 Dec 2007) $
  44.  */
  45.  
  46. /**
  47.  * load the base class
  48.  */
  49. require_once(XOOPS_ROOT_PATH.'/class/mail/phpmailer/class.phpmailer.php');
  50.  
  51. /**
  52.  * Mailer Class.
  53.  * 
  54.  * At the moment, this does nothing but send email through PHP's "mail()" function,
  55.  * but it has the abiltiy to do much more.
  56.  * 
  57.  * If you have problems sending mail with "mail()", you can edit the member variables
  58.  * to suit your setting. Later this will be possible through the admin panel.
  59.  *
  60.  * @todo        Make a page in the admin panel for setting mailer preferences.
  61.  * 
  62.  * @package        class
  63.  * @subpackage    mail
  64.  *
  65.  * @author        Jochen Buennagel    <job@buennagel.com>
  66.  * @copyright    (c) 2000-2003 The Xoops Project - www.xoops.org
  67.  * @version        $Revision: 1150 $ - changed by $Author$ on $Date: 2007-12-04 23:30:14 +0800 (Tue, 04 Dec 2007) $
  68.  */
  69. class XoopsMultiMailer extends PHPMailer {
  70.  
  71.     /**
  72.      * "from" address
  73.      * @var     string
  74.      * @access    private
  75.      */
  76.     var $From         = "";
  77.     
  78.     /**
  79.      * "from" name
  80.      * @var     string
  81.      * @access    private
  82.      */
  83.     var $FromName     = "";
  84.  
  85.     // can be "smtp", "sendmail", or "mail"
  86.     /**
  87.      * Method to be used when sending the mail.
  88.      * 
  89.      * This can be:
  90.      * <li>mail (standard PHP function "mail()") (default)
  91.      * <li>smtp    (send through any SMTP server, SMTPAuth is supported.
  92.      * You must set {@link $Host}, for SMTPAuth also {@link $SMTPAuth}, 
  93.      * {@link $Username}, and {@link $Password}.)
  94.      * <li>sendmail (manually set the path to your sendmail program 
  95.      * to something different than "mail()" uses in {@link $Sendmail}) 
  96.      * 
  97.      * @var     string
  98.      * @access    private
  99.      */
  100.     var $Mailer        = "mail";
  101.  
  102.     /**
  103.      * set if $Mailer is "sendmail"
  104.      * 
  105.      * Only used if {@link $Mailer} is set to "sendmail".
  106.      * Contains the full path to your sendmail program or replacement.
  107.      * @var     string
  108.      * @access    private
  109.      */
  110.     var $Sendmail = "/usr/sbin/sendmail";
  111.  
  112.     /**
  113.      * SMTP Host.
  114.      * 
  115.      * Only used if {@link $Mailer} is set to "smtp"
  116.      * @var     string
  117.      * @access    private
  118.      */
  119.     var $Host        = "";
  120.  
  121.     /**
  122.      * Does your SMTP host require SMTPAuth authentication?
  123.      * @var     boolean
  124.      * @access    private
  125.      */
  126.     var $SMTPAuth    = FALSE;
  127.  
  128.     /**
  129.      * Username for authentication with your SMTP host.
  130.      * 
  131.      * Only used if {@link $Mailer} is "smtp" and {@link $SMTPAuth} is TRUE
  132.      * @var     string
  133.      * @access    private
  134.      */
  135.     var $Username    = "";
  136.  
  137.     /**
  138.      * Password for SMTPAuth.
  139.      * 
  140.      * Only used if {@link $Mailer} is "smtp" and {@link $SMTPAuth} is TRUE
  141.      * @var     string
  142.      * @access    private
  143.      */
  144.     var $Password    = "";
  145.     
  146.     /**
  147.      * Constuctor
  148.      * 
  149.      * @access public
  150.      * @return void 
  151.      * 
  152.      * @global    $xoopsConfig
  153.      */
  154.     function XoopsMultiMailer(){
  155.         global $xoopsConfig;
  156.     
  157.         $config_handler =& xoops_gethandler('config');
  158.         $xoopsMailerConfig =& $config_handler->getConfigsByCat(XOOPS_CONF_MAILER);
  159.         $this->From = $xoopsMailerConfig['from'];
  160.         if ($this->From == '') {
  161.             $this->From = $xoopsConfig['adminmail'];
  162.         }
  163.         $this->Sender = $this->From;
  164.  
  165.         if ($xoopsMailerConfig["mailmethod"] == "smtpauth") {
  166.             $this->Mailer = "smtp";
  167.             $this->SMTPAuth = TRUE;
  168.             // TODO: change value type of xoopsConfig "smtphost" from array to text
  169.             $this->Host = implode(';',$xoopsMailerConfig['smtphost']);
  170.             $this->Username = $xoopsMailerConfig['smtpuser'];
  171.             $this->Password = $xoopsMailerConfig['smtppass'];
  172.         } else {
  173.             $this->Mailer = $xoopsMailerConfig['mailmethod'];
  174.             $this->SMTPAuth = FALSE;
  175.             $this->Sendmail = $xoopsMailerConfig['sendmailpath'];
  176.             $this->Host = implode(';',$xoopsMailerConfig['smtphost']);
  177.         }
  178.         $this->CharSet = strtolower( _CHARSET );
  179.         if ( file_exists( XOOPS_ROOT_PATH . "/language/{$xoopsConfig['language']}/phpmailer.php" ) ) {
  180.             include( XOOPS_ROOT_PATH . "/language/{$xoopsConfig['language']}/phpmailer.php" );
  181.             $this->language = $PHPMAILER_LANG;
  182.         } else {
  183.             $this->SetLanguage( 'en', XOOPS_ROOT_PATH . "/class/mail/phpmailer/language/" );
  184.         }
  185.         $this->PluginDir = XOOPS_ROOT_PATH."/class/mail/phpmailer/";
  186.     }
  187.  
  188.     /**
  189.      * Formats an address correctly. This overrides the default addr_format method which does not seem to encode $FromName correctly
  190.      * @access private
  191.      * @return string
  192.      */
  193.     function AddrFormat($addr) {
  194.         if(empty($addr[1]))
  195.             $formatted = $addr[0];
  196.         else
  197.             $formatted = sprintf('%s <%s>', '=?'.$this->CharSet.'?B?'.base64_encode($addr[1]).'?=', $addr[0]);
  198.  
  199.         return $formatted;
  200.     }
  201.  
  202.     /**
  203.     * Sends mail via SMTP using PhpSMTP (Author:
  204.     * Chris Ryan).  Returns bool.  Returns false if there is a
  205.     * bad MAIL FROM, or DATA input.
  206.     * Rebuild Header if there is a bad RCPT
  207.     * @access protected
  208.     * @return bool
  209.     */
  210.     function SmtpSend($header, $body) {
  211.         include_once($this->PluginDir . "class.smtp.php");
  212.         $error = "";
  213.         $bad_rcpt = array();
  214.  
  215.         if (!$this->SmtpConnect()) {
  216.             return false;
  217.         }            
  218.  
  219.         $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender;
  220.         if (!$this->smtp->Mail($smtp_from)) {
  221.             $error = $this->Lang("from_failed") . $smtp_from;
  222.             $this->SetError($error);
  223.             $this->smtp->Reset();
  224.             return false;
  225.         }
  226.         // Attempt to send attach all recipients
  227.         for ($i = 0; $i < count($this->to); $i++) {
  228.             if (!$this->smtp->Recipient($this->to[$i][0])) {
  229.                 $bad_rcpt[] = $this->to[$i][0];
  230.                 unset($this->to[$i]);
  231.             }
  232.         }
  233.         for ($i = 0; $i < count($this->cc); $i++) {
  234.             if (!$this->smtp->Recipient($this->cc[$i][0])) {
  235.                 $bad_rcpt[] = $this->cc[$i][0];
  236.                 unset($this->cc[$i]);
  237.             }
  238.         }
  239.         for ($i = 0; $i < count($this->bcc); $i++) {
  240.             if (!$this->smtp->Recipient($this->bcc[$i][0])) {
  241.                 $bad_rcpt[] = $this->bcc[$i][0];
  242.                 unset($this->bcc[$i]);
  243.             }
  244.         }
  245.  
  246.         // Create error message
  247.         $count = count($bad_rcpt);
  248.         if ($count > 0) {
  249.             for ($i = 0; $i < $count; $i++) {
  250.                 if ($i != 0) { 
  251.                     $error .= ", ";
  252.                 }
  253.                 $error .= $bad_rcpt[$i];
  254.             }
  255.             
  256.             //To rebuild a correct header, it should to rebuild a correct adress array
  257.             $this->to = array_values($this->to);
  258.             $this->cc = array_values($this->cc);
  259.             $this->bcc = array_values($this->bcc);
  260.             $header = $this->CreateHeader();
  261.             
  262.             $error = $this->Lang("recipients_failed") . $error;
  263.             $this->SetError($error);
  264.         }
  265.         if (!$this->smtp->Data($header . $body)) {
  266.             $this->SetError($this->Lang("data_not_accepted"));
  267.             $this->smtp->Reset();
  268.             return false;
  269.         }
  270.         if ($this->SMTPKeepAlive == true) {
  271.             $this->smtp->Reset();
  272.         } else {
  273.             $this->SmtpClose();
  274.         }
  275.  
  276.         return true;
  277.     }
  278. }
  279.  
  280.  
  281. ?>