class Mail extends PHPMailer

Email Class. Provides a common interface to send email from the Joomla! Platform

Properties

string $CharSet Charset of the message.

Methods

__construct( boolean $exceptions = true)

Constructor

static  Mail
getInstance( string $id = 'Joomla', boolean $exceptions = true)

Returns the global email object, only creating it if it doesn't already exist.

boolean|JException
Send()

Send the mail

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

Set the From and FromName properties.

Mail|boolean
setSender( mixed $from)

Set the email sender

setSubject( string $subject)

Set the email subject

setBody( string $content)

Set the email body

Mail|boolean
addRecipient( mixed $recipient, mixed $name = '')

Add recipients to the email

Mail|boolean
addCc( mixed $cc, mixed $name = '')

Add carbon copy recipients to the email

Mail|boolean
addBcc( mixed $bcc, mixed $name = '')

Add blind carbon copy recipients to the email

Mail|boolean
addAttachment( mixed $path, mixed $name = '', mixed $encoding = 'base64', mixed $type = 'application/octet-stream', string $disposition = 'attachment')

Add file attachment to the email

clearAttachments()

Unset all file attachments from the email

removeAttachment( integer $index)

Unset file attachments specified by array index.

Mail|boolean
addReplyTo( mixed $replyto, mixed $name = '')

Add Reply to email address(es) to the email

isHtml( boolean $ishtml = true)

Sets message type to HTML

void
isSendmail()

Send messages using $Sendmail.

boolean
useSendmail( string $sendmail = null)

Use sendmail for sending the email

boolean
useSmtp( string $auth = null, string $host = null, string $user = null, string $pass = null, string $secure = null, integer $port = 25)

Use SMTP for sending the email

boolean
sendMail( string $from, string $fromName, mixed $recipient, string $subject, string $body, boolean $mode = false, mixed $cc = null, mixed $bcc = null, mixed $attachment = null, mixed $replyTo = null, mixed $replyToName = null)

Function to send an email

boolean
sendAdminMail( string $adminName, string $adminEmail, string $email, string $type, string $title, string $author, string $url = null)

Sends mail to administrator for approval of a user submission

Details

__construct( boolean $exceptions = true)

Constructor

Parameters

boolean $exceptions Flag if Exceptions should be thrown

static Mail getInstance( string $id = 'Joomla', boolean $exceptions = true)

Returns the global email object, only creating it if it doesn't already exist.

NOTE: If you need an instance to use that does not have the global configuration values, use an id string that is not 'Joomla'.

Parameters

string $id The id string for the Mail instance [optional]
boolean $exceptions Flag if Exceptions should be thrown [optional]

Return Value

Mail The global Mail object

boolean|JException Send()

Send the mail

Return Value

boolean|JException Boolean true if successful, boolean false if the mailonline configuration is set to 0, or a JException object if the mail function does not exist or sending the message fails.

Exceptions

RuntimeException

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

Set the From and FromName properties.

Parameters

string $address The sender email address
string $name The sender name
boolean $auto Whether to also set the Sender address, defaults to true

Return Value

boolean

Mail|boolean setSender( mixed $from)

Set the email sender

Parameters

mixed $from email address and Name of sender array([0] => email Address, [1] => Name) or as a string

Return Value

Mail|boolean Returns this object for chaining on success or boolean false on failure.

Exceptions

UnexpectedValueException

Mail setSubject( string $subject)

Set the email subject

Parameters

string $subject Subject of the email

Return Value

Mail Returns this object for chaining.

Mail setBody( string $content)

Set the email body

Parameters

string $content Body of the email

Return Value

Mail Returns this object for chaining.

Mail|boolean addRecipient( mixed $recipient, mixed $name = '')

Add recipients to the email

Parameters

mixed $recipient Either a string or array of strings [email address(es)]
mixed $name Either a string or array of strings [name(s)]

Return Value

Mail|boolean Returns this object for chaining.

Mail|boolean addCc( mixed $cc, mixed $name = '')

Add carbon copy recipients to the email

Parameters

mixed $cc Either a string or array of strings [email address(es)]
mixed $name Either a string or array of strings [name(s)]

Return Value

Mail|boolean Returns this object for chaining on success or boolean false on failure.

Mail|boolean addBcc( mixed $bcc, mixed $name = '')

Add blind carbon copy recipients to the email

Parameters

mixed $bcc Either a string or array of strings [email address(es)]
mixed $name Either a string or array of strings [name(s)]

Return Value

Mail|boolean Returns this object for chaining on success or boolean false on failure.

Mail|boolean addAttachment( mixed $path, mixed $name = '', mixed $encoding = 'base64', mixed $type = 'application/octet-stream', string $disposition = 'attachment')

Add file attachment to the email

Parameters

mixed $path Either a string or array of strings [filenames]
mixed $name Either a string or array of strings [names]. N.B. if this is an array it must contain the same number of elements as the array of paths supplied.
mixed $encoding The encoding of the attachment
mixed $type The mime type
string $disposition The disposition of the attachment

Return Value

Mail|boolean Returns this object for chaining on success or boolean false on failure.

Exceptions

InvalidArgumentException

Mail clearAttachments()

Unset all file attachments from the email

Return Value

Mail Returns this object for chaining.

Mail removeAttachment( integer $index)

Unset file attachments specified by array index.

Parameters

integer $index The numerical index of the attachment to remove

Return Value

Mail Returns this object for chaining.

Mail|boolean addReplyTo( mixed $replyto, mixed $name = '')

Add Reply to email address(es) to the email

Parameters

mixed $replyto Either a string or array of strings [email address(es)]
mixed $name Either a string or array of strings [name(s)]

Return Value

Mail|boolean Returns this object for chaining on success or boolean false on failure.

Mail isHtml( boolean $ishtml = true)

Sets message type to HTML

Parameters

boolean $ishtml Boolean true or false.

Return Value

Mail Returns this object for chaining.

void isSendmail()

Send messages using $Sendmail.

This overrides the parent class to remove the restriction on the executable's name containing the word "sendmail"

Return Value

void

boolean useSendmail( string $sendmail = null)

Use sendmail for sending the email

Parameters

string $sendmail Path to sendmail [optional]

Return Value

boolean True on success

boolean useSmtp( string $auth = null, string $host = null, string $user = null, string $pass = null, string $secure = null, integer $port = 25)

Use SMTP for sending the email

Parameters

string $auth SMTP Authentication [optional]
string $host SMTP Host [optional]
string $user SMTP Username [optional]
string $pass SMTP Password [optional]
string $secure Use secure methods
integer $port The SMTP port

Return Value

boolean True on success

boolean sendMail( string $from, string $fromName, mixed $recipient, string $subject, string $body, boolean $mode = false, mixed $cc = null, mixed $bcc = null, mixed $attachment = null, mixed $replyTo = null, mixed $replyToName = null)

Function to send an email

Parameters

string $from From email address
string $fromName From name
mixed $recipient Recipient email address(es)
string $subject email subject
string $body Message body
boolean $mode false = plain text, true = HTML
mixed $cc CC email address(es)
mixed $bcc BCC email address(es)
mixed $attachment Attachment file name(s)
mixed $replyTo Reply to email address(es)
mixed $replyToName Reply to name(s)

Return Value

boolean True on success

boolean sendAdminMail( string $adminName, string $adminEmail, string $email, string $type, string $title, string $author, string $url = null)

Sends mail to administrator for approval of a user submission

Parameters

string $adminName Name of administrator
string $adminEmail Email address of administrator
string $email [NOT USED TODO: Deprecate?]
string $type Type of item to approve
string $title Title of item to approve
string $author Author of item to approve
string $url A URL to included in the mail

Return Value

boolean True on success