E qui l'altra classe class.phpmailer.php

Codice PHP:
<?php
////////////////////////////////////////////////////
// PHPMailer - PHP email class
//
// Class for sending email using either
// sendmail, PHP mail(), or SMTP.  Methods are
// based upon the standard AspEmail(tm) classes.
//
// Copyright (C) 2001 - 2003  Brent R. Matzelle
//
// License: LGPL, see LICENSE
////////////////////////////////////////////////////

/**
 * PHPMailer - PHP email transport class
 * @package PHPMailer
 * @author Brent R. Matzelle
 * @copyright 2001 - 2003 Brent R. Matzelle
 */
class PHPMailer
{
    
/////////////////////////////////////////////////
    // PUBLIC VARIABLES
    /////////////////////////////////////////////////

    /**
     * Email priority (1 = High, 3 = Normal, 5 = low).
     * @var int
     */
    
var $Priority          3;

    
/**
     * Sets the CharSet of the message.
     * @var string
     */
    
var $CharSet           "iso-8859-1";

    
/**
     * Sets the Content-type of the message.
     * @var string
     */
    
var $ContentType        "text/plain";

    
/**
     * Sets the Encoding of the message. Options for this are "8bit",
     * "7bit", "binary", "base64", and "quoted-printable".
     * @var string
     */
    
var $Encoding          "8bit";

    
/**
     * Holds the most recent mailer error message.
     * @var string
     */
    
var $ErrorInfo         "";

    
/**
     * Sets the From email address for the message.
     * @var string
     */
    
var $From               "root@localhost";

    
/**
     * Sets the From name of the message.
     * @var string
     */
    
var $FromName           "Root User";

    
/**
     * Sets the Sender email (Return-Path) of the message.  If not empty,
     * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
     * @var string
     */
    
var $Sender            "";

    
/**
     * Sets the Subject of the message.
     * @var string
     */
    
var $Subject           "";

    
/**
     * Sets the Body of the message.  This can be either an HTML or text body.
     * If HTML then run IsHTML(true).
     * @var string
     */
    
var $Body               "";

    
/**
     * Sets the text-only body of the message.  This automatically sets the
     * email to multipart/alternative.  This body can be read by mail
     * clients that do not have HTML email capability such as mutt. Clients
     * that can read HTML will view the normal Body.
     * @var string
     */
    
var $AltBody           "";

    
/**
     * Sets word wrapping on the body of the message to a given number of 
     * characters.
     * @var int
     */
    
var $WordWrap          0;

    
/**
     * Method to send mail: ("mail", "sendmail", or "smtp").
     * @var string
     */
    
var $Mailer            "mail";

    
/**
     * Sets the path of the sendmail program.
     * @var string
     */
    
var $Sendmail          "/usr/sbin/sendmail";
    
    
/**
     * Path to PHPMailer plugins.  This is now only useful if the SMTP class 
     * is in a different directory than the PHP include path.  
     * @var string
     */
    
var $PluginDir         "";

    
/**
     *  Holds PHPMailer version.
     *  @var string
     */
    
var $Version           "1.72";

    
/**
     * Sets the email address that a reading confirmation will be sent.
     * @var string
     */
    
var $ConfirmReadingTo  "";

    
/**
     *  Sets the hostname to use in Message-Id and Received headers
     *  and as default HELO string. If empty, the value returned
     *  by SERVER_NAME is used or 'localhost.localdomain'.
     *  @var string
     */
    
var $Hostname          "";

    
/////////////////////////////////////////////////
    // SMTP VARIABLES
    /////////////////////////////////////////////////

    /**
     *  Sets the SMTP hosts.  All hosts must be separated by a
     *  semicolon.  You can also specify a different port
     *  for each host by using this format: [hostname:port]
     *  (e.g. "smtp1.example.com:25;smtp2.example.com").
     *  Hosts will be tried in order.
     *  @var string
     */
    
var $Host        "localhost";

    
/**
     *  Sets the default SMTP server port.
     *  @var int
     */
    
var $Port        25;

    
/**
     *  Sets the SMTP HELO of the message (Default is $Hostname).
     *  @var string
     */
    
var $Helo        "";

    
/**
     *  Sets SMTP authentication. Utilizes the Username and Password variables.
     *  @var bool
     */
    
var $SMTPAuth     false;

    
/**
     *  Sets SMTP username.
     *  @var string
     */
    
var $Username     "";

    
/**
     *  Sets SMTP password.
     *  @var string
     */
    
var $Password     "";

    
/**
     *  Sets the SMTP server timeout in seconds. This function will not 
     *  work with the win32 version.
     *  @var int
     */
    
var $Timeout      10;

    
/**
     *  Sets SMTP class debugging on or off.
     *  @var bool
     */
    
var $SMTPDebug    false;

    
/**
     * Prevents the SMTP connection from being closed after each mail 
     * sending.  If this is set to true then to close the connection 
     * requires an explicit call to SmtpClose(). 
     * @var bool
     */
    
var $SMTPKeepAlive false;

    
/**#@+
     * @access private
     */
    
var $smtp            NULL;
    var 
$to              = array();
    var 
$cc              = array();
    var 
$bcc             = array();
    var 
$ReplyTo         = array();
    var 
$attachment      = array();
    var 
$CustomHeader    = array();
    var 
$message_type    "";
    var 
$boundary        = array();
    var 
$language        = array();
    var 
$error_count     0;
    var 
$LE              "\n";
    
/**#@-*/
    
    /////////////////////////////////////////////////
    // VARIABLE METHODS
    /////////////////////////////////////////////////

    /**
     * Sets message type to HTML.  
     * @param bool $bool
     * @return void
     */
    
function IsHTML($bool) {
        if(
$bool == true)
            
$this->ContentType "text/html";
        else
            
$this->ContentType "text/plain";
    }

    
/**
     * Sets Mailer to send message using SMTP.
     * @return void
     */
    
function IsSMTP() {
        
$this->Mailer "smtp";
    }

    
/**
     * Sets Mailer to send message using PHP mail() function.
     * @return void
     */
    
function IsMail() {
        
$this->Mailer "mail";
    }

    
/**
     * Sets Mailer to send message using the $Sendmail program.
     * @return void
     */
    
function IsSendmail() {
        
$this->Mailer "sendmail";
    }

    
/**
     * Sets Mailer to send message using the qmail MTA. 
     * @return void
     */
    
function IsQmail() {
        
$this->Sendmail "/var/qmail/bin/sendmail";
        
$this->Mailer "sendmail";
    }


    
/////////////////////////////////////////////////
    // RECIPIENT METHODS
    /////////////////////////////////////////////////

    /**
     * Adds a "To" address.  
     * @param string $address
     * @param string $name
     * @return void
     */
    
function AddAddress($address$name "") {
        
$cur count($this->to);
        
$this->to[$cur][0] = trim($address);
        
$this->to[$cur][1] = $name;
    }

    
/**
     * Adds a "Cc" address. Note: this function works
     * with the SMTP mailer on win32, not with the "mail"
     * mailer.  
     * @param string $address
     * @param string $name
     * @return void
    */
    
function AddCC($address$name "") {
        
$cur count($this->cc);
        
$this->cc[$cur][0] = trim($address);
        
$this->cc[$cur][1] = $name;
    }

    
/**
     * Adds a "Bcc" address. Note: this function works
     * with the SMTP mailer on win32, not with the "mail"
     * mailer.  
     * @param string $address
     * @param string $name
     * @return void
     */
    
function AddBCC($address$name "") {
        
$cur count($this->bcc);
        
$this->bcc[$cur][0] = trim($address);
        
$this->bcc[$cur][1] = $name;
    }

    
/**
     * Adds a "Reply-to" address.  
     * @param string $address
     * @param string $name
     * @return void
     */
    
function AddReplyTo($address$name "") {
        
$cur count($this->ReplyTo);
        
$this->ReplyTo[$cur][0] = trim($address);
        
$this->ReplyTo[$cur][1] = $name;
    }


    
/////////////////////////////////////////////////
    // MAIL SENDING METHODS
    /////////////////////////////////////////////////

    /**
     * Creates message and assigns Mailer. If the message is
     * not sent successfully then it returns false.  Use the ErrorInfo
     * variable to view description of the error.  
     * @return bool
     */
    
function Send() {
        
$header "";
        
$body "";
        
$result true;

        if((
count($this->to) + count($this->cc) + count($this->bcc)) < 1)
        {
            
$this->SetError($this->Lang("provide_address"));
            return 
false;
        }

        
// Set whether the message is multipart/alternative
        
if(!empty($this->AltBody))
            
$this->ContentType "multipart/alternative";

        
$this->error_count 0// reset errors
        
$this->SetMessageType();
        
$header .= $this->CreateHeader();
        
$body $this->CreateBody();

        if(
$body == "") { return false; }

        
// Choose the mailer
        
switch($this->Mailer)
        {
            case 
"sendmail":
                
$result $this->SendmailSend($header$body);
                break;
            case 
"mail":
                
$result $this->MailSend($header$body);
                break;
            case 
"smtp":
                
$result $this->SmtpSend($header$body);
                break;
            default:
            
$this->SetError($this->Mailer $this->Lang("mailer_not_supported"));
                
$result false;
                break;
        }

        return 
$result;
    }
    
    
/**
     * Sends mail using the $Sendmail program.  
     * @access private
     * @return bool
     */
    
function SendmailSend($header$body) {
        if (
$this->Sender != "")
            
$sendmail sprintf("%s -oi -f %s -t"$this->Sendmail$this->Sender);
        else
            
$sendmail sprintf("%s -oi -t"$this->Sendmail);

        if(!@
$mail popen($sendmail"w"))
        {
            
$this->SetError($this->Lang("execute") . $this->Sendmail);
            return 
false;
        }

        
fputs($mail$header);
        
fputs($mail$body);
        
        
$result pclose($mail) >> 0xFF;
        if(
$result != 0)
        {
            
$this->SetError($this->Lang("execute") . $this->Sendmail);
            return 
false;
        }

        return 
true;
    }

    
/**
     * Sends mail using the PHP mail() function.  
     * @access private
     * @return bool
     */
    
function MailSend($header$body) {
        
$to "";
        for(
$i 0$i count($this->to); $i++)
        {
            if(
$i != 0) { $to .= ", "; }
            
$to .= $this->to[$i][0];
        }

        if (
$this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
        {
            
$old_from ini_get("sendmail_from");
            
ini_set("sendmail_from"$this->Sender);
            
$params sprintf("-oi -f %s"$this->Sender);
            
$rt = @mail($to$this->EncodeHeader($this->Subject), $body
                        
$header$params);
        }
        else
            
$rt = @mail($to$this->EncodeHeader($this->Subject), $body$header);

        if (isset(
$old_from))
            
ini_set("sendmail_from"$old_from);

        if(!
$rt)
        {
            
$this->SetError($this->Lang("instantiate"));
            return 
false;
        }

        return 
true;
    }