Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- // 1. Change the line at the bottom that detects YourLib::isLocal() to whatever you want to use for detecting if you're running locally. This just outputs the mail message if we are local.
- // 2. Add <?= $this->Session->flash('email'); ?> to your default.ctp view. This is where the debug email will output to (if you're running locally)
- // 3. Copy the below into a file called custom_email_component.php
- // 4. Now in your controller or wherever, call it: public $components = array('CustomEmail');
- // 5. Use exactly like you would the Email component, eg. $this->CustomEmail->to = 'bob@blah.com'
- /**
- * The reason we're extending CakePHP's email component is because
- * we don't want to repeat ourselves when sending mail. This allows us
- * to plug in some defaults like "$from" and $this->delivery = 'debug' if
- * we're running locally.
- */
- App::import('Component', 'Email');
- class CustomEmailComponent extends EmailComponent
- {
- // Default from address
- public $from = 'Miley Cyrus <miley@cyrus.com>';
- /**
- * Over-write the send method. Then call if after we do our own
- * custom work. We dont have mail servers setup on our machines, so
- * we check if we're running locally, if so, set the emails to debug
- * and they will output
- *
- * @param array $data The posted form data
- */
- public function send($content = null, $template = null, $layout = null)
- {
- if(YourLib::isLocal())
- {
- $this->delivery = 'debug';
- }
- return parent::send($content, $template, $layout);
- }
- }
Add Comment
Please, Sign In to add comment