E-mail sending is not a task that requires any interaction by visitors to our web applications, so it is pointless to make them wait for their delivery, which is exactly what we would do if we were to send an e-mail from a controller's action.
Deferring e-mail sending to a shell makes real sense both from a performance perspective and from the administrator point of view, as we may also add the ability to re-send failed e-mails.
This recipe uses the Email
component provided by CakePHP to send a fictitious newsletter, adding the ability to test the sending process through a shell parameter.
To go through this recipe we need some data to work with. Create a subscribers
table with the following SQL statement:
CREATE TABLE `subscribers`( `id` INT UNSIGNED AUTO_INCREMENT NOT NULL, `name` VARCHAR(255) NOT NULL, `email` VARCHAR(255) NOT NULL, PRIMARY KEY(`id`) );
Create a newsletters
table with the following statement:
CREATE TABLE `newsletters`( `id` INT...