Guest User

Untitled

a guest
Jul 22nd, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <?
  2. // 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.
  3. // 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)
  4. // 3. Copy the below into a file called custom_email_component.php
  5. // 4. Now in your controller or wherever, call it: public $components = array('CustomEmail');
  6. // 5. Use exactly like you would the Email component, eg. $this->CustomEmail->to = 'bob@blah.com'
  7. /**
  8. * The reason we're extending CakePHP's email component is because
  9. * we don't want to repeat ourselves when sending mail. This allows us
  10. * to plug in some defaults like "$from" and $this->delivery = 'debug' if
  11. * we're running locally.
  12. */
  13. App::import('Component', 'Email');
  14. class CustomEmailComponent extends EmailComponent
  15. {
  16. // Default from address
  17. public $from = 'Miley Cyrus <miley@cyrus.com>';
  18.  
  19. /**
  20. * Over-write the send method. Then call if after we do our own
  21. * custom work. We dont have mail servers setup on our machines, so
  22. * we check if we're running locally, if so, set the emails to debug
  23. * and they will output
  24. *
  25. * @param array $data The posted form data
  26. */
  27. public function send($content = null, $template = null, $layout = null)
  28. {
  29. if(YourLib::isLocal())
  30. {
  31. $this->delivery = 'debug';
  32. }
  33.  
  34. return parent::send($content, $template, $layout);
  35.  
  36. }
  37.  
  38. }
Add Comment
Please, Sign In to add comment