-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMY_Email.php
108 lines (79 loc) · 3.01 KB
/
MY_Email.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Email Logger
*
* This control allows you to bypass sending email and log it's content
* instead. Most appropriate for development environment or other rapid
* testing scenarios. The actual mail will never get sent only logged.
*
* By defailt it will not do anything. You either need to manually pass
* in 'log' as the protocol or the perferred way would be to add the
* following record to your email config file (config/email.php):
*
* $config['force_email_logging'] = true;
*
* TIP: Add an environment-specific config file to automatically control.
* https://www.codeigniter.com/userguide3/libraries/config.html#environments
*
* @package CodeIgniter
* @subpackage CodeIgniter Email Logger
* @category Libraries
* @author Louis Walch
* @link http://www.hellolouis.com
*/
class MY_Email extends CI_Email {
/**
* Force all mail sent from CI to be logged. Off by default.
*
* @var bool
*/
protected $_force_logging = FALSE;
/**
* Plain-text subject
*
* @var string
*/
protected $_raw_subject = '';
// --------------------------------------------------------------------
public function __construct(array $config = array()) {
// Global Code Igniter instance.
$CI = &get_instance();
// Make sure email configuration file is loaded.
$CI->load->config('email');
// Allow config file to determine what this class should do.
if (config_item('force_email_logging') && is_bool(config_item('force_email_logging'))) {
$this->_force_logging = config_item('force_email_logging');
}
parent::__construct($config);
}
// --------------------------------------------------------------------
/**
* Set Email Subject
*
* @param string
* @return CI_Email
*/
public function subject($subject) {
$this->_raw_subject = $subject;
return parent::subject($subject);
}
// --------------------------------------------------------------------
/**
* Intercept the spool request to check if we should switch to log protocol.
* We need to do this everytime in case the protocol is being passed in from Controller.
*
* @return bool
*/
protected function _spool_email() {
// If we are not logging, continue as if nothing ever happened.
if (!$this->_force_logging) return parent::_spool_email();
// Otherwise write the mail request to CodeIgnter logs.
log_message('debug', '====== MAIL LOGGER : Start ===================================================');
log_message('debug', 'To: ' . implode(', ', $this->_recipients));
log_message('debug', 'Subject: ' . $this->_raw_subject);
log_message('debug', $this->_body);
log_message('debug', '====== MAIL LOGGER : End =====================================================');
return TRUE;
}
}