« Back to blog

Blog: Emailer Component, with a twist

Graham Weldon

13 November, 2008

Implemented the mailout facility for the Enquiries page, finally. Not that this is difficult at all, since CakePHP provides a nice ready-to-use Email Component. But with the help of Dale, I was able to devise a manner in which the Email component is extended, slightly, to provide site-wide settings in a transparent manner.

While this is entirely possible from the Email component as it is, you would need to either apply these settings in your AppController, or change the setting in each controller that used the Email Component. What I have achieved basically overloads the send() function, and applies the sitewide settings before passing the call back to the parent Email component. Simple, yet effective. But wait, theres more...

To extend this even further, it defaults to the mail delivery method, but reads the settings table in the database to see if SMTP is preferred, and what values are provided for SMTP. It applies these, and adjusts the delivery method accordingly. So currently the Enquiry page on this site is sending mail out via an external SMTP server that hosts my mail. Fantastic! I even managed to stay pretty DRY in the process.

Comments