Email Class. Provides a common interface to send email from the Joomla! Platform
since |
1.7.0 |
---|---|
package |
Joomla CMS |
Methods
__construct
Constructor
__construct( exceptions = true) :
since |
1.7.0 |
---|
Arguments
- exceptions
bool
Flag if Exceptions should be thrown
Response
mixed
add
Add recipients to the email.
add( recipient, name = '', method = 'addAddress') : \Joomla\CMS\Mail\Mail|bool
since |
1.7.0 |
---|---|
throws |
|
Arguments
- recipient
mixed
Either a string or array of strings [email address(es)]- name
mixed
Either a string or array of strings [name(s)]- method
string
The parent method's name.
Response
Mail|bool
Returns this object for chaining on success or boolean false on failure.
addAttachment
Add file attachment to the email
addAttachment( path, name = '', encoding = 'base64', type = 'application/octet-stream', disposition = 'attachment') : \Joomla\CMS\Mail\Mail|bool
since |
3.0.1 |
---|---|
throws |
|
Arguments
- path
mixed
Either a string or array of strings [filenames]- name
mixed
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.- encoding
mixed
The encoding of the attachment- type
mixed
The mime type- disposition
string
The disposition of the attachment
Response
Mail|bool
Returns 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( bcc, name = '') : \Joomla\CMS\Mail\Mail|bool
since |
1.7.0 |
---|---|
throws |
|
Arguments
- bcc
mixed
Either a string or array of strings [email address(es)]- name
mixed
Either a string or array of strings [name(s)]
Response
Mail|bool
Returns 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( cc, name = '') : \Joomla\CMS\Mail\Mail|bool
since |
1.7.0 |
---|---|
throws |
|
Arguments
- cc
mixed
Either a string or array of strings [email address(es)]- name
mixed
Either a string or array of strings [name(s)]
Response
Mail|bool
Returns this object for chaining on success or boolean false on failure when exception throwing is enabled.
addRecipient
Add recipients to the email
addRecipient( recipient, name = '') : \Joomla\CMS\Mail\Mail|bool
since |
1.7.0 |
---|---|
throws |
|
Arguments
- recipient
mixed
Either a string or array of strings [email address(es)]- name
mixed
Either a string or array of strings [name(s)]
Response
Mail|bool
Returns 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( replyto, name = '') : \Joomla\CMS\Mail\Mail|bool
since |
1.7.0 |
---|---|
throws |
|
Arguments
- replyto
mixed
Either a string or array of strings [email address(es)]- name
mixed
Either a string or array of strings [name(s)]
Response
Mail|bool
Returns 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
getInstance
Returns the global email object, only creating it if it doesn't already exist.
getInstance( id = 'Joomla', exceptions = true) : \Joomla\CMS\Mail\Mail
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 |
4.4.0 |
---|---|
deprecated |
4.4.0 will be removed in 6.0 Use the mailer service in the DI container and create a mailer from there Example: Factory::getContainer()->get(MailerFactoryInterface::class)->createMailer(); |
Arguments
- id
string
The id string for the Mail instance [optional]- exceptions
bool
Flag if Exceptions should be thrown [optional]
Response
Mail
The global Mail object
isHtml
Sets message type to HTML
isHtml( ishtml = true) : \Joomla\CMS\Mail\Mail
since |
3.1.4 |
---|
Arguments
- ishtml
bool
Boolean true or false.
Response
Mail
Returns this object for chaining.
isSendmail
Send messages using $Sendmail.
isSendmail() :
This overrides the parent class to remove the restriction on the executable's name containing the word "sendmail"
since |
1.7.0 |
---|
Response
void
removeAttachment
Unset file attachments specified by array index.
removeAttachment( index) : \Joomla\CMS\Mail\Mail
since |
3.0.1 |
---|
Arguments
- index
int
The numerical index of the attachment to remove
Response
Mail
Returns this object for chaining.
Send
Send the mail
Send() :
since |
1.7.0 |
---|---|
throws |
|
Response
bool
Boolean true if successful, false if exception throwing is disabled.
sendMail
Function to send an email
sendMail( from, fromName, recipient, subject, body, mode = false, cc = null, bcc = null, attachment = null, replyTo = null, replyToName = null) :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- from
string
From email address- fromName
string
From name- recipient
mixed
Recipient email address(es)- subject
string
email subject- body
string
Message body- mode
bool
false = plain text, true = HTML- cc
mixed
CC email address(es)- bcc
mixed
BCC email address(es)- attachment
mixed
Attachment file name(s)- replyTo
mixed
Reply to email address(es)- replyToName
mixed
Reply to name(s)
Response
bool
True on success, false on failure when exception throwing is disabled.
setBody
Set the email body
setBody( content) : \Joomla\CMS\Mail\Mail
since |
1.7.0 |
---|
Arguments
- content
string
Body of the email
Response
Mail
Returns this object for chaining.
setSender
Set the email sender
setSender( from, name = '') : \Joomla\CMS\Mail\Mail|bool
since |
1.7.0 |
---|---|
throws |
|
Arguments
- from
mixed
email address and Name of senderarray([0] => email Address, [1] => Name)
or as a string- name
mixed
Either a string or array of strings [name(s)]
Response
Mail|bool
Returns this object for chaining on success or boolean false on failure.
setSubject
Set the email subject
setSubject( subject) : \Joomla\CMS\Mail\Mail
since |
1.7.0 |
---|
Arguments
- subject
string
Subject of the email
Response
Mail
Returns this object for chaining.
useSendmail
Use sendmail for sending the email
useSendmail( sendmail = null) :
since |
1.7.0 |
---|
Arguments
- sendmail
string
Path to sendmail [optional]
Response
bool
True on success
useSmtp
Use SMTP for sending the email
useSmtp( auth = null, host = null, user = null, pass = null, secure = null, port = 25) :
since |
1.7.0 |
---|
Arguments
- auth
string
SMTP Authentication [optional]- host
string
SMTP Host [optional]- user
string
SMTP Username [optional]- pass
string
SMTP Password [optional]- secure
string
Use secure methods- port
int
The SMTP port
Response
bool
True on success
Properties
instances
Mail instances container.
since |
1.7.3 |
---|---|
deprecated |
4.4.0 will be removed in 6.0 See getInstance() for more details |
Type(s)
array<string|int, Mail>
CharSet
Charset of the message.
since |
1.7.0 |
---|
Type(s)
string