modMail is an abstract class that can be extended to provide mail services for Revolution. It cannot be run by itself, but must be extended with an implementation class (such as PHPMailer).
modPHPMailer is a class that extends modMail to provide an implementation for the open source PHPMailer class.
- modSwiftMailer - Can be downloaded through Package Management.
The following example is based on the modPHPMailer which comes with MODX Revolution.
Let's say we have an email template in the Chunk 'myEmailTemplate'. We want to send it via mail to firstname.lastname@example.org, with the From address being 'email@example.com'. We also want it to be an HTML email. Here's how we'd do it:
Note that we have to reset() if we want to send mail again; this resets all the fields to blank. Also, the fields above are optional (just like PHPMailer), so that if you didn't want to specify a 'reply-to' (though we recommend it!) you can.
Also, if you want to send the email to multiple addresses, you can simply call address('to') again, like so:
And finally, the example code above will send a message to our error.log if the mail isn't sent for some reason (usually a server misconfiguration).
In the example above, modX.getChunk was used as the mail message. See the documentation on that function for how to use its optional second argument. As far as modMail is concerned, the placeholders used are entirely up to you; you don't even have to use getChunk at all. You could just as easily pass the modMail::MAIL_BODY setting a static string.
Simple - just extend modMail with that class, then load your class via getService. You'll get all the modMail functionality, but you will have to provide the wrapper class (like modPHPMailer) to do so.