Version 3.2.3

This commit is contained in:
Neo committed 2025-12-19 00:34:03 -08:00
1 parent ae5c01cc78
commit 78706903a2
2641 files changed
+228363 -201264

No files matched your search

+168 -148
View File
@@ -3,19 +3,19 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.1.4
* IP.Board v3.2.3
* Send email using php mail() or SMTP
* Last Updated: $Date: 2010-09-09 17:45:22 -0400 (Thu, 09 Sep 2010) $
* Last Updated: $Date: 2011-09-05 07:36:28 -0400 (Mon, 05 Sep 2011) $
* </pre>
*
* @author $Author: bfarber $
* @author $Author: mmecham $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/community/board/license.html
* @license This is NULLED!
* @package IP.Board
* @subpackage Kernel
* @link http://www.invisionpower.com
* @link http://hatynka.in
* @since Tuesday 1st March 2005 (11:52)
* @version $Revision: 459 $
* @version $Revision: 9451 $
*
*
* Example usage:
@@ -47,9 +47,8 @@ interface interfaceEmail
/**
* Constructor
*
* @access public
* @param array Initiate class parameters
* @return void
* @return @e void
*/
public function __construct( $opts=array() );
@@ -58,23 +57,20 @@ interface interfaceEmail
* to prevent having to close/reopen SMTP connection
* repeatedly.
*
* @access public
* @return void
* @return @e void
*/
public function clearEmail();
/**
* Clear stored errors to prepare a new email.
*
* @access public
* @return void
* @return @e void
*/
public function clearError();
/**
* Set the from email address
*
* @access public
* @param string From email address
* @param string [Optional] From display
* @return boolean
@@ -84,16 +80,22 @@ interface interfaceEmail
/**
* Set the 'to' email address
*
* @access public
* @param string To email address
* @return boolean
*/
public function setTo( $email );
/**
* Add cc's
*
* @param string To email address
* @return boolean
*/
public function addCC( $email );
/**
* Add bcc's
*
* @access public
* @param string To email address
* @return boolean
*/
@@ -102,7 +104,6 @@ interface interfaceEmail
/**
* Set the email subject
*
* @access public
* @param string Email subject
* @return boolean
*/
@@ -111,7 +112,6 @@ interface interfaceEmail
/**
* Set the email body
*
* @access public
* @param string Email body
* @return boolean
*/
@@ -120,7 +120,6 @@ interface interfaceEmail
/**
* Set a header manually
*
* @access public
* @param string Header key
* @param string Header value
* @return boolean
@@ -130,7 +129,6 @@ interface interfaceEmail
/**
* Send the mail (All appropriate params must be set by this point)
*
* @access public
* @return boolean Mail sent successfully
*/
public function sendMail();
@@ -138,11 +136,10 @@ interface interfaceEmail
/**
* Add an attachment to the current email
*
* @access public
* @param string File data
* @param string File name
* @param string File type (MIME)
* @return void
* @return @e void
*/
public function addAttachment( $data="", $name="", $ctype='application/octet-stream' );
@@ -157,89 +154,85 @@ class classEmail implements interfaceEmail
/**
* From email address
*
* @access private
* @var string
*/
private $from = "";
protected $from = "";
/**
* From email address (displayed)
*
* @access private
* @var string
*/
private $from_display = "";
protected $from_display = "";
/**
* To email address
*
* @access private
* @var string
*/
private $to = "";
protected $to = "";
/**
* Email subject
*
* @access private
* @var string
*/
private $subject = "";
protected $subject = "";
/**
* Email message contents
*
* @access private
* @var string
*/
private $message = "";
protected $message = "";
/**
* PHP mail() extra params
*
* @access private
* @var string
*/
private $extra_opts = '';
protected $extra_opts = '';
/**
* Plain text message contents
*
* @access private
* @var string
*/
private $pt_message = "";
protected $pt_message = "";
/**
* Attachments: Parts
*
* @access private
* @var array
*/
private $parts = array();
protected $parts = array();
/**
* CC Email addresses
*
* @var array
*/
protected $cc = array();
/**
* BCC Email addresses
*
* @access private
* @var array
*/
private $bcc = array();
protected $bcc = array();
/**
* Email headers
*
* @access private
* @var array
*/
private $mail_headers = array();
protected $mail_headers = array();
/**
* Header EOL
* RFC specs state \r\n
* However most servers seem to only support \n
*
* @access public
* @var string
*/
const header_eol = "\n";
@@ -247,47 +240,41 @@ class classEmail implements interfaceEmail
/**
* Attachments: Multi-part
*
* @access private
* @var string
*/
private $multipart = "";
protected $multipart = "";
/**
* Attachments: Boundry
*
* @access private
* @var string
*/
private $boundry = "----=_NextPart_000_0022_01C1BD6C.D0C0F9F0";
protected $boundry = "----=_NextPart_000_0022_01C1BD6C.D0C0F9F0";
/**
* HTML email flag
*
* @access private
* @var integer
*/
private $html_email = 0;
protected $html_email = 0;
/**
* Email character set
*
* @access private
* @var string
*/
private $char_set = 'utf-8';
protected $char_set = 'utf-8';
/**
* SMTP: Resource
*
* @access private
* @var resource
*/
private $smtp_fp = null;
protected $smtp_fp = null;
/**
* SMTP: Message
*
* @access public
* @var string
*/
public $smtp_msg = "";
@@ -295,39 +282,34 @@ class classEmail implements interfaceEmail
/**
* SMTP: Port
*
* @access private
* @var integer
*/
private $smtp_port = 25;
protected $smtp_port = 25;
/**
* SMTP: Host
*
* @access private
* @var string
*/
private $smtp_host = "localhost";
protected $smtp_host = "localhost";
/**
* SMTP: Username
*
* @access private
* @var string
*/
private $smtp_user = "";
protected $smtp_user = "";
/**
* SMTP: Password
*
* @access private
* @var string
*/
private $smtp_pass = "";
protected $smtp_pass = "";
/**
* SMTP: HELO or EHLO
*
* @access public
* @var string
*/
public $smtp_helo = "HELO";
@@ -335,7 +317,6 @@ class classEmail implements interfaceEmail
/**
* SMTP: Return code
*
* @access public
* @var string
*/
public $smtp_code = "";
@@ -343,39 +324,34 @@ class classEmail implements interfaceEmail
/**
* SMTP: Wrap email addresses in brackets flag
*
* @access private
* @var boolean
*/
private $wrap_brackets = false;
protected $wrap_brackets = false;
/**
* Default email method (mail or smtp)
*
* @access private
* @var string
*/
private $mail_method = 'mail';
protected $mail_method = 'mail';
/**
* Dump email to flat file for testing
*
* @access private
* @var integer
*/
private $temp_dump = 0;
protected $temp_dump = 0;
/**
* Path for email dumps
*
* @access private
* @var string
*/
private $temp_dump_path = '';
protected $temp_dump_path = '';
/**
* Error message
*
* @access public
* @var string
*/
public $error_msg = '';
@@ -383,7 +359,6 @@ class classEmail implements interfaceEmail
/**
* Error description
*
* @access public
* @var string
*/
public $error_help = '';
@@ -391,7 +366,6 @@ class classEmail implements interfaceEmail
/**
* Error flag
*
* @access public
* @var boolean
*/
public $error = false;
@@ -399,27 +373,26 @@ class classEmail implements interfaceEmail
/**
* Constructor
*
* @access public
* @param array Initiate class parameters
* @return void
* @return @e void
*/
public function __construct( $opts=array() )
{
$this->mail_method = ( $opts['method'] AND in_array( strtolower($opts['method']), array( 'smtp', 'mail' ) ) ) ? strtolower($opts['method']) : 'mail';
$this->temp_dump = ( isset($opts['debug']) AND $opts['debug'] ) ? 1 : 0;
$this->temp_dump_path = ( isset($opts['debug_path']) AND $opts['debug_path'] ) ? $opts['debug_path'] : '';
$this->html_email = ( isset($opts['html']) AND $opts['html'] ) ? 1 : 0;
$this->char_set = ( isset($opts['charset']) AND $opts['charset'] ) ? $opts['charset'] : 'utf-8';
$this->temp_dump = !empty($opts['debug']) ? 1 : 0;
$this->temp_dump_path = !empty($opts['debug_path']) ? $opts['debug_path'] : '';
$this->html_email = !empty($opts['html']) ? 1 : 0;
$this->char_set = !empty($opts['charset']) ? $opts['charset'] : 'utf-8';
$this->smtp_host = ( isset($opts['smtp_host']) AND $opts['smtp_host'] ) ? $opts['smtp_host'] : '';
$this->smtp_port = ( isset($opts['smtp_port']) AND $opts['smtp_port'] ) ? intval($opts['smtp_port']) : 25;
$this->smtp_user = ( isset($opts['smtp_user']) AND $opts['smtp_user'] ) ? $opts['smtp_user'] : '';
$this->smtp_pass = ( isset($opts['smtp_pass']) AND $opts['smtp_pass'] ) ? $opts['smtp_pass'] : '';
$this->smtp_helo = ( isset($opts['smtp_helo']) AND $opts['smtp_helo'] ) ? $opts['smtp_helo'] : 'HELO';
$this->wrap_brackets = ( isset($opts['wrap_brackets']) AND $opts['wrap_brackets'] ) ? true : false;
$this->extra_opts = ( isset($opts['extra_opts']) AND $opts['extra_opts'] ) ? $opts['extra_opts'] : '';
$this->smtp_host = !empty($opts['smtp_host']) ? $opts['smtp_host'] : '';
$this->smtp_port = !empty($opts['smtp_port']) ? intval($opts['smtp_port']) : 25;
$this->smtp_user = !empty($opts['smtp_user']) ? $opts['smtp_user'] : '';
$this->smtp_pass = !empty($opts['smtp_pass']) ? $opts['smtp_pass'] : '';
$this->smtp_helo = !empty($opts['smtp_helo']) ? $opts['smtp_helo'] : 'HELO';
$this->wrap_brackets = !empty($opts['wrap_brackets']) ? true : false;
$this->extra_opts = !empty($opts['extra_opts']) ? $opts['extra_opts'] : '';
if( $this->mail_method == 'smtp' )
if ( $this->mail_method == 'smtp' && ! $this->temp_dump )
{
$this->_smtpConnect();
}
@@ -428,8 +401,7 @@ class classEmail implements interfaceEmail
/**
* Destructor
*
* @access public
* @return void
* @return @e void
*/
public function __destruct()
{
@@ -439,19 +411,46 @@ class classEmail implements interfaceEmail
}
}
/**
* Sets the HTML version of the email
* @param string $content
*/
public function setHtmlContent( $content )
{
$this->message = $content;
}
/**
* Sets plain text version of the email
* @param string $content
*/
public function setPlainTextContent( $content )
{
$this->pt_message = $content;
}
/**
* Sets whether or not this is a HTML email
* @param boolean duh $boolean
*/
public function setHtmlEmail( $boolean=null )
{
$this->html_email = ( $boolean ) ? true : false;
}
/**
* Clear stored data to prepare a new email. Useful
* to prevent having to close/reopen SMTP connection
* repeatedly.
*
* @access public
* @return void
* @return @e void
*/
public function clearEmail()
{
$this->from = '';
$this->from_display = '';
$this->to = '';
$this->cc = array();
$this->bcc = array();
$this->subject = '';
$this->message = '';
@@ -464,8 +463,7 @@ class classEmail implements interfaceEmail
/**
* Clear stored errors to prepare a new email.
*
* @access public
* @return void
* @return @e void
*/
public function clearError()
{
@@ -477,7 +475,6 @@ class classEmail implements interfaceEmail
/**
* Set the from email address
*
* @access public
* @param string From email address
* @param string [Optional] From display
* @return boolean
@@ -508,7 +505,6 @@ class classEmail implements interfaceEmail
/**
* Set a header manually
*
* @access public
* @param string Header key
* @param string Header value
* @return boolean
@@ -523,7 +519,6 @@ class classEmail implements interfaceEmail
/**
* Set the 'to' email address
*
* @access public
* @param string To email address
* @return boolean
*/
@@ -534,10 +529,22 @@ class classEmail implements interfaceEmail
return true;
}
/**
* Add cc's
*
* @param string To email address
* @return boolean
*/
public function addCC( $email )
{
$this->cc[] = $this->_cleanEmail( $email );
return true;
}
/**
* Add bcc's
*
* @access public
* @param string To email address
* @return boolean
*/
@@ -551,7 +558,6 @@ class classEmail implements interfaceEmail
/**
* Set the email subject
*
* @access public
* @param string Email subject
* @return boolean
*/
@@ -578,7 +584,6 @@ class classEmail implements interfaceEmail
/**
* Set the email body
*
* @access public
* @param string Email body
* @return boolean
*/
@@ -592,18 +597,17 @@ class classEmail implements interfaceEmail
/**
* Clean an email address
*
* @access private
* @param string Email address
* @return string Cleaned email address
*/
private function _cleanEmail( $email )
protected function _cleanEmail( $email )
{
$email = str_replace( ' ' , '', $email );
$email = str_replace( "\t" , '', $email );
$email = str_replace( "\r" , '', $email );
$email = str_replace( "\n" , '', $email );
$email = str_replace( ',,' , ',', $email );
$email = preg_replace( "#\#\[\]'\"\(\):;/\$!ᆪ%\^&\*\{\}#" , "", $email );
$email = preg_replace( '#\#\[\]\'"\(\):;/\$!ᆪ%\^&\*\{\}#' , "", $email );
return $email;
}
@@ -611,7 +615,6 @@ class classEmail implements interfaceEmail
/**
* Send the mail (All appropriate params must be set by this point)
*
* @access public
* @return boolean Mail sent successfully
*/
public function sendMail()
@@ -621,7 +624,7 @@ class classEmail implements interfaceEmail
//-----------------------------------------
$this->_buildHeaders();
//-----------------------------------------
// Verify params are all set
//-----------------------------------------
@@ -642,8 +645,8 @@ class classEmail implements interfaceEmail
if( !is_dir( $this->temp_dump_path ) )
{
@mkdir( $this->temp_dump_path );
@chmod( $this->temp_dump_path, 0777 );
@mkdir( $this->temp_dump_path, IPS_FOLDER_PERMISSION );
@chmod( $this->temp_dump_path, IPS_FOLDER_PERMISSION );
}
if( !is_dir( $this->temp_dump_path ) )
@@ -666,7 +669,16 @@ class classEmail implements interfaceEmail
if( $this->mail_method != 'smtp' )
{
if ( ! @mail( $this->to, $this->subject, $this->message, $this->rfc_headers, $this->extra_opts ) )
/* Fifth parameter not supported in safe mode
@link http://community.invisionpower.com/tracker/issue-30145-php-mail-and-safe-mode */
if( ( defined('SAFE_MODE_ON') AND SAFE_MODE_ON ) OR $this->settings['safe_mode_skins'] )
{
if ( ! @mail( $this->to, $this->subject, $this->message, $this->rfc_headers ) )
{
$this->_fatalError( "Could not send the email", "Failed at 'mail' command (SAFE MODE)" );
}
}
else if ( ! @mail( $this->to, $this->subject, $this->message, $this->rfc_headers, $this->extra_opts ) )
{
if ( ! @mail( $this->to, $this->subject, $this->message, $this->rfc_headers ) )
{
@@ -693,12 +705,11 @@ class classEmail implements interfaceEmail
/**
* Fatal error handler
*
* @access private
* @param string Error Message
* @param string Error Help / Description
* @return boolean
*/
private function _fatalError( $msg, $help="" )
protected function _fatalError( $msg, $help="" )
{
$this->error = true;
$this->error_msg = $msg;
@@ -715,10 +726,9 @@ class classEmail implements interfaceEmail
/**
* Build the multipart headers for the email
*
* @access private
* @return string Multipart headers
*/
private function _buildMultipart()
protected function _buildMultipart()
{
$multipart = '';
@@ -733,7 +743,6 @@ class classEmail implements interfaceEmail
/**
* ENCODE HEADERS - RFC2047
*
* @access private
* @param array Array of headers
* @return array Headers encoded per RFCs
* @see http://www.faqs.org/rfcs/rfc822.html
@@ -741,7 +750,7 @@ class classEmail implements interfaceEmail
* @see http://www.faqs.org/rfcs/rfc2047
* @see http://us2.php.net/manual/en/function.mail.php#27997
*/
private function _encodeHeaders( $headers = array() )
protected function _encodeHeaders( $headers = array() )
{
$enc_headers = count($headers) ? $headers : $this->mail_headers;
@@ -832,13 +841,12 @@ class classEmail implements interfaceEmail
/**
* Build the email headers (MIME, Charset, From, BCC, To, Subject, etc)
*
* @access private
* @return void
* @return @e void
*/
private function _buildHeaders()
protected function _buildHeaders()
{
$extra_headers = array();
$extra_header_rfc = "";
$extra_headers_rfc = "";
//-----------------------------------------
// HTML (hitmuhl)
@@ -847,15 +855,18 @@ class classEmail implements interfaceEmail
// it for non HTML browsers
//-----------------------------------------
$this->pt_message = $this->message;
$this->pt_message = str_replace( "<br />", "\n", $this->pt_message );
$this->pt_message = str_replace( "<br>" , "\n", $this->pt_message );
$this->pt_message = strip_tags( $this->pt_message );
if ( ! $this->pt_message )
{
$this->pt_message = $this->message;
$this->pt_message = str_replace( "<br />", "\n", $this->pt_message );
$this->pt_message = str_replace( "<br>" , "\n", $this->pt_message );
$this->pt_message = strip_tags( $this->pt_message );
$this->pt_message = html_entity_decode( $this->pt_message, ENT_QUOTES );
$this->pt_message = str_replace( '&#092;', '\\', $this->pt_message );
$this->pt_message = str_replace( '&#036;', '$', $this->pt_message );
}
$this->pt_message = html_entity_decode( $this->pt_message, ENT_QUOTES );
$this->pt_message = str_replace( '&#092;', '\\', $this->pt_message );
$this->pt_message = str_replace( '&#036;', '$', $this->pt_message );
//-----------------------------------------
// Start mail headers
//-----------------------------------------
@@ -864,9 +875,18 @@ class classEmail implements interfaceEmail
$this->mail_headers['Date'] = date( "r" );
$this->mail_headers['Return-Path'] = $this->from;
$this->mail_headers['X-Priority'] = "3";
$this->mail_headers['X-MSMail-Priority'] = "Normal";
//$this->mail_headers['X-MSMail-Priority'] = "Normal";
$this->mail_headers['X-Mailer'] = "IPS PHP Mailer";
//-----------------------------------------
// Message-ID
//-----------------------------------------
if( $this->mail_method != 'smtp' )
{
$this->mail_headers['Message-ID'] = "<" . md5(microtime(true)) . "@" . $_SERVER['HTTP_HOST'] . ">";
}
//-----------------------------------------
// From and to...
// @link http://community.invisionpower.com/tracker/issue-22474-mail-delivery-method-character/
@@ -880,9 +900,13 @@ class classEmail implements interfaceEmail
{
$this->mail_headers['From'] = '<' . $this->from . '>';
}
if ( $this->mail_method != 'smtp' )
{
if( count( $this->cc ) > 0 )
{
$this->mail_headers['Cc'] = implode( "," , $this->cc );
}
if( count( $this->bcc ) > 0 )
{
$this->mail_headers['Bcc'] = implode( "," , $this->bcc );
@@ -896,6 +920,11 @@ class classEmail implements interfaceEmail
}
$this->mail_headers['Subject'] = $this->subject;
if( count( $this->cc ) > 0 )
{
$this->mail_headers['Cc'] = implode( "," , $this->cc );
}
}
//-----------------------------------------
@@ -1011,10 +1040,9 @@ class classEmail implements interfaceEmail
/**
* SMTP connect
*
* @access private
* @return boolean Connection successful
*/
private function _smtpConnect()
protected function _smtpConnect()
{
$this->smtp_fp = @fsockopen( $this->smtp_host, intval($this->smtp_port), $errno, $errstr, 30 );
@@ -1087,10 +1115,9 @@ class classEmail implements interfaceEmail
/**
* SMTP disconnect
*
* @access private
* @return boolean Disconnect successful
*/
private function _smtpDisconnect()
protected function _smtpDisconnect()
{
$this->_smtpSendCmd( "quit" );
@@ -1106,10 +1133,9 @@ class classEmail implements interfaceEmail
/**
* SMTP: Get next line
*
* @access private
* @return void
* @return @e void
*/
private function _smtpGetLine()
protected function _smtpGetLine()
{
$this->smtp_msg = "";
@@ -1127,11 +1153,10 @@ class classEmail implements interfaceEmail
/**
* SMTP: Send command
*
* @access private
* @param string SMTP command
* @return boolean Command successful
*/
private function _smtpSendCmd( $cmd )
protected function _smtpSendCmd( $cmd )
{
$this->smtp_msg = "";
$this->smtp_code = "";
@@ -1148,11 +1173,10 @@ class classEmail implements interfaceEmail
/**
* Encode data and make it safe for SMTP transport
*
* @access private
* @param string Raw Data
* @return string CRLF Encoded Data
*/
private function _smtpCrlfEncode( $data )
protected function _smtpCrlfEncode( $data )
{
$data .= "\n";
$data = str_replace( "\n", "\r\n", str_replace( "\r", "", $data ) );
@@ -1164,11 +1188,10 @@ class classEmail implements interfaceEmail
/**
* SMTP: Error handler
*
* @access private
* @param string SMTP error
* @return boolean
*/
private function _smtpError( $err="" )
protected function _smtpError( $err="" )
{
//$this->smtp_msg = $err;
$this->_fatalError( $err );
@@ -1178,10 +1201,9 @@ class classEmail implements interfaceEmail
/**
* SMTP: Sends the SMTP email
*
* @access private
* @return void
* @return @e void
*/
private function _smtpSendMail()
protected function _smtpSendMail()
{
$data = $this->_smtpCrlfEncode( $this->rfc_headers . "\n\n" . $this->message );
@@ -1277,11 +1299,10 @@ class classEmail implements interfaceEmail
/**
* Add an attachment to the current email
*
* @access public
* @param string File data
* @param string File name
* @param string File type (MIME)
* @return void
* @return @e void
*/
public function addAttachment( $data="", $name="", $ctype='application/octet-stream' )
{
@@ -1295,11 +1316,10 @@ class classEmail implements interfaceEmail
/**
* Encode an attachment
*
* @access private
* @param array Raw data [ctype,encode,name,data]
* @return string Processed data
*/
private function _encodeAttachment( $part=array() )
protected function _encodeAttachment( $part=array() )
{
$msg = chunk_split( base64_encode( $part['data'] ) );