Inheritances
Files
Overview
FRAMES
NO FRAMES

Class PHPMailer

PHPMailer
|- class PHPMailer
PHPMailer - PHP email transport class
PackagePHPMailer
AuthorAndy Prevost
Copyright2004 - 2009 Andy Prevost

Summary

Instance fields
+ $AltBody Sets the text-only body of the message
+ $Body Sets the Body of the message
+ $CharSet Sets the CharSet of the message
+ $ConfirmReadingTo Sets the email address that a reading confirmation will be sent
+ $ContentType Sets the Content-type of the message
+ $CustomHeader
+ $Encoding Sets the Encoding of the message
+ $ErrorInfo Holds the most recent mailer error message
+ $From Sets the From email address for the message
+ $FromName Sets the From name of the message
+ $Helo Sets the SMTP HELO of the message (Default is $Hostname)
+ $Host Sets the SMTP hosts
+ $Hostname Sets the hostname to use in Message-Id and Received headers
+ $LE
+ $Mailer Method to send mail: ("mail", "sendmail", or "smtp")
+ $MessageID Sets the message ID to be used in the Message-Id header.
+ $Password Sets SMTP password
+ $PluginDir Path to PHPMailer plugins
+ $Port Sets the default SMTP server port
+ $Priority Email priority (1 = High, 3 = Normal, 5 = low)
+ $ReplyTo
+ $SMTPAuth Sets SMTP authentication
+ $SMTPDebug Sets SMTP class debugging on or off
+ $SMTPKeepAlive Prevents the SMTP connection from being closed after each mail
+ $SMTPSecure Sets connection prefix.
+ $Sender Sets the Sender email (Return-Path) of the message
+ $Sendmail Sets the path of the sendmail program
+ $SingleTo Provides the ability to have the TO field process individual
+ $Subject Sets the Subject of the message
+ $Timeout Sets the SMTP server timeout in seconds
+ $Username Sets SMTP username
+ $Version Holds PHPMailer version
+ $WordWrap Sets word wrapping on the body of the message to a given number of
+ $attachment
+ $bcc
+ $boundary
+ $cc
+ $error_count
+ $language
+ $message_type
+ $sign_cert_file
+ $sign_key_file
+ $sign_key_pass
+ $smtp
+ $to
Instance methods
+ AddAddress() Adds a "To" address
+ AddAttachment() Adds an attachment from a path on the filesystem.
+ AddBCC() Adds a "Bcc" address
+ AddCC() Adds a "Cc" address
+ AddCustomHeader() Adds a custom header
+ AddEmbeddedImage() Adds an embedded attachment
+ AddReplyTo() Adds a "Reply-To" address
+ AddStringAttachment() Adds a string or binary attachment (non-filesystem) to the list.
+ AddrAppend() Creates recipient headers
+ AddrFormat() Formats an address correctly
+ AttachAll() Attaches all fs, string, and binary attachments to the message.
+ Base64EncodeWrapMB() Correctly encodes and wraps long multibyte strings for mail headers
+ ClearAddresses() Clears all recipients assigned in the TO array
+ ClearAllRecipients() Clears all recipients assigned in the TO, CC and BCC
+ ClearAttachments() Clears all previously set filesystem, string, and binary
+ ClearBCCs() Clears all recipients assigned in the BCC array
+ ClearCCs() Clears all recipients assigned in the CC array
+ ClearCustomHeaders() Clears all custom headers
+ ClearReplyTos() Clears all recipients assigned in the ReplyTo array
+ CreateBody() Assembles the message body
+ CreateHeader() Assembles message header
+ EncodeFile() Encodes attachment in requested format
+ EncodeHeader() Encode a header string to best of Q, B, quoted or none
+ EncodeQ() Encode string to q encoding
+ EncodeQP() Encode string to quoted-printable
+ EncodeQ_callback() Callback for converting to "=XX"
+ EncodeString() Encodes string to requested format
+ EndBoundary() Returns the end of a message boundary
+ FixEOL() Changes every end of line from CR or LF to CRLF
+ GetBoundary() Returns the start of a message boundary
+ GetMailMIME() Returns the message MIME
+ HasMultiBytes() Checks if a string contains multibyte characters
+ HeaderLine()
+ InlineImageExists() Returns true if an inline attachment is present
+ IsError() Returns true if an error occurred
+ IsHTML() Sets message type to HTML
+ IsMail() Sets Mailer to send message using PHP mail() function
+ IsQmail() Sets Mailer to send message using the qmail MTA
+ IsSMTP() Sets Mailer to send message using SMTP
+ IsSendmail() Sets Mailer to send message using the $Sendmail program
+ Lang() Returns a message in the appropriate language
+ MailSend() Sends mail using the PHP mail() function
+ MsgHTML() Evaluates the message and returns modifications for inline images and backgrounds
+ RFCDate() Returns the proper RFC 822 formatted date
+ SecureHeader() Strips newlines to prevent header injection
+ Send() Creates message and assigns Mailer
+ SendmailSend() Sends mail using the $Sendmail program
+ ServerHostname() Returns the server hostname or 'localhost.localdomain' if unknown
+ ServerVar() Returns the appropriate server variable
+ SetError() Adds the error message to the error container.
+ SetLanguage() Sets the language for all class error messages
+ SetMessageType() Sets the message type
+ SetWordWrap() Set the body wrapping
+ Sign() Set the private key file and password to sign the message
+ SmtpClose() Closes the active SMTP session if one exists
+ SmtpConnect() Initiates a connection to an SMTP server
+ SmtpSend() Sends mail via SMTP using PhpSMTP (Author:
+ TextLine() Returns a formatted mail line
+ UTF8CharBoundary() Finds last character boundary prior to maxLength in a utf-8
+ WrapText() Wraps message for use with mailers that do not
+ _mime_types() Gets the mime type of the embedded or inline image
+ getFile() Read a file from a supplied filename and return it
+ set() Set (or reset) Class Objects (variables)

Details

Instance fields

$AltBody
var $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.
Var string
$Body
var $Body = ''
Sets the Body of the message. This can be either an HTML or text body.
If HTML then run IsHTML(true).
Var string
$CharSet
var $CharSet = 'iso-8859-1'
Sets the CharSet of the message.
Var string
$ConfirmReadingTo
var $ConfirmReadingTo = ''
Sets the email address that a reading confirmation will be sent.
Var string
$ContentType
var $ContentType = 'text/plain'
Sets the Content-type of the message.
Var string
$CustomHeader
var $CustomHeader = array()
$Encoding
var $Encoding = '8bit'
Sets the Encoding of the message. Options for this are "8bit",
"7bit", "binary", "base64", and "quoted-printable".
Var string
$ErrorInfo
var $ErrorInfo = ''
Holds the most recent mailer error message.
Var string
$From
var $From = 'root@localhost'
Sets the From email address for the message.
Var string
$FromName
var $FromName = 'Root User'
Sets the From name of the message.
Var string
$Helo
var $Helo = ''
Sets the SMTP HELO of the message (Default is $Hostname).
Var string
$Host
var $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.
Var string
$Hostname
var $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'.
Var string
$Mailer
var $Mailer = 'mail'
Method to send mail: ("mail", "sendmail", or "smtp").
Var string
$MessageID
var $MessageID = ''
Sets the message ID to be used in the Message-Id header.
If empty, a unique id will be generated.
Var string
$Password
var $Password = ''
Sets SMTP password.
Var string
$PluginDir
var $PluginDir = ''
Path to PHPMailer plugins. This is now only useful if the SMTP class
is in a different directory than the PHP include path.
Var string
$Port
var $Port = 25
Sets the default SMTP server port.
Var int
$Priority
var $Priority = 3
Email priority (1 = High, 3 = Normal, 5 = low).
Var int
$ReplyTo
var $ReplyTo = array()
$SMTPAuth
var $SMTPAuth = false
Sets SMTP authentication. Utilizes the Username and Password variables.
Var bool
$SMTPDebug
var $SMTPDebug = false
Sets SMTP class debugging on or off.
Var bool
$SMTPKeepAlive
var $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().
Var bool
$SMTPSecure
var $SMTPSecure = ""
Sets connection prefix.
Options are "", "ssl" or "tls"
Var string
$Sender
var $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.
Var string
$Sendmail
var $Sendmail = '/usr/sbin/sendmail'
Sets the path of the sendmail program.
Var string
$SingleTo
var $SingleTo = false
Provides the ability to have the TO field process individual
emails, instead of sending to entire TO addresses
Var bool
$Subject
var $Subject = ''
Sets the Subject of the message.
Var string
$Timeout
var $Timeout = 10
Sets the SMTP server timeout in seconds. This function will not
work with the win32 version.
Var int
$Username
var $Username = ''
Sets SMTP username.
Var string
$Version
var $Version = "2.0.4"
Holds PHPMailer version.
Var string
$WordWrap
var $WordWrap = 0
Sets word wrapping on the body of the message to a given number of
characters.
Var int
$attachment
var $attachment = array()
$bcc
var $bcc = array()
$boundary
var $boundary = array()
$cc
var $cc = array()
$language
var $language = array()
$sign_cert_file
var $sign_cert_file = ""
$to
var $to = array()

Instance methods

AddAddress()
function AddAddress( $address
$name = ''
)
Adds a "To" address.
Parameters
string $address
string $name
Returns void
AddAttachment()
function AddAttachment( $path
$name = ''
$encoding = 'base64'
$type = 'application/octet-stream'
)
Adds an attachment from a path on the filesystem.
Returns false if the file could not be found
or accessed.
Parameters
string $path Path to the attachment.
string $name Overrides the attachment name.
string $encoding File encoding (see $Encoding).
string $type File extension (MIME) type.
Returns bool
AddBCC()
function AddBCC( $address
$name = ''
)
Adds a "Bcc" address. Note: this function works
with the SMTP mailer on win32, not with the "mail"
mailer.
Parameters
string $address
string $name
Returns void
AddCC()
function AddCC( $address
$name = ''
)
Adds a "Cc" address. Note: this function works
with the SMTP mailer on win32, not with the "mail"
mailer.
Parameters
string $address
string $name
Returns void
AddCustomHeader()
function AddCustomHeader( $custom_header)
Adds a custom header.
Parameters
$custom_header
Returns void
AddEmbeddedImage()
function AddEmbeddedImage( $path
$cid
$name = ''
$encoding = 'base64'
$type = 'application/octet-stream'
)
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
string $path Path to the attachment.
string $cid Content ID of the attachment. Use this to identify
the Id for accessing the image in an HTML form.
string $name Overrides the attachment name.
string $encoding File encoding (see $Encoding).
string $type File extension (MIME) type.
Returns bool
AddReplyTo()
function AddReplyTo( $address
$name = ''
)
Adds a "Reply-To" address.
Parameters
string $address
string $name
Returns void
AddStringAttachment()
function AddStringAttachment( $string
$filename
$encoding = 'base64'
$type = 'application/octet-stream'
)
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
string $string String attachment data.
string $filename Name of the attachment.
string $encoding File encoding (see $Encoding).
string $type File extension (MIME) type.
Returns void
AddrAppend()
function AddrAppend( $type
$addr
)
Creates recipient headers.
Parameters
$type
$addr
Returns string
Access private
AddrFormat()
function AddrFormat( $addr)
Formats an address correctly.
Parameters
$addr
Returns string
Access private
AttachAll()
function AttachAll( )
Attaches all fs, string, and binary attachments to the message.
Returns an empty string on failure.
Returns string
Access private
Base64EncodeWrapMB()
function Base64EncodeWrapMB( $str)
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
string $str multi-byte text to wrap encode
Returns string
Access private
ClearAddresses()
function ClearAddresses( )
Clears all recipients assigned in the TO array. Returns void.
Returns void
ClearAllRecipients()
function ClearAllRecipients( )
Clears all recipients assigned in the TO, CC and BCC
array. Returns void.
Returns void
ClearAttachments()
function ClearAttachments( )
Clears all previously set filesystem, string, and binary
attachments. Returns void.
Returns void
ClearBCCs()
function ClearBCCs( )
Clears all recipients assigned in the BCC array. Returns void.
Returns void
ClearCCs()
function ClearCCs( )
Clears all recipients assigned in the CC array. Returns void.
Returns void
ClearCustomHeaders()
function ClearCustomHeaders( )
Clears all custom headers. Returns void.
Returns void
ClearReplyTos()
function ClearReplyTos( )
Clears all recipients assigned in the ReplyTo array. Returns void.
Returns void
CreateBody()
function CreateBody( )
Assembles the message body. Returns an empty string on failure.
Returns string
Access private
CreateHeader()
function CreateHeader( )
Assembles message header.
Returns string
Access private
EncodeFile()
function EncodeFile( $path
$encoding = 'base64'
)
Encodes attachment in requested format. Returns an
empty string on failure.
Parameters
$path
$encoding
Returns string
Access private
EncodeHeader()
function EncodeHeader( $str
$position = 'text'
)
Encode a header string to best of Q, B, quoted or none.
Parameters
$str
$position
Returns string
Access private
EncodeQ()
function EncodeQ( $str
$position = 'text'
)
Encode string to q encoding.
Parameters
$str
$position
Returns string
Access private
EncodeQP()
function EncodeQP( $input = ''
$line_max = 76
$space_conv = false
)
Encode string to quoted-printable.
Parameters
$input
$line_max
$space_conv
Returns string
Access private
EncodeQ_callback()
function EncodeQ_callback( $matches)
Callback for converting to "=XX".
Parameters
$matches
Returns string
Access private
EncodeString()
function EncodeString( $str
$encoding = 'base64'
)
Encodes string to requested format. Returns an
empty string on failure.
Parameters
$str
$encoding
Returns string
Access private
EndBoundary()
function EndBoundary( $boundary)
Returns the end of a message boundary.
Parameters
$boundary
Access private
FixEOL()
function FixEOL( $str)
Changes every end of line from CR or LF to CRLF.
Parameters
$str
Returns string
Access private
GetBoundary()
function GetBoundary( $boundary
$charSet
$contentType
$encoding
)
Returns the start of a message boundary.
Parameters
$boundary
$charSet
$contentType
$encoding
Access private
GetMailMIME()
function GetMailMIME( )
Returns the message MIME.
Returns string
Access private
HasMultiBytes()
function HasMultiBytes( $str)
Checks if a string contains multibyte characters.
Parameters
string $str multi-byte text to wrap encode
Returns bool
Access private
HeaderLine()
function HeaderLine( $name
$value
)
Parameters
$name
$value
InlineImageExists()
function InlineImageExists( )
Returns true if an inline attachment is present.
Returns bool
Access private
IsError()
function IsError( )
Returns true if an error occurred.
Returns bool
IsHTML()
function IsHTML( $bool)
Sets message type to HTML.
Parameters
bool $bool
Returns void
IsMail()
function IsMail( )
Sets Mailer to send message using PHP mail() function.
Returns void
IsQmail()
function IsQmail( )
Sets Mailer to send message using the qmail MTA.
Returns void
IsSMTP()
function IsSMTP( )
Sets Mailer to send message using SMTP.
Returns void
IsSendmail()
function IsSendmail( )
Sets Mailer to send message using the $Sendmail program.
Returns void
Lang()
function Lang( $key)
Returns a message in the appropriate language.
Parameters
$key
Returns string
Access private
MailSend()
function MailSend( $header
$body
)
Sends mail using the PHP mail() function.
Parameters
$header
$body
Returns bool
Access private
MsgHTML()
function MsgHTML( $message
$basedir = ''
)
Evaluates the message and returns modifications for inline images and backgrounds
Parameters
$message
$basedir
Returns $message
Access public
RFCDate()
function RFCDate( )
Returns the proper RFC 822 formatted date.
Returns string
Access private
SecureHeader()
function SecureHeader( $str)
Strips newlines to prevent header injection.
Parameters
string $str String
Returns string
Access private
Send()
function Send( )
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 bool
SendmailSend()
function SendmailSend( $header
$body
)
Sends mail using the $Sendmail program.
Parameters
$header
$body
Returns bool
Access private
ServerHostname()
function ServerHostname( )
Returns the server hostname or 'localhost.localdomain' if unknown.
Returns string
Access private
ServerVar()
function ServerVar( $varName)
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.
Parameters
$varName
Returns mixed
Access private
SetError()
function SetError( $msg)
Adds the error message to the error container.
Returns void.
Parameters
$msg
Returns void
Access private
SetLanguage()
function SetLanguage( $lang_type
$lang_path = 'language/'
)
Sets the language for all class error messages. Returns false
if it cannot load the language file. The default language type
is English.
Parameters
string $lang_type Type of language (e.g. Portuguese: "br")
string $lang_path Path to the language file directory
Returns bool
Access public
SetMessageType()
function SetMessageType( )
Sets the message type.
Returns void
Access private
SetWordWrap()
function SetWordWrap( )
Set the body wrapping.
Returns void
Access private
Sign()
function Sign( $cert_filename
$key_filename
$key_pass
)
Set the private key file and password to sign the message.
Parameters
$cert_filename
string $key_filename Parameter File Name
string $key_pass Password for private key
Access public
SmtpClose()
function SmtpClose( )
Closes the active SMTP session if one exists.
Returns void
SmtpConnect()
function SmtpConnect( )
Initiates a connection to an SMTP server. Returns false if the
operation failed.
Returns bool
Access private
SmtpSend()
function SmtpSend( $header
$body
)
Sends mail via SMTP using PhpSMTP (Author:
Chris Ryan). Returns bool. Returns false if there is a
bad MAIL FROM, RCPT, or DATA input.
Parameters
$header
$body
Returns bool
Access private
TextLine()
function TextLine( $value)
Returns a formatted mail line.
Parameters
$value
Returns string
Access private
UTF8CharBoundary()
function UTF8CharBoundary( $encodedText
$maxLength
)
Finds last character boundary prior to maxLength in a utf-8
quoted (printable) encoded string.
Original written by Colin Brown.
Parameters
string $encodedText utf-8 QP text
int $maxLength find last character boundary prior to this length
Returns int
Access private
WrapText()
function WrapText( $message
$length
$qp_mode = false
)
Wraps message for use with mailers that do not
automatically perform wrapping and for quoted-printable.
Original written by philippe.
Parameters
$message
$length
$qp_mode
Returns string
Access private
_mime_types()
function _mime_types( $ext = '')
Gets the mime type of the embedded or inline image
Parameters
$ext
Returns mime type of ext
Access private
getFile()
function getFile( $filename)
Read a file from a supplied filename and return it.
Parameters
string $filename Parameter File Name
Access public
set()
function set( $name
$value = ''
)
Set (or reset) Class Objects (variables)

Usage Example:
$page->set('X-Priority', '3');
Parameters
string $name Parameter Name
mixed $value Parameter Value
NOTE: will not work with arrays, there are no arrays to set/reset
Access public