Sending Mail with Xaraya

Sending mail with PHP is a trivial call to the mail function. It's a basic of PHP that is generally one of the first functions that PHP developers learn when picking up the language. The problem is, often time we need the mail function to do just a little more, such as sending attachments or inline HTML, and to rewrite the code over and over becomes redundant, especially in the Xaraya paradigm.

Xaraya has mail handling capabilities in packaged in the core. The mail module is a basic Xaraya wrapper for the versatile PHPMailer Class. Xaraya utilizes the strengths of the class and allows you to set the defaults of the class through a web based configuration. It is generally one of the first things done on a Xaraya installation, to configure and test the mail module.

With this capability built into Xaraya, we make the specifics of sending a complex mail back to being easy, just like the above mentioned PHP mail function. Now sending mail in Xaraya from your module is as easy as any Xaraya API call, considering that you understand the input parameters. There are four input parameters which are necessary for any mail call:

The PHP Documentor notes show that these inputs are required. So for any call to the mail module API, you will need the following:

Is the bare minimum call that you need to make to the mail API. Keep in mind that the info could be replaced with an array of recipients using the recipients input instead. This is all well and good, but this alone is longer than a normal PHP mail function call. The difference is, we allow more parameters to be sent. For instance, perhaps you want to add a name to the mail, along with the address:

Or perhaps you want to add a text and HTML version of the email:

Perhaps, you need to change the priority that the message is sent:

You could even add an attachment to an email if you so like:

You can also schedule the mail when you provide a timestamp which tells the Mail module to not send the mail earlier than a certain time. This parameter requires the scheduler module to be installed and activated.

Xaraya is simply a building block for your applications. The development time decreases within the framework with the reusable components. The mail module is a core module, so there is not a need to set the mail module as a dependency within your version file. It is there to use. For example of it's use, refer to the mail, roles, recommend or pubsub module for a demonstrations of its use in a working capacity.

Print | Related