DRY sendEmail() ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: DRY sendEmail() ? (/showthread.php?tid=63669) Pages:
1
2
|
DRY sendEmail() ? - solidcodes - 11-25-2015 I just created a simple DRY sendEmail() method. Hoping this will save me time from not re-inventing the wheel over and over again. here is the codes Code: /*** Below is an example of how to call the method above from controller Code: public function callSendEmail() It's just a simple first step. currently I put it under MY_Controller. Should I put this under helper file? or stick with MY_Controller. thanks in advance. RE: DRY sendEmail() ? - Bhavesh - 11-25-2015 Hi Create one helper file in helper folder (mail_helper.php) and write PHP Code: if ( ! function_exists('sendMail')) and call or use in controller like below PHP Code: $this->load->helper('mail_helper'); RE: DRY sendEmail() ? - solidcodes - 11-25-2015 actually this code below, Code: sendMail($to_email,$to_name,$from_email,$from_name,'Mail subject','Mail message'); For starter that code is fine, but it's called longlinitis disease. Beautiful codes are short and concise. RE: DRY sendEmail() ? - InsiteFX - 11-26-2015 Both of you should be checking the send method to make sure it did not error. RE: DRY sendEmail() ? - solidcodes - 11-26-2015 @insidefx can you show us your sample codes please. thanks in advance. RE: DRY sendEmail() ? - solidcodes - 11-26-2015 @Bhavesh why did you used/call this code below? Code: $CI =& get_instance(); please explain thanks. RE: DRY sendEmail() ? - orionstar - 11-26-2015 (11-26-2015, 05:00 PM)solidcodes Wrote: @Bhavesh In a helper you cannot access the features of CodeIgniter with the $this variable, so if you want to utilize CI's features you have to get the CI superobject which is possible with the get_instance() method. RE: DRY sendEmail() ? - solidcodes - 11-26-2015 @orionstar I'm familiar with it but I forgot because I've been to laravel. thanks for reminding me. This is the reason to be a good programmer you need to use it and practice it everyday. or else you will forget. @Bhavesh thanks for sharing the codes dude. +1 for sharing RE: DRY sendEmail() ? - solidcodes - 11-26-2015 here is the updated codes under helper folder now. Code: function sendEmail($data = array()) RE: DRY sendEmail() ? - kenjis - 11-26-2015 See http://www.codeigniter.com/user_guide/libraries/email.html#CI_Email::send The send() method returns FALSE on failure. You should take care of the case. |