-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmail.php
More file actions
212 lines (191 loc) · 4.08 KB
/
Email.php
File metadata and controls
212 lines (191 loc) · 4.08 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php if ( ! defined('DENY_ACCESS')) exit('403: No direct file access allowed');
/**
* A Bright CMS
*
* Open source, lightweight, web application framework and content management
* system in PHP.
*
* @package A Bright CMS
* @author Gabriel Liwerant
*/
/**
* Email Class
*
* @subpackage core
* @author Gabriel Liwerant
*/
class Email
{
/**
* Stores the email address to send the email to
*
* @var string $_email_address
*/
private $_email_address;
/**
* Subject line for email
*
* @var string $_subject
*/
private $_subject;
/**
* Email message
*
* @var string $_message
*/
private $_message;
/**
* Reply-To header
*
* @var string $_reply_to
*/
private $_reply_to;
/**
* Nothing to see here...
*/
public function __construct()
{
//
}
/**
* Set email address property
*
* @param string $email_address
*
* @return object Email
*/
public function setEmailAddress($email_address)
{
$this->_email_address = $email_address;
return $this;
}
/**
* Set subject property
*
* @param string $subject
*
* @return object Email
*/
public function setSubject($subject)
{
$this->_subject = $subject;
return $this;
}
/**
* Set message property
*
* @param string $message
*
* @return object Email
*/
public function setMessage($message)
{
$this->_message = $message;
return $this;
}
/**
* Set reply to property
*
* @param string $reply_to
*
* @return object Email
*/
public function setReplyTo($reply_to)
{
$this->_reply_to = $reply_to;
return $this;
}
/**
* Sends an email with the properties and any headers which then returns a
* boolean to indicate success or failure.
*
* @return boolean
*/
public function sendMessage($email_headers)
{
$from = 'From: ' . $this->_reply_to . "\r\n";
$reply_to = 'Reply-To: ' . $this->_reply_to . "\r\n";
return mail(
$this->_email_address,
$this->_subject,
$this->_message,
$email_headers . $from . $reply_to
);
}
/**
* Validate an email address
*
* Returns true if the email address has the email address format and the
* domain exists.
*
* @author Douglas Lovell, modified by Gabriel Liwerant
* @link http://www.linuxjournal.com/article/9585?page=0,3
*
* @param string $email_address Email address to check for validity
*
* @return boolean Result of the validity checks on the email address
*/
public function validateEmailAddress($email_address)
{
$is_valid = true;
$at_index = strrpos($email_address, "@");
if (is_bool($at_index) AND ! $at_index)
{
$is_valid = false;
}
else
{
$domain = substr($email_address, $at_index + 1);
$local = substr($email_address, 0, $at_index);
$local_length = strlen($local);
$domain_length = strlen($domain);
if ( ($local_length < 1) OR ($local_length > 64) )
{
// local part length exceeded
$is_valid = false;
}
elseif ( ($domain_length < 1) OR ($domain_length > 255) )
{
// domain part length exceeded
$is_valid = false;
}
elseif ( ($local[0] === '.') OR ($local[$local_length - 1] === '.') )
{
// local part starts or ends with '.'
$is_valid = false;
}
elseif (preg_match('/\\.\\./', $local))
{
// local part has two consecutive dots
$is_valid = false;
}
elseif ( ! preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
{
// character not valid in domain part
$is_valid = false;
}
elseif (preg_match('/\\.\\./', $domain))
{
// domain part has two consecutive dots
$is_valid = false;
}
elseif ( ! preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace('\\\\', '', $local)) )
{
// character not valid in local part unless
// local part is quoted
if ( ! preg_match('/^"(\\\\"|[^"])+"$/', str_replace('\\\\', '', $local)) )
{
$is_valid = false;
}
}
if ( $is_valid AND ! (checkdnsrr($domain, 'MX') OR checkdnsrr($domain, 'A')) )
{
// domain not found in DNS
$is_valid = false;
}
}
return $is_valid;
}
}
// End of Email Class
/* EOF system/core/Email.php */