Mail

Extends \PHPMailer\PHPMailer\PHPMailer

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

since

1.7.0

Methods

__construct

Constructor

__construct(boolean $exceptions = true) 
since

1.7.0

Arguments

$exceptions

booleanFlag if Exceptions should be thrown

add

Add recipients to the email.

add(mixed $recipient, mixed $name = '', string $method = 'addAddress') : \Joomla\CMS\Mail\Mail|boolean
since

1.7.0

throws

\InvalidArgumentExceptionif the argument array counts do not match

\PHPMailer\PHPMailer\Exceptionif setting the address failed and exception throwing is enabled

Arguments

$recipient

mixedEither a string or array of strings [email address(es)]

$name

mixedEither a string or array of strings [name(s)]

$method

stringThe parent method's name.

Response

\Joomla\CMS\Mail\Mail|booleanReturns this object for chaining on success or boolean false on failure.

addAttachment

Add file attachment to the email

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

3.0.1

throws

\InvalidArgumentExceptionif the argument array counts do not match

\PHPMailer\PHPMailer\Exceptionif setting the attachment failed and exception throwing is enabled

Arguments

$path

mixedEither a string or array of strings [filenames]

$name

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

$encoding

mixedThe encoding of the attachment

$type

mixedThe mime type

$disposition

stringThe disposition of the attachment

Response

\Joomla\CMS\Mail\Mail|booleanReturns this object for chaining on success or boolean false on failure when exception throwing is disabled.

addBcc

Add blind carbon copy recipients to the email

addBcc(mixed $bcc, mixed $name = '') : \Joomla\CMS\Mail\Mail|boolean
since

1.7.0

throws

\PHPMailer\PHPMailer\Exceptionif exception throwing is enabled

Arguments

$bcc

mixedEither a string or array of strings [email address(es)]

$name

mixedEither a string or array of strings [name(s)]

Response

\Joomla\CMS\Mail\Mail|booleanReturns this object for chaining on success or boolean false on failure when exception throwing is disabled.

addCc

Add carbon copy recipients to the email

addCc(mixed $cc, mixed $name = '') : \Joomla\CMS\Mail\Mail|boolean
since

1.7.0

throws

\PHPMailer\PHPMailer\Exceptionif exception throwing is enabled

Arguments

$cc

mixedEither a string or array of strings [email address(es)]

$name

mixedEither a string or array of strings [name(s)]

Response

\Joomla\CMS\Mail\Mail|booleanReturns this object for chaining on success or boolean false on failure when exception throwing is enabled.

addRecipient

Add recipients to the email

addRecipient(mixed $recipient, mixed $name = '') : \Joomla\CMS\Mail\Mail|boolean
since

1.7.0

throws

\PHPMailer\PHPMailer\Exceptionif exception throwing is enabled

Arguments

$recipient

mixedEither a string or array of strings [email address(es)]

$name

mixedEither a string or array of strings [name(s)]

Response

\Joomla\CMS\Mail\Mail|booleanReturns this object for chaining on success or false on failure when exception throwing is disabled.

addReplyTo

Add Reply to email address(es) to the email

addReplyTo(mixed $replyto, mixed $name = '') : \Joomla\CMS\Mail\Mail|boolean
since

1.7.0

throws

\PHPMailer\PHPMailer\Exceptionif exception throwing is enabled

Arguments

$replyto

mixedEither a string or array of strings [email address(es)]

$name

mixedEither a string or array of strings [name(s)]

Response

\Joomla\CMS\Mail\Mail|booleanReturns this object for chaining on success or boolean false on failure when exception throwing is disabled.

clearAttachments

Unset all file attachments from the email

clearAttachments() : \Joomla\CMS\Mail\Mail
since

3.0.1

Response

\Joomla\CMS\Mail\MailReturns this object for chaining.

getInstance

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

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

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

since

1.7.0

Arguments

$id

stringThe id string for the Mail instance [optional]

$exceptions

booleanFlag if Exceptions should be thrown [optional]

Response

\Joomla\CMS\Mail\MailThe global Mail object

isHtml

Sets message type to HTML

isHtml(boolean $ishtml = true) : \Joomla\CMS\Mail\Mail
since

3.1.4

Arguments

$ishtml

booleanBoolean true or false.

Response

\Joomla\CMS\Mail\MailReturns this object for chaining.

isSendmail

Send messages using $Sendmail.

isSendmail() : void

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

since

1.7.0

removeAttachment

Unset file attachments specified by array index.

removeAttachment(integer $index) : \Joomla\CMS\Mail\Mail
since

3.0.1

Arguments

$index

integerThe numerical index of the attachment to remove

Response

\Joomla\CMS\Mail\MailReturns this object for chaining.

Send

Send the mail

Send() : boolean
since

1.7.0

throws

\Joomla\CMS\Mail\Exception\MailDisabledExceptionif the mail function is disabled

\PHPMailer\PHPMailer\Exceptionif sending failed

Response

booleanBoolean true if successful, false if exception throwing is disabled.

sendMail

Function to send an email

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) : boolean
since

1.7.0

throws

\Joomla\CMS\Mail\Exception\MailDisabledExceptionif the mail function is disabled

\PHPMailer\PHPMailer\Exceptionif exception throwing is enabled

Arguments

$from

stringFrom email address

$fromName

stringFrom name

$recipient

mixedRecipient email address(es)

$subject

stringemail subject

$body

stringMessage body

$mode

booleanfalse = plain text, true = HTML

$cc

mixedCC email address(es)

$bcc

mixedBCC email address(es)

$attachment

mixedAttachment file name(s)

$replyTo

mixedReply to email address(es)

$replyToName

mixedReply to name(s)

Response

booleanTrue on success, false on failure when exception throwing is disabled.

setBody

Set the email body

setBody(string $content) : \Joomla\CMS\Mail\Mail
since

1.7.0

Arguments

$content

stringBody of the email

Response

\Joomla\CMS\Mail\MailReturns this object for chaining.

setSender

Set the email sender

setSender(mixed $from) : \Joomla\CMS\Mail\Mail|boolean
since

1.7.0

throws

\UnexpectedValueExceptionif the sender is not a valid address

\PHPMailer\PHPMailer\Exceptionif setting the sender failed and exception throwing is enabled

Arguments

$from

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

Response

\Joomla\CMS\Mail\Mail|booleanReturns this object for chaining on success or boolean false on failure.

setSubject

Set the email subject

setSubject(string $subject) : \Joomla\CMS\Mail\Mail
since

1.7.0

Arguments

$subject

stringSubject of the email

Response

\Joomla\CMS\Mail\MailReturns this object for chaining.

useSendmail

Use sendmail for sending the email

useSendmail(string $sendmail = null) : boolean
since

1.7.0

Arguments

$sendmail

stringPath to sendmail [optional]

Response

booleanTrue on success

useSmtp

Use SMTP for sending the email

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

1.7.0

Arguments

$auth

stringSMTP Authentication [optional]

$host

stringSMTP Host [optional]

$user

stringSMTP Username [optional]

$pass

stringSMTP Password [optional]

$secure

stringUse secure methods

$port

integerThe SMTP port

Response

booleanTrue on success

Properties

instances

Mail instances container.

static
since

1.7.3

Type(s)

array<mixed,\Joomla\CMS\Mail\Mail>

CharSet

Charset of the message.

since

1.7.0

Type(s)

string