User Guides


The Mail class enables you to easily programatically send emails from your website.

Configuring Mail

Out of the box, LexasCMS supports sending email via SMTP using the built-in mailSmtp addon. You can configure the addon by placing a mail.yaml config file in your sites config directory. For example:

# config/default/mail.yaml
auth: true
username: foo
password: bar

Sending an Email

Once you have added your mail configuration, you can start sending emails. See the example below.

// Create email message
$emailMessage = $cms->mail->createMessage();

// Add recipient

// Set email body
$emailMessage->setBody("<strong>HTML</strong> body copy");
$emailMessage->setTextBody("Plain text body copy");

// Send email

This will send an HTML email containing <strong>HTML</strong> body copy to It will also attach a plain text alternative of the email, which is useful for recipients who either cannot receive HTML emails, or simply prefer a plain text alternative.

Further Reading

You can find full documentation for the MailMessage class in the full API reference.