You can send email using the Zend_Mail library when coding in Zend framework but what if you want to send email from a number of your scripts. You cannot go and replicate the code on your every controller script as that would be a waste of effort and time. Not only that you would not be using the flexible power of OOP to create reusable code which you can use elsewhere in other projects in the future. I am going to create a custom library in Zend which will send out email. You will need to pass the sender email address, recipient email address, subject and body and the code will do the rest.
- Firsly create a folder by the name of Custom in your library folder.
- Then create a PHP script and name it as Functions.php
- Open the Functions.php script and enter the following code inside it.
addTo($to); $mail->setSubject($subject); $mail->setBodyHtml($body); $mail->setFrom($from); $mail->addBcc(
); $mail->send(); } }
After adding the above code save the file and call the function from your controller as follows
, , , );
Please note that I have declared the function as static in my Functions.php file so I can execute the function as is and do not need to instantiate it.