include/phpmailer/class.phpmailer.php
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
- Children
- \SugarPHPMailer
Constants
Properties

string
$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.
''Details- Type
- string

string
$Body= ''''
Sets the Body of the message. This can be either an HTML or text body.
If HTML then run IsHTML(true).
''Details- Type
- string

string
$ConfirmReadingTo= ''''
Sets the email address that a reading confirmation will be sent.
''Details- Type
- string

string
$ContentType= ''text/plain''
Sets the Content-type of the message.
'text/plain'Details- Type
- string

string
$DKIM_domain= ''''
Used with DKIM DNS Resource Record optional, in format of email address 'you@yourdomain.com'
''Details- Type
- string

string
$DKIM_identity= ''''
Used with DKIM DNS Resource Record optional, in format of email address 'you@yourdomain.com'
''Details- Type
- string

string
$DKIM_private= ''''
Used with DKIM DNS Resource Record optional, in format of email address 'you@yourdomain.com'
''Details- Type
- string

string
$DKIM_selector= ''phpmailer''
Used with DKIM DNS Resource Record
'phpmailer'Details- Type
- string

string
$Encoding= ''8bit''
Sets the Encoding of the message. Options for this are "8bit", "7bit", "binary", "base64", and "quoted-printable".
'8bit'Details- Type
- string

string
$ErrorInfo= ''''
Holds the most recent mailer error message.
''Details- Type
- string

string
$From= ''root@localhost''
Sets the From email address for the message.
'root@localhost'Details- Type
- string

string
$FromName= ''Root User''
Sets the From name of the message.
'Root User'Details- Type
- string

string
$Helo= ''''
Sets the SMTP HELO of the message (Default is $Hostname).
''Details- Type
- string

string
$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.
'localhost'Details- Type
- string

string
$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'.
''Details- Type
- string

string
$LE= '"\n"'
Provides the ability to change the line ending
"\n"Details- Type
- string

string
$MIMEBody= ''''
Stores the complete compiled MIME message body.
''Details- Type
- string
- Access
- protected

string
$MIMEHeader= ''''
Stores the complete compiled MIME message headers.
''Details- Type
- string
- Access
- protected

string
$Mailer= ''mail''
Method to send mail: ("mail", "sendmail", or "smtp").
'mail'Details- Type
- string

string
$MessageID= ''''
Sets the message ID to be used in the Message-Id header.
If empty, a unique id will be generated.
''Details- Type
- string

string
$PluginDir= ''''
Path to PHPMailer plugins. Useful if the SMTP class is in a different directory than the PHP include path.
''Details- Type
- string

bool
$SMTPAuth= 'false'
Sets SMTP authentication. Utilizes the Username and Password variables.
falseDetails- Type
- bool

bool
$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().
falseDetails- Type
- bool

string
$SMTPSecure= ''''
Sets connection prefix.
Options are "", "ssl" or "tls"
''Details- Type
- string

string
$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.
''Details- Type
- string

string
$Sendmail= ''/usr/sbin/sendmail''
Sets the path of the sendmail program.
'/usr/sbin/sendmail'Details- Type
- string

string
$SentMIMEMessage= ''''
Stores the complete sent MIME message (Body and Headers)
''Details- Type
- string
- Access
- protected

bool
$SingleTo= 'false'
Provides the ability to have the TO field process individual emails, instead of sending to entire TO addresses
falseDetails- Type
- bool

bool
$SingleToArray= 'array()'
If SingleTo is true, this provides the array to hold the email addresses
array()Details- Type
- bool

int
$Timeout= '10'
Sets the SMTP server timeout in seconds.
This function will not work with the win32 version.
10Details- Type
- int

string
$Version= ''5.2.1''
Sets the PHPMailer Version number
'5.2.1'Details- Type
- string

int
$WordWrap= '0'
Sets word wrapping on the body of the message to a given number of characters.
0Details- Type
- int

string
$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
''Details- Type
- string
Methods

AddAddress(
string $address, string $name
=
''
)
:
booleanAdds a "To" address.
| Name | Type | Description |
|---|---|---|
| $address | string | |
| $name | string |
| Type | Description |
|---|---|
| boolean | true on success, false if address already used |

AddAnAddress(
string $kind, string $address, string $name
=
''
)
:
booleanAdds an address to one of the recipient arrays Addresses that have been added already return false, but do not throw exceptions
| Name | Type | Description |
|---|---|---|
| $kind | string | One of 'to', 'cc', 'bcc', 'ReplyTo' |
| $address | string | The email address to send to |
| $name | string |
| Type | Description |
|---|---|
| boolean | true on success, false if address already used or invalid in some way |
- Access
- protected

AddAttachment(
string $path, string $name
=
'', string $encoding
=
'base64', string $type
=
'application/octet-stream'
)
:
boolAdds an attachment from a path on the filesystem.
Returns false if the file could not be found or accessed.
| 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. |
| Type | Description |
|---|---|
| bool |

AddBCC(
string $address, string $name
=
''
)
:
booleanAdds a "Bcc" address.
Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
| Name | Type | Description |
|---|---|---|
| $address | string | |
| $name | string |
| Type | Description |
|---|---|
| boolean | true on success, false if address already used |

AddCC(
string $address, string $name
=
''
)
:
booleanAdds a "Cc" address.
Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
| Name | Type | Description |
|---|---|---|
| $address | string | |
| $name | string |
| Type | Description |
|---|---|
| boolean | true on success, false if address already used |

AddCustomHeader(
$custom_header
)
:
voidAdds a custom header.
| Name | Type | Description |
|---|---|---|
| $custom_header |
- Access
- public

AddEmbeddedImage(
string $path, string $cid, string $name
=
'', string $encoding
=
'base64', string $type
=
'application/octet-stream'
)
:
boolAdds 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".
| 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. |
| Type | Description |
|---|---|
| bool |

AddReplyTo(
string $address, string $name
=
''
)
:
booleanAdds a "Reply-to" address.
| Name | Type | Description |
|---|---|---|
| $address | string | |
| $name | string |
| Type | Description |
|---|---|
| boolean |

AddStringAttachment(
string $string, string $filename, string $encoding
=
'base64', string $type
=
'application/octet-stream'
)
:
voidAdds 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.
| 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. |

AddStringEmbeddedImage(
$string, $cid, $filename
=
'', $encoding
=
'base64', $type
=
'application/octet-stream'
)
:
void| Name | Type | Description |
|---|---|---|
| $string | ||
| $cid | ||
| $filename | ||
| $encoding | ||
| $type |

AddrAppend(
$type, $addr
)
:
stringCreates recipient headers.
| Name | Type | Description |
|---|---|---|
| $type | ||
| $addr |
| Type | Description |
|---|---|
| string |
- Access
- public

AddrFormat(
$addr
)
:
stringFormats an address correctly.
| Name | Type | Description |
|---|---|---|
| $addr |
| Type | Description |
|---|---|
| string |
- Access
- public

AttachAll(
$disposition_type, $boundary
)
:
stringAttaches all fs, string, and binary attachments to the message.
Returns an empty string on failure.
| Name | Type | Description |
|---|---|---|
| $disposition_type | ||
| $boundary |
| Type | Description |
|---|---|
| string |
- Access
- protected

Base64EncodeWrapMB(
string $str
)
:
stringCorrectly 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
| Name | Type | Description |
|---|---|---|
| $str | string | multi-byte text to wrap encode |
| Type | Description |
|---|---|
| string |
- Access
- public

ClearAllRecipients(
)
:
voidClears all recipients assigned in the TO, CC and BCC array. Returns void.

ClearAttachments(
)
:
voidClears all previously set filesystem, string, and binary attachments. Returns void.

CreateBody(
)
:
stringAssembles the message body. Returns an empty string on failure.
| Type | Description |
|---|---|
| string | The assembled message body |
- Access
- public

CreateHeader(
)
:
stringAssembles message header.
| Type | Description |
|---|---|
| string | The assembled header |
- Access
- public

DKIM_Add(
string $headers_line, string $subject, string $body
)
:
voidCreate the DKIM header, body, as new header
| Name | Type | Description |
|---|---|---|
| $headers_line | string | Header lines |
| $subject | string | Subject |
| $body | string | Body |
- Access
- public

DKIM_BodyC(
string $body
)
:
voidGenerate DKIM Canonicalization Body
| Name | Type | Description |
|---|---|---|
| $body | string | Message Body |
- Access
- public

DKIM_HeaderC(
string $s
)
:
voidGenerate DKIM Canonicalization Header
| Name | Type | Description |
|---|---|---|
| $s | string | Header |
- Access
- public

DKIM_QP(
$txt
)
:
voidSet the private key file and password to sign the message.
| Name | Type | Description |
|---|---|---|
| $txt |
- Access
- public

DKIM_Sign(
string $s
)
:
voidGenerate DKIM signature
| Name | Type | Description |
|---|---|---|
| $s | string | Header |
- Access
- public

EncodeFile(
string $path, string $encoding
=
'base64'
)
:
stringEncodes attachment in requested format.
Returns an empty string on failure.
| 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' |
| Type | Description |
|---|---|
| string |
- Access
- protected
- See
- \EncodeFile()

EncodeHeader(
$str, $position
=
'text'
)
:
stringEncode a header string to best (shortest) of Q, B, quoted or none.
| Name | Type | Description |
|---|---|---|
| $str | ||
| $position |
| Type | Description |
|---|---|
| string |
- Access
- public

EncodeQ(
string $str, string $position
=
'text'
)
:
stringEncode string to q encoding.
| 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 |
| Type | Description |
|---|---|
| string |
- Access
- public
- Link
- http://tools.ietf.org/html/rfc2047

EncodeQP(
string $string, integer $line_max
=
76, boolean $space_conv
=
false
)
:
stringEncode 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
| 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 |
| Type | Description |
|---|---|
| string |
- Access
- public
- Author
- Marcus Bointon
- See
- \EncodeQPphp()

EncodeQPphp(
$input
=
'', integer $line_max
=
76, $space_conv
=
false
)
:
stringEncode string to quoted-printable.
Only uses standard PHP, slow, but will always work
| Name | Type | Description |
|---|---|---|
| $input | ||
| $line_max | integer | Number of chars allowed on a line before wrapping |
| $space_conv |
| Type | Description |
|---|---|
| string |
- Access
- public

EncodeString(
string $str, string $encoding
=
'base64'
)
:
stringEncodes string to requested format.
Returns an empty string on failure.
| Name | Type | Description |
|---|---|---|
| $str | string | The text to encode |
| $encoding | string | The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' |
| Type | Description |
|---|---|
| string |
- Access
- public

EndBoundary(
$boundary
)
:
stringReturns the end of a message boundary.
| Name | Type | Description |
|---|---|---|
| $boundary |
| Type | Description |
|---|---|
| string |
- Access
- protected

FixEOL(
$str
)
:
stringChanges every end of line from CR or LF to CRLF.
| Name | Type | Description |
|---|---|---|
| $str |
| Type | Description |
|---|---|
| string |
- Access
- public

GetBoundary(
$boundary, $charSet, $contentType, $encoding
)
:
stringReturns the start of a message boundary.
| Name | Type | Description |
|---|---|---|
| $boundary | ||
| $charSet | ||
| $contentType | ||
| $encoding |
| Type | Description |
|---|---|
| string |
- Access
- protected

GetMailMIME(
)
:
stringReturns the message MIME.
| Type | Description |
|---|---|
| string |
- Access
- public

GetSentMIMEMessage(
)
:
stringReturns the MIME message (headers and body). Only really valid post PreSend().
| Type | Description |
|---|---|
| string |
- Access
- public

GetTranslations(
)
:
arrayReturn the current array of language strings
| Type | Description |
|---|---|
| array |

HasMultiBytes(
string $str
)
:
boolChecks if a string contains multibyte characters.
| Name | Type | Description |
|---|---|---|
| $str | string | multi-byte text to wrap encode |
| Type | Description |
|---|---|
| bool |
- Access
- public

HeaderLine(
$name, $value
)
:
stringReturns a formatted header line.
| Name | Type | Description |
|---|---|---|
| $name | ||
| $value |
| Type | Description |
|---|---|
| string |
- Access
- public

InlineImageExists(
)
:
boolReturns true if an inline attachment is present.
| Type | Description |
|---|---|
| bool |
- Access
- public

IsError(
)
:
boolReturns true if an error occurred.
| Type | Description |
|---|---|
| bool |
- Access
- public

IsHTML(
bool $ishtml
=
true
)
:
voidSets message type to HTML.
| Name | Type | Description |
|---|---|---|
| $ishtml | bool |

Lang(
$key
)
:
stringReturns a message in the appropriate language.
| Name | Type | Description |
|---|---|---|
| $key |
| Type | Description |
|---|---|
| string |
- Access
- protected

MailSend(
string $header, string $body
)
:
boolSends mail using the PHP mail() function.
| Name | Type | Description |
|---|---|---|
| $header | string | The message headers |
| $body | string | The message body |
| Type | Description |
|---|---|
| bool |
- Access
- protected

MsgHTML(
$message, $basedir
=
''
)
:
\$messageEvaluates the message and returns modifications for inline images and backgrounds
| Name | Type | Description |
|---|---|---|
| $message | ||
| $basedir |
| Type | Description |
|---|---|
| \$message |
- Access
- public

RFCDate(
)
:
stringReturns the proper RFC 822 formatted date.
| Type | Description |
|---|---|
| string |
- Access
- public
- Static

SecureHeader(
string $str
)
:
stringStrips newlines to prevent header injection.
| Name | Type | Description |
|---|---|---|
| $str | string | String |
| Type | Description |
|---|---|
| string |
- Access
- public

Send(
)
:
boolCreates 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.
| Type | Description |
|---|---|
| bool |

SendmailSend(
string $header, string $body
)
:
boolSends mail using the $Sendmail program.
| Name | Type | Description |
|---|---|---|
| $header | string | The message headers |
| $body | string | The message body |
| Type | Description |
|---|---|
| bool |
- Access
- protected

ServerHostname(
)
:
stringReturns the server hostname or 'localhost.localdomain' if unknown.
| Type | Description |
|---|---|
| string |
- Access
- protected

SetError(
$msg
)
:
voidAdds the error message to the error container.
| Name | Type | Description |
|---|---|---|
| $msg |
- Access
- protected

SetFrom(
string $address, string $name
=
'', $auto
=
1
)
:
booleanSet the From and FromName properties
| Name | Type | Description |
|---|---|---|
| $address | string | |
| $name | string | |
| $auto |
| Type | Description |
|---|---|
| boolean |

SetLanguage(
string $langcode
=
'en', string $lang_path
=
'language/'
)
:
voidSets the language for all class error messages.
Returns false if it cannot load the language file. The default language is English.
| 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 |
- Access
- public

Sign(
$cert_filename, string $key_filename, string $key_pass
)
:
voidSet the private key file and password to sign the message.
| Name | Type | Description |
|---|---|---|
| $cert_filename | ||
| $key_filename | string | Parameter File Name |
| $key_pass | string | Password for private key |
- Access
- public

SmtpConnect(
)
:
boolInitiates a connection to an SMTP server.
Returns false if the operation failed.
| Type | Description |
|---|---|
| bool |
- Access
- public
- Uses
- \SMTP

SmtpSend(
string $header, string $body
)
:
boolSends mail via SMTP using PhpSMTP Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
| Name | Type | Description |
|---|---|---|
| $header | string | The message headers |
| $body | string | The message body |
| Type | Description |
|---|---|
| bool |
- Access
- protected
- Uses
- \SMTP

TextLine(
$value
)
:
stringReturns a formatted mail line.
| Name | Type | Description |
|---|---|---|
| $value |
| Type | Description |
|---|---|
| string |
- Access
- public

UTF8CharBoundary(
string $encodedText, int $maxLength
)
:
intFinds last character boundary prior to maxLength in a utf-8 quoted (printable) encoded string.
Original written by Colin Brown.
| Name | Type | Description |
|---|---|---|
| $encodedText | string | utf-8 QP text |
| $maxLength | int | find last character boundary prior to this length |
| Type | Description |
|---|---|
| int |
- Access
- public

ValidateAddress(
string $address
)
:
booleanCheck 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
| Name | Type | Description |
|---|---|---|
| $address | string | The email address to check |
| Type | Description |
|---|---|
| boolean |
- Access
- public
- Link
- Original pattern found here
- Static

WrapText(
string $message, integer $length, boolean $qp_mode
=
false
)
:
stringWraps message for use with mailers that do not automatically perform wrapping and for quoted-printable.
Original written by philippe.
| 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 |
| Type | Description |
|---|---|
| string |
- Access
- public

__construct(
boolean $exceptions
=
false
)
:
voidConstructor
| Name | Type | Description |
|---|---|---|
| $exceptions | boolean | Should we throw external exceptions? |

_mime_types(
string $ext
=
''
)
:
stringGets the MIME type of the embedded or inline image
| Name | Type | Description |
|---|---|---|
| $ext | string | File extension |
| Type | Description |
|---|---|
| string | MIME type of ext |
- Access
- public
- Static

doCallback(
$isSent, $to, $cc, $bcc, $subject, $body
)
:
void| Name | Type | Description |
|---|---|---|
| $isSent | ||
| $to | ||
| $cc | ||
| $bcc | ||
| $subject | ||
| $body |

set(
string $name, mixed $value
=
''
)
:
voidSet (or reset) Class Objects (variables)
Usage Example: $page->set('X-Priority', '3');
| Name | Type | Description |
|---|---|---|
| $name | string | Parameter Name |
| $value | mixed | Parameter Value NOTE: will not work with arrays, there are no arrays to set/reset |
- Access
- public
- Todo
- Should this not be using __set() magic function?