-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMail.php
113 lines (91 loc) · 1.81 KB
/
Mail.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
109
110
111
112
113
<?php
/**
* Quokka Framework
*
* @copyright Copyright 2012 Fabien Casters
* @license http://www.gnu.org/licenses/lgpl.html Lesser General Public License
*/
namespace Quokka;
/**
* \Quokka\Mail
*
* @package Quokka
* @author Fabien Casters
*/
class Mail {
/**
* @var array
*/
private $_to = [];
/**
* @var array
*/
private $_from = '';
/**
* @var array
*/
private $_headers = [];
/**
* @var string
*/
private $_subject = '';
/**
* @var string
*/
private $_body = '';
/**
*
* @param $name string
* @param $from string
* @return void
*/
public function setFrom($name, $mail) {
$this->_from = $name . ' <' . $mail . '>';
}
/**
*
* @param $name string
* @param $mail string
* @return void
*/
public function addTo($name, $mail) {
$this->_to[] = $name . ' <' . $mail . '>';
}
/**
*
* @param $key string
* @param $value string
*/
public function addHeader($key, $value) {
$this->_headers[$key] = $value;
}
/**
*
* @param $subject string
* @return void
*/
public function setSubject($subject) {
$this->_subject = $subject;
}
/**
*
* @param $body string
* @return void
*/
public function setBody($body) {
$this->_body = $body;
}
/**
*
* @return boolean
*/
public function send() {
$to = implode(', ', $this->_to);
$this->addHeader('From', $this->_from);
$headers = [];
foreach($this->_headers as $key => $value)
$headers[] = $key . ': ' . $value;
$headers = implode("\r\n", $headers);
return mail($to, $this->_subject, $this->_body, $headers);
}
}