BaseEmailConfig.php 1.6 KB

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