BaseEmailConfig.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. class BaseEmailConfig {
  3. public $default = array(
  4. 'transport' => 'Smtp',
  5. );
  6. /**
  7. * Read Configure Email pwds and assign them to the configs.
  8. * Also assigns custom Mail config as well as log/trace configs.
  9. */
  10. public function __construct() {
  11. $pwds = (array)Configure::read('Email.Pwd');
  12. foreach ($pwds as $key => $val) {
  13. if (isset($this->{$key})) {
  14. $this->{$key}['password'] = $val;
  15. }
  16. }
  17. if (!empty($this->default['log'])) {
  18. $this->default['report'] = true;
  19. }
  20. if (isset($this->default['log'])) {
  21. unset($this->default['log']);
  22. }
  23. if (isset($this->default['trace'])) {
  24. $this->default['log'] = 'email_trace';
  25. }
  26. if (Configure::read('debug') && !Configure::read('Email.live')) {
  27. $this->default['transport'] = 'Debug';
  28. if (!isset($this->default['trace'])) {
  29. $this->default['log'] = 'email_trace';
  30. }
  31. }
  32. if ($config = Configure::read('Mail')) {
  33. if (!empty($config['smtp_host'])) {
  34. $this->default['host'] = $config['smtp_host'];
  35. }
  36. if (!empty($config['smtp_username'])) {
  37. $this->default['username'] = $config['smtp_username'];
  38. }
  39. if (!empty($config['smtp_password'])) {
  40. $this->default['password'] = $config['smtp_password'];
  41. }
  42. }
  43. }
  44. }