class-PHPMailer

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
Overview

Classes

Interfaces

Exceptions

Functions

Class PHPMailer

PHPMailer - PHP email creation and transport class.

Direct known subclasses

C_mailer, PHPMailerOAuth
Package: PHPMailer
Copyright: 2012 - 2014 Marcus Bointon
Copyright: 2010 - 2012 Jim Jagielski
Copyright: 2004 - 2009 Andy Prevost
License: GNU Lesser General Public License
Author: Marcus Bointon (Synchro/coolbru) phpmailer@synchromedia.co.uk
Author: Jim Jagielski (jimjag) jimjag@gmail.com
Author: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net
Author: Brent R. Matzelle (original founder)
Located at shared/phpmailer/class.phpmailer.php
Methods summary
public
# __construct( boolean $exceptions = null )

Constructor.

public
# __destruct( )

Destructor.

private boolean
# mailPassthru( string $to, string $subject, string $body, string $header, string $params )

Call mail() in a safe_mode-aware fashion. Also, unless sendmail_path points to sendmail (or something that claims to be sendmail), don't pass params (not a perfect fix, but it will do)

protected
# edebug( string $str )

Output debugging info via user-defined method. Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).

public
# isHTML( boolean $isHtml = true )

Sets message type to HTML or plain.

public
# isSMTP( )

Send messages using SMTP.

public
# isMail( )

Send messages using PHP's mail() function.

public
# isSendmail( )

Send messages using $Sendmail.

public
# isQmail( )

Send messages using qmail.

public boolean
# addAddress( string $address, string $name = '' )

Add a "To" address.

public boolean
# addCC( string $address, string $name = '' )

Add a "CC" address.

public boolean
# addBCC( string $address, string $name = '' )

Add a "BCC" address.

public boolean
# addReplyTo( string $address, string $name = '' )

Add a "Reply-To" address.

protected boolean
# addOrEnqueueAnAddress( string $kind, string $address, string $name )

Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still be modified after calling this function), addition of such addresses is delayed until send(). Addresses that have been added already return false, but do not throw exceptions.

protected boolean
# addAnAddress( string $kind, string $address, string $name = '' )

Add an address to one of the recipient arrays or to the ReplyTo array. Addresses that have been added already return false, but do not throw exceptions.

public array
# parseAddresses( string $addrstr, boolean $useimap = true )

Parse and validate a string containing one or more RFC822-style comma-separated email addresses of the form "display name

<

address>" into an array of name/address pairs. Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. Note that quotes in the name part are removed.

public boolean
# setFrom( string $address, string $name = '', boolean $auto = true )

Set the From and FromName properties.

public string
# getLastMessageID( )

Return the Message-ID header of the last email. Technically this is the value from the last time the headers were created, but it's also the message ID of the last sent message except in pathological cases.

public static boolean
# validateAddress( string $address, string|callable $patternselect = null )

Check that a string looks like an email address.

public boolean
# idnSupported( )

Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the "intl" and "mbstring" PHP extensions.

public string
# punyencodeAddress( string $address )

Converts IDN in given email address to its ASCII form, also known as punycode, if possible. Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet. This function silently returns unmodified address if: - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form) - Conversion to punycode is impossible (e.g. required PHP functions are not available) or fails for any reason (e.g. domain has characters not allowed in an IDN)

public boolean
# send( )

Create a message and send it. Uses the sending method specified by $Mailer.

public boolean
# preSend( )

Prepare a message for sending.

public boolean
# postSend( )

Actually send a message. Send the email via the selected mechanism

protected boolean
# sendmailSend( string $header, string $body )

Send mail using the $Sendmail program.

protected static boolean
# isShellSafe( string $string )

Fix CVE-2016-10033 and CVE-2016-10045 by disallowing potentially unsafe shell characters.

protected boolean
# mailSend( string $header, string $body )

Send mail using the PHP mail() function.

public SMTP
# getSMTPInstance( )

Get an instance to use for SMTP operations. Override this function to load your own SMTP implementation

protected boolean
# smtpSend( string $header, string $body )

Send mail via SMTP. Returns false if there is a bad MAIL FROM, RCPT, or DATA input. Uses the PHPMailerSMTP class by default.

public boolean
# smtpConnect( array $options = null )

Initiate a connection to an SMTP server. Returns false if the operation failed.

public
# smtpClose( )

Close the active SMTP session if one exists.

public boolean
# setLanguage( string $langcode = 'en', string $lang_path = '' )

Set the language for error messages. Returns false if it cannot load the language file. The default language is English.

public array
# getTranslations( )

Get the array of strings for the current language.

public string
# addrAppend( string $type, array $addr )

Create recipient headers.

public string
# addrFormat( array $addr )

Format an address for use in a message header.

public string
# wrapText( string $message, integer $length, boolean $qp_mode = false )

Word-wrap message. For use with mailers that do not automatically perform wrapping and for quoted-printable encoded messages. Original written by philippe.

public integer
# utf8CharBoundary( string $encodedText, integer $maxLength )

Find the last character boundary prior to $maxLength in a utf-8 quoted-printable encoded string. Original written by Colin Brown.

public
# setWordWrap( )

Apply word wrapping to the message body. Wraps the message body to the number of chars set in the WordWrap property. You should only do this to plain-text bodies as wrapping HTML tags may break them. This is called automatically by createBody(), so you don't need to call it yourself.

public string
# createHeader( )

Assemble message headers.

public string
# getMailMIME( )

Get the message MIME type headers.

public string
# getSentMIMEMessage( )

Returns the whole MIME message. Includes complete headers and body. Only valid post preSend().

protected string
# generateId( )

Create unique ID

public string
# createBody( )

Assemble the message body. Returns an empty string on failure.

protected string
# getBoundary( string $boundary, string $charSet, string $contentType, string $encoding )

Return the start of a message boundary.

protected string
# endBoundary( string $boundary )

Return the end of a message boundary.

protected
# setMessageType( )

Set the message type. PHPMailer only supports some preset message types, not arbitrary MIME structures.

public string
# headerLine( string $name, string $value )

Format a header line.

public string
# textLine( string $value )

Return a formatted mail line.

public boolean
# addAttachment( string $path, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'attachment' )

Add an attachment from a path on the filesystem. Never use a user-supplied path to a file! Returns false if the file could not be found or read.

public array
# getAttachments( )

Return the array of attachments.

protected string
# attachAll( string $disposition_type, string $boundary )

Attach all file, string, and binary attachments to the message. Returns an empty string on failure.

protected string
# encodeFile( string $path, string $encoding = 'base64' )

Encode a file attachment in requested format. Returns an empty string on failure.

public string
# encodeString( string $str, string $encoding = 'base64' )

Encode a string in requested format. Returns an empty string on failure.

public string
# encodeHeader( string $str, string $position = 'text' )

Encode a header string optimally. Picks shortest of Q, B, quoted-printable or none.

public boolean
# hasMultiBytes( string $str )

Check if a string contains multi-byte characters.

public boolean
# has8bitChars( string $text )

Does a string contain any 8-bit chars (in any charset)?

public string
# base64EncodeWrapMB( string $str, string $linebreak = null )

Encode and wrap long multibyte strings for mail headers without breaking lines within a character. Adapted from a function by paravoid

public string
# encodeQP( string $string, integer $line_max = 76 )

Encode a string in quoted-printable format. According to RFC2045 section 6.7.

public string
# encodeQPphp( string $string, integer $line_max = 76, boolean $space_conv = false )

Backward compatibility wrapper for an old QP encoding function that was removed.

public string
# encodeQ( string $str, string $position = 'text' )

Encode a string using Q encoding.

public
# addStringAttachment( string $string, string $filename, string $encoding = 'base64', string $type = '', string $disposition = 'attachment' )

Add a string or binary attachment (non-filesystem). This method can be used to attach ascii or binary data, such as a BLOB record from a database.

public boolean
# addEmbeddedImage( string $path, string $cid, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'inline' )

Add an embedded (inline) attachment from a file. This can include images, sounds, and just about any other document type. These differ from 'regular' attachments in that they are intended to be displayed inline with the message, not just attached for download. This is used in HTML messages that embed the images the HTML refers to using the $cid value. Never use a user-supplied path to a file!

public boolean
# addStringEmbeddedImage( string $string, string $cid, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'inline' )

Add an embedded stringified attachment. This can include images, sounds, and just about any other document type. Be sure to set the $type to an image type for images: JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'.

public boolean
# inlineImageExists( )

Check if an inline attachment is present.

public boolean
# attachmentExists( )

Check if an attachment (non-inline) is present.

public boolean
# alternativeExists( )

Check if this message has an alternative body set.

public
# clearQueuedAddresses( string $kind )

Clear queued addresses of given kind.

public
# clearAddresses( )

Clear all To recipients.

public
# clearCCs( )

Clear all CC recipients.

public
# clearBCCs( )

Clear all BCC recipients.

public
# clearReplyTos( )

Clear all ReplyTo recipients.

public
# clearAllRecipients( )

Clear all recipient types.

public
# clearAttachments( )

Clear all filesystem, string, and binary attachments.

public
# clearCustomHeaders( )

Clear all custom headers.

protected
# setError( string $msg )

Add an error message to the error container.

public static string
# rfcDate( )

Return an RFC 822 formatted date.

protected string
# serverHostname( )

Get the server hostname. Returns 'localhost.localdomain' if unknown.

protected string
# lang( string $key )

Get an error message in the current language.

public boolean
# isError( )

Check if an error occurred.

public string
# fixEOL( string $str )

Ensure consistent line endings in a string. Changes every end of line from CRLF, CR or LF to $this->LE.

public
# addCustomHeader( string $name, string $value = null )

Add a custom header. $name value can be overloaded to contain both header name and value (name:value)

public array
# getCustomHeaders( )

Returns all custom headers.

public string
# msgHTML( string $message, string $basedir = '', boolean|callable $advanced = false )

Create a message body from an HTML string. Automatically inlines images and creates a plain-text version by converting the HTML, overwriting any existing values in Body and AltBody. Do not source $message content from user input! $basedir is prepended when handling relative URLs, e.g. and must not be empty will look for an image file in $basedir/images/a.png and convert it to inline. If you don't provide a $basedir, relative paths will be left untouched (and thus probably break in email) If you don't want to apply these transformations to your HTML, just set Body and AltBody directly.

public string
# html2text( string $html, boolean|callable $advanced = false )

Convert an HTML string into plain text. This is used by msgHTML(). Note - older versions of this function used a bundled advanced converter which was been removed for license reasons in #232. Example usage:

// Use default conversion
$plain = $mail->html2text($html);
// Use your own custom converter
$plain = $mail->html2text($html, function($html) {
    $converter = new MyHtml2text($html);
    return $converter->get_text();
});
public static string
# _mime_types( string $ext = '' )

Get the MIME type for a file extension.

public static string
# filenameToType( string $filename )

Map a file name to a MIME type. Defaults to 'application/octet-stream', i.e.. arbitrary binary data.

public static string|array
# mb_pathinfo( string $path, integer|string $options = null )

Multi-byte-safe pathinfo replacement. Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe. Works similarly to the one in PHP >= 5.2.0

public boolean
# set( string $name, mixed $value = '' )

Set or reset instance properties. You should avoid this function - it's more verbose, less efficient, more error-prone and harder to debug than setting properties directly. Usage Example: $mail->set('SMTPSecure', 'tls'); is the same as: $mail->SMTPSecure = 'tls';

public string
# secureHeader( string $str )

Strip newlines to prevent header injection.

public static string
# normalizeBreaks( string $text, string $breaktype = "\r\n" )

Normalize line breaks in a string. Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format. Defaults to CRLF (for message bodies) and preserves consecutive breaks.

public
# sign( string $cert_filename, string $key_filename, string $key_pass, string $extracerts_filename = '' )

Set the public and private key files and password for S/MIME signing.

public string
# DKIM_QP( string $txt )

Quoted-Printable-encode a DKIM header.

public string
# DKIM_Sign( string $signHeader )

Generate a DKIM signature.

public string
# DKIM_HeaderC( string $signHeader )

Generate a DKIM canonicalization header.

public string
# DKIM_BodyC( string $body )

Generate a DKIM canonicalization body.

public string
# DKIM_Add( string $headers_line, string $subject, string $body )

Create the DKIM header and body in a new message header.

public static boolean
# hasLineLongerThanMax( string $str )

Detect if a string contains a line longer than the maximum line length allowed.

public array
# getToAddresses( )

Allows for public read access to 'to' property.

public array
# getCcAddresses( )

Allows for public read access to 'cc' property.

public array
# getBccAddresses( )

Allows for public read access to 'bcc' property.

public array
# getReplyToAddresses( )

Allows for public read access to 'ReplyTo' property.

public array
# getAllRecipientAddresses( )

Allows for public read access to 'all_recipients' property.

protected
# doCallback( boolean $isSent, array $to, array $cc, array $bcc, string $subject, string $body, string $from )

Perform a callback.

Constants summary
integer STOP_MESSAGE

Error severity: message only, continue processing.

# 0
integer STOP_CONTINUE

Error severity: message, likely ok to continue processing.

# 1
integer STOP_CRITICAL

Error severity: message, plus full stop, critical error reached.

# 2
string CRLF

SMTP RFC standard line ending.

# "\r\n"
integer MAX_LINE_LENGTH

The maximum line length allowed by RFC 2822 section 2.1.1

# 998
Properties summary
public string $Version

The PHPMailer Version number.

# '5.2.23'
public integer $Priority

Email priority. Options: null (default), 1 = High, 3 = Normal, 5 = low. When null, the header is not set at all.

# null
public string $CharSet

The character set of the message.

# 'iso-8859-1'
public string $ContentType

The MIME Content-type of the message.

# 'text/plain'
public string $Encoding

The message encoding. Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".

# '8bit'
public string $ErrorInfo

Holds the most recent mailer error message.

# ''
public string $From

The From email address for the message.

# 'root@localhost'
public string $FromName

The From name of the message.

# 'Root User'
public string $Sender

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.

# ''
public string $ReturnPath

The Return-Path of the message. If empty, it will be set to either From or Sender.

# ''
public string $Subject

The Subject of the message.

# ''
public string $Body

An HTML or plain text message body. If HTML then call isHTML(true).

# ''
public string $AltBody

The plain-text message body. This body can be read by mail clients that do not have HTML email capability such as mutt & Eudora. Clients that can read HTML will view the normal Body.

# ''
public string $Ical

An iCal message part body. Only supported in simple alt or alt_inline message types To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator

# ''
protected string $MIMEBody

The complete compiled MIME message body.

# ''
protected string $MIMEHeader

The complete compiled MIME message headers.

# ''
protected string $mailHeader

Extra headers that createHeader() doesn't fold in.

# ''
public integer $WordWrap

Word-wrap the message body to this number of chars. Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.

# 0
public string $Mailer

Which method to use to send mail. Options: "mail", "sendmail", or "smtp".

# 'mail'
public string $Sendmail

The path to the sendmail program.

# '/usr/sbin/sendmail'
public boolean $UseSendmailOptions

Whether mail() uses a fully sendmail-compatible MTA. One which supports sendmail's "-oi -f" options.

# true
public string $PluginDir

Path to PHPMailer plugins. Useful if the SMTP class is not in the PHP include path.

# ''
public string $ConfirmReadingTo

The email address that a reading confirmation should be sent to, also known as read receipt.

# ''
public string $Hostname

The hostname to use in the Message-ID header and as default HELO string. If empty, PHPMailer attempts to find one with, in order, $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value 'localhost.localdomain'.

# ''
public string $MessageID

An ID to be used in the Message-ID header. If empty, a unique id will be generated. You can set your own, but it must be in the format "<id@domain>", as defined in RFC5322 section 3.6.4 or it will be ignored.

# ''
public string $MessageDate

The message Date to be used in the Date header. If empty, the current date will be added.

# ''
public string $Host

SMTP hosts. Either a single hostname or multiple semicolon-delimited hostnames. 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"). You can also specify encryption type, for example: (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465"). Hosts will be tried in order.

# 'localhost'
public integer $Port

The default SMTP server port.

# 25
public string $Helo

The SMTP HELO of the message. Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find one with the same method described above for $Hostname.

# ''
public string $SMTPSecure

What kind of encryption to use on the SMTP connection. Options: '', 'ssl' or 'tls'

# ''
public boolean $SMTPAutoTLS

Whether to enable TLS encryption automatically if a server supports it, even if SMTPSecure is not set to 'tls'. Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.

# true
public boolean $SMTPAuth

Whether to use SMTP authentication. Uses the Username and Password properties.

# false
public array $SMTPOptions

Options array passed to stream_context_create when connecting via SMTP.

# array()
public string $Username

SMTP username.

# ''
public string $Password

SMTP password.

# ''
public string $AuthType

SMTP auth type. Options are CRAM-MD5, LOGIN, PLAIN, NTLM, XOAUTH2, attempted in that order if not specified

# ''
public string $Realm

SMTP realm. Used for NTLM auth

# ''
public string $Workstation

SMTP workstation. Used for NTLM auth

# ''
public integer $Timeout

The SMTP server timeout in seconds. Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2

# 300
public integer $SMTPDebug

SMTP class debug output mode. Debug output level. Options: * 0 No output * 1 Commands * 2 Data and commands * 3 As 2 plus connection status * 4 Low-level data output

# 0
public string|callable $Debugoutput

How to handle debug output. Options: * echo Output plain-text as-is, appropriate for CLI * html Output escaped, line breaks converted to <br>, appropriate for browser output * error_log Output to error log as configured in php.ini

# 'echo'
public boolean $SMTPKeepAlive

Whether to keep SMTP connection open after each message. If this is set to true then to close the connection requires an explicit call to smtpClose().

# false
public boolean $SingleTo

Whether to split multiple to addresses into multiple messages or send them all in one message. Only supported in mail and sendmail transports, not in SMTP.

# false
public array $SingleToArray

Storage for addresses when SingleTo is enabled.

# array()
public boolean $do_verp

Whether to generate VERP addresses on send. Only applicable when sending via SMTP.

# false
public boolean $AllowEmpty

Whether to allow sending messages with an empty body.

# false
public string $LE

The default line ending.

# "\n"
public string $DKIM_selector

DKIM selector.

# ''
public string $DKIM_identity

DKIM Identity. Usually the email address used as the source of the email.

# ''
public string $DKIM_passphrase

DKIM passphrase. Used if your key is encrypted.

# ''
public string $DKIM_domain

DKIM signing domain name.

# ''
public string $DKIM_private

DKIM private key file path.

# ''
public string $DKIM_private_string

DKIM private key string. If set, takes precedence over $DKIM_private.

# ''
public string $action_function

Callback Action function name.

# ''
public string $XMailer

What to put in the X-Mailer header. Options: An empty string for PHPMailer default, whitespace for none, or a string to use

# ''
public static string|callable $validator

Which validator to use by default when validating email addresses. May be a callable to inject your own validator, but there are several built-in validators.

# 'auto'
protected SMTP $smtp

An instance of the SMTP sender class.

# null
protected array $to

The array of 'to' names and addresses.

# array()
protected array $cc

The array of 'cc' names and addresses.

# array()
protected array $bcc

The array of 'bcc' names and addresses.

# array()
protected array $ReplyTo

The array of reply-to names and addresses.

# array()
protected array $all_recipients

An array of all kinds of addresses. Includes all of $to, $cc, $bcc

# array()
protected array $RecipientsQueue

An array of names and addresses queued for validation. In send(), valid and non duplicate entries are moved to $all_recipients and one of $to, $cc, or $bcc. This array is used only for addresses with IDN.

# array()
protected array $ReplyToQueue

An array of reply-to names and addresses queued for validation. In send(), valid and non duplicate entries are moved to $ReplyTo. This array is used only for addresses with IDN.

# array()
protected array $attachment

The array of attachments.

# array()
protected array $CustomHeader

The array of custom headers.

# array()
protected string $lastMessageID

The most recent Message-ID (including angular brackets).

# ''
protected string $message_type

The message's MIME type.

# ''
protected array $boundary

The array of MIME boundary strings.

# array()
protected array $language

The array of available languages.

# array()
protected integer $error_count

The number of errors encountered.

# 0
protected string $sign_cert_file

The S/MIME certificate file path.

# ''
protected string $sign_key_file

The S/MIME key file path.

# ''
protected string $sign_extracerts_file

The optional S/MIME extra certificates ("CA Chain") file path.

# ''
protected string $sign_key_pass

The S/MIME password for the key. Used only if the key is encrypted.

# ''
protected boolean $exceptions

Whether to throw exceptions for errors.

# false
protected string $uniqueid

Unique ID used for message ID and boundaries.

# ''
 

© 2004-2018 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy