class DrupalPHPMailer in PHPMailer 5.2
Same name and namespace in other branches
- 5 includes/phpmailer.inc \DrupalPHPMailer
- 6.3 includes/phpmailer.class.inc \DrupalPHPMailer
- 6 includes/phpmailer.inc \DrupalPHPMailer
- 6.2 includes/phpmailer.class.inc \DrupalPHPMailer
- 7.4 includes/phpmailer.class.inc \DrupalPHPMailer
- 7.3 includes/phpmailer.class.inc \DrupalPHPMailer
Base PHPMailer for Drupal implementation with support for SMTP keep-alive and setting a custom Return-Path.
Hierarchy
- class \PHPMailer
- class \DrupalPHPMailer
Expanded class hierarchy of DrupalPHPMailer
File
- includes/
phpmailer.class.inc, line 14
View source
class DrupalPHPMailer extends PHPMailer {
/**
* Stores the Return-Path, which may be different from Sender.
*/
public $ReturnPath = '';
/**
* Constructor.
*/
public function __construct() {
// Throw exceptions instead of dying (since 5.0.0).
parent::__construct(TRUE);
$this
->IsSMTP();
$this
->Reset();
$this->Host = variable_get('smtp_host', '');
if ($backup = variable_get('smtp_hostbackup', '')) {
$this->Host .= ';' . $backup;
}
$this->Port = variable_get('smtp_port', '25');
$this->SMTPSecure = variable_get('smtp_protocol', '');
// Use SMTP authentication if both username and password are given.
$this->Username = variable_get('smtp_username', '');
$this->Password = variable_get('smtp_password', '');
$this->SMTPAuth = (bool) ($this->Username != '' && $this->Password != '');
$this->SMTPKeepAlive = variable_get('smtp_keepalive', 0);
$this->SMTPDebug = variable_get('smtp_debug', 0);
// Adjust path to SMTP class.
$this->PluginDir = drupal_get_path('module', 'phpmailer') . '/phpmailer/';
}
/**
* Send mail via SMTP.
*
* Wrapper around PHPMailer::SmtpSend() with exception handling.
*/
public function SmtpSend($header, $body) {
if ($this->SMTPDebug) {
ob_start();
}
try {
$result = parent::SmtpSend($header, $body);
} catch (phpmailerException $e) {
}
if ($this->SMTPDebug) {
if ($debug = ob_get_contents()) {
drupal_set_message($debug);
}
ob_end_clean();
}
// Reinitialize properties.
$this
->Reset();
if (isset($e)) {
// Pass exception to caller.
throw $e;
}
return $result;
}
/**
* (Re-)initialize properties after sending mail.
*/
public function Reset() {
$this
->ClearAllRecipients();
$this
->ClearReplyTos();
$this
->ClearAttachments();
$this
->ClearCustomHeaders();
$this->Priority = 3;
$this->CharSet = variable_get('smtp_charset', 'utf-8');
$this->ContentType = 'text/plain';
$this->Encoding = '8bit';
// Set default From name.
$from_name = variable_get('smtp_fromname', '');
if ($from_name == '') {
// Fall back on the site name.
$from_name = variable_get('site_name', 'Drupal');
}
$this->FromName = $from_name;
$this->Sender = '';
$this->MessageID = '';
$this->ReturnPath = '';
}
/**
* Destructor.
*/
public function __destruct() {
// Required when using SMTP keep-alive.
$this
->SmtpClose();
}
/**
* Provide more user-friendly error messages.
*
* Note: messages should not end with a dot.
*/
public function SetLanguage() {
$this->language = array(
'provide_address' => t('You must provide at least one recipient e-mail address'),
'encoding' => t('Unknown encoding: '),
'file_open' => t('Could not open file: '),
'signing' => t('Signing error: '),
'empty_message' => t('Message body empty'),
'tls' => t('SMTP error: STARTTLS not accepted from server'),
'authenticate' => t('SMTP error: could not authenticate'),
'smtp_connect_failed' => t('SMTP error: could not connect to SMTP host'),
'connect_host' => t('SMTP error: could not connect to SMTP host'),
'from_failed' => t('The following sender address failed: '),
// non-admin
'recipients_failed' => t('The following recipient addresses failed: '),
// non-admin
'data_not_accepted' => t('SMTP error: data not accepted'),
'smtp_error' => t('SMTP server error: '),
// Unused messages.
//'execute' => t('Could not execute: '),
//'instantiate' => t('Could not instantiate mail() function.'),
// Messages used during email generation.
'file_access' => t('Could not access file: '),
'invalid_address' => t('Invalid address'),
'variable_set' => t('Cannot set or reset variable: '),
);
return TRUE;
}
/**
* Assemble the message header.
*
* PHPMailer always sets Return-Path to Sender, we want more flexibility.
*/
public function CreateHeader() {
$old_sender = $this->Sender;
if ($this->ReturnPath != '') {
$this->Sender = $this->ReturnPath;
}
$result = parent::CreateHeader();
// Restore sender for use in MAIL FROM command.
$this->Sender = $old_sender;
return $result;
}
/**
* Public wrapper around PHPMailer::RFCDate().
*/
public static function RFCDate() {
$tz = date('Z');
$tzs = $tz < 0 ? '-' : '+';
$tz = abs($tz);
$tz = (int) ($tz / 3600) * 100 + $tz % 3600 / 60;
$result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
return $result;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalPHPMailer:: |
public | property | Stores the Return-Path, which may be different from Sender. | |
DrupalPHPMailer:: |
public | function |
Assemble the message header. Overrides PHPMailer:: |
|
DrupalPHPMailer:: |
public | function | (Re-)initialize properties after sending mail. | |
DrupalPHPMailer:: |
public static | function |
Public wrapper around PHPMailer::RFCDate(). Overrides PHPMailer:: |
|
DrupalPHPMailer:: |
public | function |
Provide more user-friendly error messages. Overrides PHPMailer:: |
|
DrupalPHPMailer:: |
public | function |
Send mail via SMTP. Overrides PHPMailer:: |
|
DrupalPHPMailer:: |
public | function | Constructor. | |
DrupalPHPMailer:: |
public | function | Destructor. | |
PHPMailer:: |
property | 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. | ||
PHPMailer:: |
property | |||
PHPMailer:: |
property | |||
PHPMailer:: |
property | Sets the Body of the message. This can be either an HTML or text body. If HTML then run IsHTML(true). | ||
PHPMailer:: |
property | |||
PHPMailer:: |
property | |||
PHPMailer:: |
property | Sets the CharSet of the message. | ||
PHPMailer:: |
property | Sets the email address that a reading confirmation will be sent. | ||
PHPMailer:: |
property | Sets the Content-type of the message. | ||
PHPMailer:: |
property | |||
PHPMailer:: |
property | Sets the Encoding of the message. Options for this are "8bit", "7bit", "binary", "base64", and "quoted-printable". | ||
PHPMailer:: |
property | Holds the most recent mailer error message. | ||
PHPMailer:: |
property | |||
PHPMailer:: |
property | Sets the From email address for the message. | ||
PHPMailer:: |
property | Sets the From name of the message. | ||
PHPMailer:: |
property | Sets the SMTP HELO of the message (Default is $Hostname). | ||
PHPMailer:: |
property | 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. | ||
PHPMailer:: |
property | 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'. | ||
PHPMailer:: |
property | |||
PHPMailer:: |
property | |||
PHPMailer:: |
property | Method to send mail: ("mail", "sendmail", or "smtp"). | ||
PHPMailer:: |
property | |||
PHPMailer:: |
property | Sets SMTP password. | ||
PHPMailer:: |
property | Path to PHPMailer plugins. This is now only useful if the SMTP class is in a different directory than the PHP include path. | ||
PHPMailer:: |
property | Sets the default SMTP server port. | ||
PHPMailer:: |
property | Email priority (1 = High, 3 = Normal, 5 = low). | ||
PHPMailer:: |
property | |||
PHPMailer:: |
property | |||
PHPMailer:: |
property | 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. | ||
PHPMailer:: |
property | Sets the path of the sendmail program. | ||
PHPMailer:: |
property | |||
PHPMailer:: |
property | Sets SMTP authentication. Utilizes the Username and Password variables. | ||
PHPMailer:: |
property | Sets SMTP class debugging on or off. | ||
PHPMailer:: |
property | 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(). | ||
PHPMailer:: |
property | Sets the Subject of the message. | ||
PHPMailer:: |
property | Sets the SMTP server timeout in seconds. This function will not work with the win32 version. | ||
PHPMailer:: |
property | |||
PHPMailer:: |
property | Sets SMTP username. | ||
PHPMailer:: |
property | Holds PHPMailer version. | ||
PHPMailer:: |
property | Sets word wrapping on the body of the message to a given number of characters. | ||
PHPMailer:: |
function | Adds a "To" address. | ||
PHPMailer:: |
function | Adds an attachment from a path on the filesystem. Returns false if the file could not be found or accessed. | ||
PHPMailer:: |
function | Adds a "Bcc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer. | ||
PHPMailer:: |
function | Adds a "Cc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer. | ||
PHPMailer:: |
function | Adds a custom header. | ||
PHPMailer:: |
function | Adds an embedded attachment. This can include images, sounds, and just about any other document. Make sure to set the $type to an image type. For JPEG images use "image/jpeg" and for GIF images use "image/gif". | ||
PHPMailer:: |
function | Creates recipient headers. @access private | ||
PHPMailer:: |
function | Adds a "Reply-to" address. | ||
PHPMailer:: |
function | Formats an address correctly. @access private | ||
PHPMailer:: |
function | Adds a string or binary attachment (non-filesystem) to the list. This method can be used to attach ascii or binary data, such as a BLOB record from a database. | ||
PHPMailer:: |
function | Attaches all fs, string, and binary attachments to the message. Returns an empty string on failure. @access private | ||
PHPMailer:: |
function | Clears all recipients assigned in the TO array. Returns void. | ||
PHPMailer:: |
function | Clears all recipients assigned in the TO, CC and BCC array. Returns void. | ||
PHPMailer:: |
function | Clears all previously set filesystem, string, and binary attachments. Returns void. | ||
PHPMailer:: |
function | Clears all recipients assigned in the BCC array. Returns void. | ||
PHPMailer:: |
function | Clears all recipients assigned in the CC array. Returns void. | ||
PHPMailer:: |
function | Clears all custom headers. Returns void. | ||
PHPMailer:: |
function | Clears all recipients assigned in the ReplyTo array. Returns void. | ||
PHPMailer:: |
function | Assembles the message body. Returns an empty string on failure. @access private | ||
PHPMailer:: |
function | Encodes attachment in requested format. Returns an empty string on failure. @access private | ||
PHPMailer:: |
function | Encode a header string to best of Q, B, quoted or none. @access private | ||
PHPMailer:: |
function | Encode string to q encoding. @access private | ||
PHPMailer:: |
function | Encode string to quoted-printable. @access private | ||
PHPMailer:: |
function | Encodes string to requested format. Returns an empty string on failure. @access private | ||
PHPMailer:: |
function | Returns the end of a message boundary. @access private | ||
PHPMailer:: |
function | Changes every end of line from CR or LF to CRLF. @access private | ||
PHPMailer:: |
function | Returns the start of a message boundary. @access private | ||
PHPMailer:: |
function | Returns a formatted header line. @access private | ||
PHPMailer:: |
function | Returns true if an inline attachment is present. @access private | ||
PHPMailer:: |
function | Returns true if an error occurred. | ||
PHPMailer:: |
function | Sets message type to HTML. | ||
PHPMailer:: |
function | Sets Mailer to send message using PHP mail() function. | ||
PHPMailer:: |
function | Sets Mailer to send message using the qmail MTA. | ||
PHPMailer:: |
function | Sets Mailer to send message using the $Sendmail program. | ||
PHPMailer:: |
function | Sets Mailer to send message using SMTP. | ||
PHPMailer:: |
function | Returns a message in the appropriate language. @access private | ||
PHPMailer:: |
function | Sends mail using the PHP mail() function. @access private | ||
PHPMailer:: |
function | 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. | ||
PHPMailer:: |
function | Sends mail using the $Sendmail program. @access private | ||
PHPMailer:: |
function | Returns the server hostname or 'localhost.localdomain' if unknown. @access private | ||
PHPMailer:: |
function | Returns the appropriate server variable. Should work with both PHP 4.1.0+ as well as older versions. Returns an empty string if nothing is found. @access private | ||
PHPMailer:: |
function | Adds the error message to the error container. Returns void. @access private | ||
PHPMailer:: |
function | Sets the message type. @access private | ||
PHPMailer:: |
function | Set the body wrapping. @access private | ||
PHPMailer:: |
function | Closes the active SMTP session if one exists. | ||
PHPMailer:: |
function | Initiates a connection to an SMTP server. Returns false if the operation failed. @access private | ||
PHPMailer:: |
function | Returns a formatted mail line. @access private | ||
PHPMailer:: |
function | Wraps message for use with mailers that do not automatically perform wrapping and for quoted-printable. Original written by philippe. @access private |