Contents

Fetch the mail object

A reference to the global mail object (JMail) is fetched through the JFactory object. This is the object creating our mail.

$mailer=& JFactory::getMailer();

Set a sender

The mailer expect the sender to be an array of an email address and a name. We fetch the sites email address and name from the configuration. These are set in the administration back-end (Global Configuration -> Server -> Mail Settings).

Create the mail

We need to set a subject line and create the text body. The subject is set with setSubject.

The easy way to create an email body is as a string with plain text. Use the function setBody to add a message to the mail body. You can also attach a file with addAttachment. It takes a single file name or an array of file names as argument.

If you prefer to format your email in HTML, you need to tell the mailer it is HTML. This is done with IsHTML. The subject line and any attachments are handled as above, with the exception of images embedded in the HTML. These are taken care of with the function AddEmbeddedImage.