Warning
Much work should be added to this example to make a real world application of it, such as adding better security and error support.
An easy to add security measure would be to use the JMailHelper
class:
http://api.joomla.org/Joomla-Framework/Mail/JMailHelper.html
This class can help us check if we are using a proper e-mail, or check that no headers have been injected in the subject, body, and so on.
For example, in our module, if we want to check that no headers have been injected
in our body, we could do it like this. The following excerpt is from the
modules/mod_littlecontact/helper.php
file:
jimport('joomla.mail.helper'); $body = JMailHelper::cleanText($body); $mail->setBody($body);
First we import the helper class, then we use the cleanText
method to check our $body
variable. Easy, isn't it? Just
check the previous URL, you will see some useful methods to use.