1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Provides mail functionality using the php mail function |
5
|
|
|
* |
6
|
|
|
* PHP Version 5 |
7
|
|
|
* |
8
|
|
|
* @category Core |
9
|
|
|
* @package Mail |
10
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
11
|
|
|
* @copyright 2013 cSphere Team |
12
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
13
|
|
|
* @link http://www.csphere.eu |
14
|
|
|
**/ |
15
|
|
|
|
16
|
|
|
namespace csphere\core\mail; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Provides mail functionality using the php mail function |
20
|
|
|
* |
21
|
|
|
* @category Core |
22
|
|
|
* @package Mail |
23
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
24
|
|
|
* @copyright 2013 cSphere Team |
25
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
26
|
|
|
* @link http://www.csphere.eu |
27
|
|
|
**/ |
28
|
|
|
|
29
|
|
|
class Driver_Sendmail extends Base |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Creates the mail handler object |
33
|
|
|
* |
34
|
|
|
* @param array $config Configuration details as an array |
35
|
|
|
* |
36
|
|
|
* @return \csphere\core\mail\Driver_Sendmail |
37
|
|
|
**/ |
|
|
|
|
38
|
|
|
|
39
|
|
|
public function __construct(array $config) |
40
|
|
|
{ |
41
|
|
|
parent::__construct($config); |
42
|
|
|
|
43
|
|
|
// Change sendmail setting |
44
|
|
|
ini_set('sendmail_from', $this->config['from']); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Prepares a mail by setting its content |
49
|
|
|
* |
50
|
|
|
* @param string $subject Subject to use in email |
51
|
|
|
* @param string $message Message to use in email |
52
|
|
|
* @param string $type Defaults to text/plain |
53
|
|
|
* |
54
|
|
|
* @return boolean |
55
|
|
|
**/ |
|
|
|
|
56
|
|
|
|
57
|
|
|
public function prepare($subject, $message, $type = 'text/plain') |
58
|
|
|
{ |
59
|
|
|
// Run initial preparations |
60
|
|
|
parent::prepare($subject, $message, $type); |
61
|
|
|
|
62
|
|
|
// Set header data |
63
|
|
|
$headers = ['MIME-Version: 1.0', |
64
|
|
|
'Content-Type: ' . $type . '; charset=UTF-8', |
65
|
|
|
'Content-Transfer-Encoding: base64', |
66
|
|
|
'X-Mailer: cSphere', |
67
|
|
|
'From: ' . $this->config['from']]; |
68
|
|
|
|
69
|
|
|
$this->headers = array_merge($this->headers, $headers); |
70
|
|
|
|
71
|
|
|
// Create encoded subject and content strings |
72
|
|
|
$this->encode(); |
73
|
|
|
|
74
|
|
|
return true; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Sends the prepared content to a given email |
79
|
|
|
* |
80
|
|
|
* @param string $email Email target |
81
|
|
|
* @param boolean $clear Defaults to true which keeps mail data |
82
|
|
|
* |
83
|
|
|
* @return boolean |
84
|
|
|
**/ |
|
|
|
|
85
|
|
|
|
86
|
|
|
public function send($email, $clear = true) |
87
|
|
|
{ |
88
|
|
|
// Send mail |
89
|
|
|
$headers = implode($this->config['eol'], $this->headers); |
90
|
|
|
|
91
|
|
|
$send = mail( |
92
|
|
|
$email, $this->content['subject_b64'], |
93
|
|
|
$this->content['message_b64'], $headers |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
// Log mail and handle clear status |
97
|
|
|
$this->log($email, $send); |
98
|
|
|
|
99
|
|
|
$this->clear($clear); |
100
|
|
|
|
101
|
|
|
return $send; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.