Yii Framework Forum: Extending Yii Cemaillogroute Class Using Mailgun - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Extending Yii Cemaillogroute Class Using Mailgun How to send Yii log messages to an email via MailGun Rate Topic: -----

#1 User is offline   zeckdude 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 09-January 14

Posted 09 January 2014 - 04:16 PM

CMailGunLogRoute.php
// components/CMailGunLogRoute.php
class CMailGunLogRoute extends CEmailLogRoute {
  protected function sendEmail($email, $subject, $message) {
    $mail = Yii::app()->mailgun->newMessage();
    $mail->setFrom($this->getSentFrom());
    $mail->addTo($email);
    $mail->setSubject($subject);
    $mail->setText($message);
    $mail->send();
  }
}


SiteController.php
// controllers/SiteController.php
Yii::log('Test Log Message', 'info','application');


main.php
// config/main.php
'import'=>array(
    'application.components.*',
),
 
'mailgun' => array(
    'class' => 'application.extensions.php-mailgun.MailgunYii',
    'domain' => 'mydomain.com',
    'key' => 'API_KEY_NUM',
    'tags' => array('yii'), // You may also specify some Mailgun parameters
    'enableTracking' => true,
),
 
'log'=>array(
   'class'=>'CLogRouter',
   'routes'=>array(
       array(
          'class'=>'CMailGunLogRoute',
          'levels'=>'info',
          'filter'=>'CLogFilter',
          'emails'=>'recipient@domain.com',
          'sentFrom'=>'sender@domain.com',
          'subject'=>'Email Log File Message',
       ),
    ),
),


If you have any additional tips on how to improve this, please feel free to add them below.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users