/ Published in: PHP
This is a CakePHP component I used for sending out email notifications.
Expand |
Embed | Plain Text
<?php /** * This component handles sending email to webmaster */ App::uses('CakeEmail', 'Network/Email'); class NotifyComponent extends Component{ function notify($msg, $subject=null, $to=null, $smtp=false){ $body = "Website Notice.\n" . $t . "\n" . $msg; $notifyEmail = Configure::read('notify-email'); $webmasterEmail = Configure::read('webmaster-email'); $webmasterName = Configure::read('webmaster-name'); if ( $subject == null ) $subject = $webmasterName . ' - Site Notice'; $email = $this->createEmailObject($smtp); ->to($to) ->subject($subject); $email->sender($webmasterEmail, $webmasterName); $email->send($body); } function critical($msg, $trace=null){ $body = "Critical error.\n" . $t . "\n" . $msg; if ( $trace ){ $body .="\n\n"; } } else{ $body .= $trace; } } $notifyEmail = Configure::read('notify-email'); $webmasterEmail = Configure::read('webmaster-email'); $webmasterName = Configure::read('webmaster-name'); $email = $this->createEmailObject($smtp); ->to($notifyEmail) ->subject($webmasterName.' - Critical site error'); $email->sender($webmasterEmail, $webmasterName); $email->send($body); } function createEmailObject($smtp=false){ $email = new CakeEmail(); $emailConfig = Configure::read('email-config'); // force smtp if the parameter says so even if it is turned off in the config. if ( $smtp ){ $email->config('smtp'); } $email->config($emailConfig); } return $email; } } ?>
You need to login to post a comment.
