include/phpmailer/class.phpmailer.php

Show: inherited
Table of Contents

PHPMailer - PHP email transport class NOTE: Requires PHP version 5 or later

Author
Andy Prevost  
Author
Marcus Bointon  
Author
Jim Jagielski  
Copyright
2010 - 2012 Jim Jagielski  
Copyright
2004 - 2009 Andy Prevost  
License
GNU Lesser General Public License  
Package
PHPMailer  

\PHPMailer

Package:
Children
\SugarPHPMailer

Constants

Constant  STOP_MESSAGE = 0
Constant  STOP_CONTINUE = 1
Constant  STOP_CRITICAL = 2

Properties

Propertypublicstring  $AltBody= ''''

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.

Default value''Details
Type
string
Propertypublicstring  $Body= ''''

Sets the Body of the message. This can be either an HTML or text body.

If HTML then run IsHTML(true).

Default value''Details
Type
string
Propertypublicstring  $CharSet= ''utf-8''

Sets the CharSet of the message.

Default value'utf-8'Details
Type
string
Propertypublicstring  $ConfirmReadingTo= ''''

Sets the email address that a reading confirmation will be sent.

Default value''Details
Type
string
Propertypublicstring  $ContentType= ''text/plain''

Sets the Content-type of the message.

Default value'text/plain'Details
Type
string
Propertyprotected  $CustomHeader= 'array()'
Default valuearray()Details
Type
n/a
Propertypublicstring  $DKIM_domain= ''''

Used with DKIM DNS Resource Record optional, in format of email address 'you@yourdomain.com'

Default value''Details
Type
string
Propertypublicstring  $DKIM_identity= ''''

Used with DKIM DNS Resource Record optional, in format of email address 'you@yourdomain.com'

Default value''Details
Type
string
Propertypublicstring  $DKIM_passphrase= ''''

Used with DKIM DNS Resource Record

Default value''Details
Type
string
Propertypublicstring  $DKIM_private= ''''

Used with DKIM DNS Resource Record optional, in format of email address 'you@yourdomain.com'

Default value''Details
Type
string
Propertypublicstring  $DKIM_selector= ''phpmailer''

Used with DKIM DNS Resource Record

Default value'phpmailer'Details
Type
string
Propertypublicstring  $Encoding= ''8bit''

Sets the Encoding of the message. Options for this are "8bit", "7bit", "binary", "base64", and "quoted-printable".

Default value'8bit'Details
Type
string
Propertypublicstring  $ErrorInfo= ''''

Holds the most recent mailer error message.

Default value''Details
Type
string
Propertypublicstring  $From= ''root@localhost''

Sets the From email address for the message.

Default value'root@localhost'Details
Type
string
Propertypublicstring  $FromName= ''Root User''

Sets the From name of the message.

Default value'Root User'Details
Type
string
Propertypublicstring  $Helo= ''''

Sets the SMTP HELO of the message (Default is $Hostname).

Default value''Details
Type
string
Propertypublicstring  $Host= ''localhost''

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.

Default value'localhost'Details
Type
string
Propertypublicstring  $Hostname= ''''

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'.

Default value''Details
Type
string
Propertypublicstring  $LE= '"\n"'

Provides the ability to change the line ending

Default value"\n"Details
Type
string
Propertyprotectedstring  $MIMEBody= ''''

Stores the complete compiled MIME message body.

Default value''Details
Type
string
Access
protected  
Propertyprotectedstring  $MIMEHeader= ''''

Stores the complete compiled MIME message headers.

Default value''Details
Type
string
Access
protected  
Propertypublicstring  $Mailer= ''mail''

Method to send mail: ("mail", "sendmail", or "smtp").

Default value'mail'Details
Type
string
Propertypublicstring  $MessageID= ''''

Sets the message ID to be used in the Message-Id header.

If empty, a unique id will be generated.

Default value''Details
Type
string
Propertypublicstring  $Password= ''''

Sets SMTP password.

Default value''Details
Type
string
Propertypublicstring  $PluginDir= ''''

Path to PHPMailer plugins. Useful if the SMTP class is in a different directory than the PHP include path.

Default value''Details
Type
string
Propertypublicint  $Port= '25'

Sets the default SMTP server port.

Default value25Details
Type
int
Propertypublicint  $Priority= '3'

Email priority (1 = High, 3 = Normal, 5 = low).

Default value3Details
Type
int
Propertyprotected  $ReplyTo= 'array()'
Default valuearray()Details
Type
n/a
Propertypublicbool  $SMTPAuth= 'false'

Sets SMTP authentication. Utilizes the Username and Password variables.

Default valuefalseDetails
Type
bool
Propertypublicbool  $SMTPDebug= 'false'

Sets SMTP class debugging on or off.

Default valuefalseDetails
Type
bool
Propertypublicbool  $SMTPKeepAlive= '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().

Default valuefalseDetails
Type
bool
Propertypublicstring  $SMTPSecure= ''''

Sets connection prefix.

Options are "", "ssl" or "tls"

Default value''Details
Type
string
Propertypublicstring  $Sender= ''''

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.

Default value''Details
Type
string
Propertypublicstring  $Sendmail= ''/usr/sbin/sendmail''

Sets the path of the sendmail program.

Default value'/usr/sbin/sendmail'Details
Type
string
Propertyprotectedstring  $SentMIMEMessage= ''''

Stores the complete sent MIME message (Body and Headers)

Default value''Details
Type
string
Access
protected  
Propertypublicbool  $SingleTo= 'false'

Provides the ability to have the TO field process individual emails, instead of sending to entire TO addresses

Default valuefalseDetails
Type
bool
Propertypublicbool  $SingleToArray= 'array()'

If SingleTo is true, this provides the array to hold the email addresses

Default valuearray()Details
Type
bool
Propertypublicstring  $Subject= ''''

Sets the Subject of the message.

Default value''Details
Type
string
Propertypublicint  $Timeout= '10'

Sets the SMTP server timeout in seconds.

This function will not work with the win32 version.

Default value10Details
Type
int
Propertypublicstring  $Username= ''''

Sets SMTP username.

Default value''Details
Type
string
Propertypublicstring  $Version= ''5.2.1''

Sets the PHPMailer Version number

Default value'5.2.1'Details
Type
string
Propertypublicint  $WordWrap= '0'

Sets word wrapping on the body of the message to a given number of characters.

Default value0Details
Type
int
Propertypublicstring  $XMailer= ''''

What to use in the X-Mailer header

Default value''Details
Type
string
Propertypublicstring  $action_function= ''''

Callback Action function name the function that handles the result of the send email action. Parameters: bool $result result of the send action string $to email address of the recipient string $cc cc email addresses string $bcc bcc email addresses string $subject the subject string $body the email body

Default value''Details
Type
string
Propertyprotected  $all_recipients= 'array()'
Default valuearray()Details
Type
n/a
Propertyprotected  $attachment= 'array()'
Default valuearray()Details
Type
n/a
Propertyprotected  $bcc= 'array()'
Default valuearray()Details
Type
n/a
Propertyprotected  $boundary= 'array()'
Default valuearray()Details
Type
n/a
Propertyprotected  $cc= 'array()'
Default valuearray()Details
Type
n/a
Propertyprotected  $error_count= '0'
Default value0Details
Type
n/a
Propertyprotected  $exceptions= 'false'
Default valuefalseDetails
Type
n/a
Propertyprotected  $language= 'array()'
Default valuearray()Details
Type
n/a
Propertyprotected  $message_type= ''''
Default value''Details
Type
n/a
Propertyprotected  $sign_cert_file= ''''
Default value''Details
Type
n/a
Propertyprotected  $sign_key_file= ''''
Default value''Details
Type
n/a
Propertyprotected  $sign_key_pass= ''''
Default value''Details
Type
n/a
Propertyprotected  $smtp= 'NULL'
Default valueNULLDetails
Type
n/a
Propertyprotected  $to= 'array()'
Default valuearray()Details
Type
n/a

Methods

methodpublicAddAddress( string $address, string $name = '' ) : boolean

Adds a "To" address.

Parameters
Name Type Description
$address string
$name string
Returns
Type Description
boolean true on success, false if address already used
methodprotectedAddAnAddress( string $kind, string $address, string $name = '' ) : boolean

Adds an address to one of the recipient arrays Addresses that have been added already return false, but do not throw exceptions

Parameters
Name Type Description
$kind string

One of 'to', 'cc', 'bcc', 'ReplyTo'

$address string

The email address to send to

$name string
Returns
Type Description
boolean true on success, false if address already used or invalid in some way
Details
Access
protected  
methodpublicAddAttachment( string $path, string $name = '', string $encoding = 'base64', string $type = 'application/octet-stream' ) : bool

Adds an attachment from a path on the filesystem.

Returns false if the file could not be found or accessed.

Parameters
Name Type Description
$path string

Path to the attachment.

$name string

Overrides the attachment name.

$encoding string

File encoding (see $Encoding).

$type string

File extension (MIME) type.

Returns
Type Description
bool
methodpublicAddBCC( string $address, string $name = '' ) : boolean

Adds a "Bcc" address.

Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.

Parameters
Name Type Description
$address string
$name string
Returns
Type Description
boolean true on success, false if address already used
methodpublicAddCC( string $address, string $name = '' ) : boolean

Adds a "Cc" address.

Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.

Parameters
Name Type Description
$address string
$name string
Returns
Type Description
boolean true on success, false if address already used
methodpublicAddCustomHeader(  $custom_header ) : void

Adds a custom header.

Parameters
Name Type Description
$custom_header
Details
Access
public  
methodpublicAddEmbeddedImage( string $path, string $cid, string $name = '', string $encoding = 'base64', string $type = 'application/octet-stream' ) : bool

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".

Parameters
Name Type Description
$path string

Path to the attachment.

$cid string

Content ID of the attachment. Use this to identify the Id for accessing the image in an HTML form.

$name string

Overrides the attachment name.

$encoding string

File encoding (see $Encoding).

$type string

File extension (MIME) type.

Returns
Type Description
bool
methodpublicAddReplyTo( string $address, string $name = '' ) : boolean

Adds a "Reply-to" address.

Parameters
Name Type Description
$address string
$name string
Returns
Type Description
boolean
methodpublicAddStringAttachment( string $string, string $filename, string $encoding = 'base64', string $type = 'application/octet-stream' ) : void

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.

Parameters
Name Type Description
$string string

String attachment data.

$filename string

Name of the attachment.

$encoding string

File encoding (see $Encoding).

$type string

File extension (MIME) type.

methodpublicAddStringEmbeddedImage(  $string,  $cid,  $filename = '',  $encoding = 'base64',  $type = 'application/octet-stream' ) : void

Parameters
Name Type Description
$string
$cid
$filename
$encoding
$type
methodpublicAddrAppend(  $type,  $addr ) : string

Creates recipient headers.

Parameters
Name Type Description
$type
$addr
Returns
Type Description
string
Details
Access
public  
methodpublicAddrFormat(  $addr ) : string

Formats an address correctly.

Parameters
Name Type Description
$addr
Returns
Type Description
string
Details
Access
public  
methodpublicAlternativeExists( ) : void

methodprotectedAttachAll(  $disposition_type,  $boundary ) : string

Attaches all fs, string, and binary attachments to the message.

Returns an empty string on failure.

Parameters
Name Type Description
$disposition_type
$boundary
Returns
Type Description
string
Details
Access
protected  
methodpublicAttachmentExists( ) : void

methodpublicBase64EncodeWrapMB( string $str ) : string

Correctly encodes and wraps long multibyte strings for mail headers without breaking lines within a character.

Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php

Parameters
Name Type Description
$str string

multi-byte text to wrap encode

Returns
Type Description
string
Details
Access
public  
methodpublicClearAddresses( ) : void

Clears all recipients assigned in the TO array. Returns void.

methodpublicClearAllRecipients( ) : void

Clears all recipients assigned in the TO, CC and BCC array. Returns void.

methodpublicClearAttachments( ) : void

Clears all previously set filesystem, string, and binary attachments. Returns void.

methodpublicClearBCCs( ) : void

Clears all recipients assigned in the BCC array. Returns void.

methodpublicClearCCs( ) : void

Clears all recipients assigned in the CC array. Returns void.

methodpublicClearCustomHeaders( ) : void

Clears all custom headers. Returns void.

methodpublicClearReplyTos( ) : void

Clears all recipients assigned in the ReplyTo array. Returns void.

methodpublicCreateBody( ) : string

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

Returns
Type Description
string The assembled message body
Details
Access
public  
methodpublicCreateHeader( ) : string

Assembles message header.

Returns
Type Description
string The assembled header
Details
Access
public  
methodpublicDKIM_Add( string $headers_line, string $subject, string $body ) : void

Create the DKIM header, body, as new header

Parameters
Name Type Description
$headers_line string

Header lines

$subject string

Subject

$body string

Body

Details
Access
public  
methodpublicDKIM_BodyC( string $body ) : void

Generate DKIM Canonicalization Body

Parameters
Name Type Description
$body string

Message Body

Details
Access
public  
methodpublicDKIM_HeaderC( string $s ) : void

Generate DKIM Canonicalization Header

Parameters
Name Type Description
$s string

Header

Details
Access
public  
methodpublicDKIM_QP(  $txt ) : void

Set the private key file and password to sign the message.

Parameters
Name Type Description
$txt
Details
Access
public  
methodpublicDKIM_Sign( string $s ) : void

Generate DKIM signature

Parameters
Name Type Description
$s string

Header

Details
Access
public  
methodprotectedEncodeFile( string $path, string $encoding = 'base64' ) : string

Encodes attachment in requested format.

Returns an empty string on failure.

Parameters
Name Type Description
$path string

The full path to the file

$encoding string

The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'

Returns
Type Description
string
Details
Access
protected  
See
\EncodeFile()  
methodpublicEncodeHeader(  $str,  $position = 'text' ) : string

Encode a header string to best (shortest) of Q, B, quoted or none.

Parameters
Name Type Description
$str
$position
Returns
Type Description
string
Details
Access
public  
methodpublicEncodeQ( string $str, string $position = 'text' ) : string

Encode string to q encoding.

Parameters
Name Type Description
$str string

the text to encode

$position string

Where the text is going to be used, see the RFC for what that means

Returns
Type Description
string
Details
Access
public  
Link
http://tools.ietf.org/html/rfc2047  
methodpublicEncodeQP( string $string, integer $line_max = 76, boolean $space_conv = false ) : string

Encode string to RFC2045 (6.7) quoted-printable format Uses a PHP5 stream filter to do the encoding about 64x faster than the old version Also results in same content as you started with after decoding

Parameters
Name Type Description
$string string

the text to encode

$line_max integer

Number of chars allowed on a line before wrapping

$space_conv boolean

Dummy param for compatibility with existing EncodeQP function

Returns
Type Description
string
Details
Access
public  
Author
Marcus Bointon  
See
\EncodeQPphp()  
methodpublicEncodeQPphp(  $input = '', integer $line_max = 76,  $space_conv = false ) : string

Encode string to quoted-printable.

Only uses standard PHP, slow, but will always work

Parameters
Name Type Description
$input
$line_max integer

Number of chars allowed on a line before wrapping

$space_conv
Returns
Type Description
string
Details
Access
public  
methodpublicEncodeString( string $str, string $encoding = 'base64' ) : string

Encodes string to requested format.

Returns an empty string on failure.

Parameters
Name Type Description
$str string

The text to encode

$encoding string

The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'

Returns
Type Description
string
Details
Access
public  
methodprotectedEndBoundary(  $boundary ) : string

Returns the end of a message boundary.

Parameters
Name Type Description
$boundary
Returns
Type Description
string
Details
Access
protected  
methodpublicFixEOL(  $str ) : string

Changes every end of line from CR or LF to CRLF.

Parameters
Name Type Description
$str
Returns
Type Description
string
Details
Access
public  
methodpublicGetAttachments( ) : array

Return the current array of attachments

Returns
Type Description
array
methodprotectedGetBoundary(  $boundary,  $charSet,  $contentType,  $encoding ) : string

Returns the start of a message boundary.

Parameters
Name Type Description
$boundary
$charSet
$contentType
$encoding
Returns
Type Description
string
Details
Access
protected  
methodpublicGetMailMIME( ) : string

Returns the message MIME.

Returns
Type Description
string
Details
Access
public  
methodpublicGetSentMIMEMessage( ) : string

Returns the MIME message (headers and body). Only really valid post PreSend().

Returns
Type Description
string
Details
Access
public  
methodpublicGetTranslations( ) : array

Return the current array of language strings

Returns
Type Description
array
methodpublicHasMultiBytes( string $str ) : bool

Checks if a string contains multibyte characters.

Parameters
Name Type Description
$str string

multi-byte text to wrap encode

Returns
Type Description
bool
Details
Access
public  
methodpublicHeaderLine(  $name,  $value ) : string

Returns a formatted header line.

Parameters
Name Type Description
$name
$value
Returns
Type Description
string
Details
Access
public  
methodpublicInlineImageExists( ) : bool

Returns true if an inline attachment is present.

Returns
Type Description
bool
Details
Access
public  
methodpublicIsError( ) : bool

Returns true if an error occurred.

Returns
Type Description
bool
Details
Access
public  
methodpublicIsHTML( bool $ishtml = true ) : void

Sets message type to HTML.

Parameters
Name Type Description
$ishtml bool
methodpublicIsMail( ) : void

Sets Mailer to send message using PHP mail() function.

methodpublicIsQmail( ) : void

Sets Mailer to send message using the qmail MTA.

methodpublicIsSMTP( ) : void

Sets Mailer to send message using SMTP.

methodpublicIsSendmail( ) : void

Sets Mailer to send message using the $Sendmail program.

methodprotectedLang(  $key ) : string

Returns a message in the appropriate language.

Parameters
Name Type Description
$key
Returns
Type Description
string
Details
Access
protected  
methodprotectedMailSend( string $header, string $body ) : bool

Sends mail using the PHP mail() function.

Parameters
Name Type Description
$header string

The message headers

$body string

The message body

Returns
Type Description
bool
Details
Access
protected  
methodpublicMsgHTML(  $message,  $basedir = '' ) : \$message

Evaluates the message and returns modifications for inline images and backgrounds

Parameters
Name Type Description
$message
$basedir
Returns
Type Description
\$message
Details
Access
public  
methodprotectedPostSend( ) : void

methodprotectedPreSend( ) : void

methodpublicRFCDate( ) : string
static

Returns the proper RFC 822 formatted date.

Returns
Type Description
string
Details
Access
public  
Static
 
methodpublicSecureHeader( string $str ) : string

Strips newlines to prevent header injection.

Parameters
Name Type Description
$str string

String

Returns
Type Description
string
Details
Access
public  
methodpublicSend( ) : bool

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.

Returns
Type Description
bool
methodprotectedSendmailSend( string $header, string $body ) : bool

Sends mail using the $Sendmail program.

Parameters
Name Type Description
$header string

The message headers

$body string

The message body

Returns
Type Description
bool
Details
Access
protected  
methodprotectedServerHostname( ) : string

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

Returns
Type Description
string
Details
Access
protected  
methodprotectedSetError(  $msg ) : void

Adds the error message to the error container.

Parameters
Name Type Description
$msg
Details
Access
protected  
methodpublicSetFrom( string $address, string $name = '',  $auto = 1 ) : boolean

Set the From and FromName properties

Parameters
Name Type Description
$address string
$name string
$auto
Returns
Type Description
boolean
methodpublicSetLanguage( string $langcode = 'en', string $lang_path = 'language/' ) : void

Sets the language for all class error messages.

Returns false if it cannot load the language file. The default language is English.

Parameters
Name Type Description
$langcode string

ISO 639-1 2-character language code (e.g. Portuguese: "br")

$lang_path string

Path to the language file directory

Details
Access
public  
methodprotectedSetMessageType( ) : void

Sets the message type.

Details
Access
protected  
methodpublicSetWordWrap( ) : void

Set the body wrapping.

Details
Access
public  
methodpublicSign(  $cert_filename, string $key_filename, string $key_pass ) : void

Set the private key file and password to sign the message.

Parameters
Name Type Description
$cert_filename
$key_filename string

Parameter File Name

$key_pass string

Password for private key

Details
Access
public  
methodpublicSmtpClose( ) : void

Closes the active SMTP session if one exists.

methodpublicSmtpConnect( ) : bool

Initiates a connection to an SMTP server.

Returns false if the operation failed.

Returns
Type Description
bool
Details
Access
public  
Uses
\SMTP  
methodprotectedSmtpSend( string $header, string $body ) : bool

Sends mail via SMTP using PhpSMTP Returns false if there is a bad MAIL FROM, RCPT, or DATA input.

Parameters
Name Type Description
$header string

The message headers

$body string

The message body

Returns
Type Description
bool
Details
Access
protected  
Uses
\SMTP  
methodpublicTextLine(  $value ) : string

Returns a formatted mail line.

Parameters
Name Type Description
$value
Returns
Type Description
string
Details
Access
public  
methodpublicUTF8CharBoundary( string $encodedText, int $maxLength ) : int

Finds last character boundary prior to maxLength in a utf-8 quoted (printable) encoded string.

Original written by Colin Brown.

Parameters
Name Type Description
$encodedText string

utf-8 QP text

$maxLength int

find last character boundary prior to this length

Returns
Type Description
int
Details
Access
public  
methodpublicValidateAddress( string $address ) : boolean
static

Check that a string looks roughly like an email address should Static so it can be used without instantiation Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator Conforms approximately to RFC2822

Parameters
Name Type Description
$address string

The email address to check

Returns
Type Description
boolean
Details
Access
public  
Link
Original pattern found here  
Static
 
methodpublicWrapText( string $message, integer $length, boolean $qp_mode = false ) : string

Wraps message for use with mailers that do not automatically perform wrapping and for quoted-printable.

Original written by philippe.

Parameters
Name Type Description
$message string

The message to wrap

$length integer

The line length to wrap to

$qp_mode boolean

Whether to run in Quoted-Printable mode

Returns
Type Description
string
Details
Access
public  
methodpublic__construct( boolean $exceptions = false ) : void

Constructor

Parameters
Name Type Description
$exceptions boolean

Should we throw external exceptions?

methodpublic_mime_types( string $ext = '' ) : string
static

Gets the MIME type of the embedded or inline image

Parameters
Name Type Description
$ext string

File extension

Returns
Type Description
string MIME type of ext
Details
Access
public  
Static
 
methodprotecteddoCallback(  $isSent,  $to,  $cc,  $bcc,  $subject,  $body ) : void

Parameters
Name Type Description
$isSent
$to
$cc
$bcc
$subject
$body
methodpublicset( string $name, mixed $value = '' ) : void

Set (or reset) Class Objects (variables)

Usage Example: $page->set('X-Priority', '3');

Parameters
Name Type Description
$name string

Parameter Name

$value mixed

Parameter Value NOTE: will not work with arrays, there are no arrays to set/reset

Details
Access
public  
Todo
Should this not be using __set() magic function?  

\phpmailerException

Package:
Parent(s)
\Exception

Methods

methodpublicerrorMessage( ) : void

Documentation was generated by DocBlox 0.18.1.