| 1 |
<?php |
|---|
| 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 |
class Mail { |
|---|
| 59 |
|
|---|
| 60 |
* List of fake e-mails hosts. IMPORTANT NOTE: This is not meant to block |
|---|
| 61 |
* hotmail, gmail, etc. On the contrary, we encourage users to use |
|---|
| 62 |
* annonymous email. We just want them to stay reachable in case of problem |
|---|
| 63 |
* or abuse. |
|---|
| 64 |
* |
|---|
| 65 |
* All domains must be lowercase |
|---|
| 66 |
* @note We may have to do something a little smarter to deal with the likes |
|---|
| 67 |
* of 2prong.com and blah+blah@gmail.com |
|---|
| 68 |
*/ |
|---|
| 69 |
private static $_hosts_black_list = array ( |
|---|
| 70 |
"10minutemail.com", |
|---|
| 71 |
"afrobacon.com", |
|---|
| 72 |
"antispam24.de", |
|---|
| 73 |
"bloglines.com", |
|---|
| 74 |
"discardmail.com", |
|---|
| 75 |
"disposeamail.com", |
|---|
| 76 |
"dodgeit.com", |
|---|
| 77 |
"dontreg.com", |
|---|
| 78 |
"dumpmail.de", |
|---|
| 79 |
"e4ward.com", |
|---|
| 80 |
"emailias.com", |
|---|
| 81 |
"guerrillamail.info", |
|---|
| 82 |
"gishpuppy.com", |
|---|
| 83 |
"golfilla.info", |
|---|
| 84 |
"greensloth.com", |
|---|
| 85 |
"hatespam.org", |
|---|
| 86 |
"haltospam.com", |
|---|
| 87 |
"h8s.org", |
|---|
| 88 |
"ipoo.org", |
|---|
| 89 |
"jetable.org", |
|---|
| 90 |
"kasmail.com", |
|---|
| 91 |
"mail-filter.com", |
|---|
| 92 |
"maileater.com", |
|---|
| 93 |
"mailexpire.com", |
|---|
| 94 |
"mailinator.com", |
|---|
| 95 |
"mailnull.com", |
|---|
| 96 |
"mailshell.com", |
|---|
| 97 |
"mymailoasis.com", |
|---|
| 98 |
"mytrashmail.com", |
|---|
| 99 |
"mytrashmail.net", |
|---|
| 100 |
"nervmich.net", |
|---|
| 101 |
"oopi.org", |
|---|
| 102 |
"poofy.org", |
|---|
| 103 |
"pookmail.com", |
|---|
| 104 |
"put2.net", |
|---|
| 105 |
"senseless-entertainment.com", |
|---|
| 106 |
"shortmail.net", |
|---|
| 107 |
"simplicato.net", |
|---|
| 108 |
"slaskpost.se", |
|---|
| 109 |
"sneakemail.com", |
|---|
| 110 |
"sofort-mail.de", |
|---|
| 111 |
"spam.la", |
|---|
| 112 |
"spamcon.org", |
|---|
| 113 |
"spamday.com", |
|---|
| 114 |
"spamex.com", |
|---|
| 115 |
"spamgourmet.com", |
|---|
| 116 |
"spamhole.com", |
|---|
| 117 |
"spammotel.com", |
|---|
| 118 |
"tempemail.net", |
|---|
| 119 |
"tempinbox.com", |
|---|
| 120 |
"temporaryinbox.com", |
|---|
| 121 |
"throwaway.de", |
|---|
| 122 |
"trash-mail.de", |
|---|
| 123 |
"woodyland.org", |
|---|
| 124 |
"wuzup.net" |
|---|
| 125 |
); |
|---|
| 126 |
|
|---|
| 127 |
* Name email will been sent from |
|---|
| 128 |
* |
|---|
| 129 |
* @var string |
|---|
| 130 |
*/ |
|---|
| 131 |
private $_fromName; |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
* Address email will be sent from |
|---|
| 135 |
* |
|---|
| 136 |
* @var string |
|---|
| 137 |
*/ |
|---|
| 138 |
private $_fromEmail; |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
* Name email will be sent to |
|---|
| 142 |
* |
|---|
| 143 |
* @var string |
|---|
| 144 |
*/ |
|---|
| 145 |
private $_toName; |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
* Address email will be sent to |
|---|
| 149 |
* |
|---|
| 150 |
* @var string |
|---|
| 151 |
*/ |
|---|
| 152 |
private $_toEmail; |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
* Subject of email |
|---|
| 156 |
* |
|---|
| 157 |
* @var string |
|---|
| 158 |
*/ |
|---|
| 159 |
private $_subject; |
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
* Content of email |
|---|
| 163 |
* |
|---|
| 164 |
* @var string |
|---|
| 165 |
*/ |
|---|
| 166 |
private $_body; |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
* Priority of email |
|---|
| 170 |
* |
|---|
| 171 |
* @var boolean |
|---|
| 172 |
*/ |
|---|
| 173 |
private $_highPriority; |
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
* Encodes the MIME header |
|---|
| 177 |
* |
|---|
| 178 |
* @param string $header Header of email |
|---|
| 179 |
* |
|---|
| 180 |
* @return string Encoded MIME header |
|---|
| 181 |
|
|---|
| 182 |
* |
|---|
| 183 |
* @see http://www.php.net/manual/en/function.mb-send-mail.php |
|---|
| 184 |
*/ |
|---|
| 185 |
private function _encodeMimeHeader($header) { |
|---|
| 186 |
|
|---|
| 187 |
$header = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $header); |
|---|
| 188 |
$header = str_replace(' ', '_', $header); |
|---|
| 189 |
return "=?utf-8?Q?$header?="; |
|---|
| 190 |
} |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
* Returns name of sender of email |
|---|
| 194 |
* |
|---|
| 195 |
* @return string Name of sender of email |
|---|
| 196 |
* |
|---|
| 197 |
* @access public |
|---|
| 198 |
*/ |
|---|
| 199 |
public function getSenderName() { |
|---|
| 200 |
return $this->_fromName; |
|---|
| 201 |
} |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
* Sets name of sender of email |
|---|
| 205 |
* |
|---|
| 206 |
* @param string $name Name of sender of email |
|---|
| 207 |
* |
|---|
| 208 |
* @return void |
|---|
| 209 |
* |
|---|
| 210 |
* @access public |
|---|
| 211 |
*/ |
|---|
| 212 |
public function setSenderName($name) { |
|---|
| 213 |
|
|---|
| 214 |
$this->_fromName = $this->_encodeMimeHeader($name); |
|---|
| 215 |
} |
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
* Returns address of sender of email |
|---|
| 219 |
* |
|---|
| 220 |
* @return string Address of sender of email |
|---|
| 221 |
* |
|---|
| 222 |
* @access public |
|---|
| 223 |
*/ |
|---|
| 224 |
public function getSenderEmail() { |
|---|
| 225 |
return $this->_fromEmail; |
|---|
| 226 |
} |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
* Sets address of sender of email |
|---|
| 230 |
* |
|---|
| 231 |
* @param string $mail Address of sender of email |
|---|
| 232 |
* |
|---|
| 233 |
* @return void |
|---|
| 234 |
* |
|---|
| 235 |
* @access public |
|---|
| 236 |
*/ |
|---|
| 237 |
public function setSenderEmail($mail) { |
|---|
| 238 |
$this->_fromEmail = $mail; |
|---|
| 239 |
} |
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
* Returns name of recipient of email |
|---|
| 243 |
* |
|---|
| 244 |
* @return string Name of recipient of email |
|---|
| 245 |
* |
|---|
| 246 |
* @access public |
|---|
| 247 |
*/ |
|---|
| 248 |
public function getRecipientName() { |
|---|
| 249 |
return $this->_toName; |
|---|
| 250 |
} |
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
* Sets name of recipient of email |
|---|
| 254 |
* |
|---|
| 255 |
* @param string $name Name of recipient of email |
|---|
| 256 |
* |
|---|
| 257 |
* @return void |
|---|
| 258 |
* |
|---|
| 259 |
* @access public |
|---|
| 260 |
*/ |
|---|
| 261 |
public function setRecipientName($name) { |
|---|
| 262 |
|
|---|
| 263 |
$this->_toName = $this->_encodeMimeHeader($name); |
|---|
| 264 |
} |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
* Returns address of recipient of email |
|---|
| 268 |
* |
|---|
| 269 |
* @return string Address of recipient of email |
|---|
| 270 |
* |
|---|
| 271 |
* @access public |
|---|
| 272 |
*/ |
|---|
| 273 |
public function getRecipientEmail() { |
|---|
| 274 |
return $this->_toEmail; |
|---|
| 275 |
} |
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
* Sets address of recipient of email |
|---|
| 279 |
* |
|---|
| 280 |
* @param string $mail Address of recipient of email |
|---|
| 281 |
* |
|---|
| 282 |
* @return void |
|---|
| 283 |
* |
|---|
| 284 |
* @access public |
|---|
| 285 |
*/ |
|---|
| 286 |
public function setRecipientEmail($mail) { |
|---|
| 287 |
$this->_toEmail = $mail; |
|---|
| 288 |
} |
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
* Returns subject of email |
|---|
| 292 |
* |
|---|
| 293 |
* @return string Subject of email |
|---|
| 294 |
* |
|---|
| 295 |
* @access public |
|---|
| 296 |
*/ |
|---|
| 297 |
public function getMessageSubject() { |
|---|
| 298 |
return $this->_subject; |
|---|
| 299 |
} |
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
* Sets subject of email |
|---|
| 303 |
* |
|---|
| 304 |
* @param string $subject Subject of email |
|---|
| 305 |
* |
|---|
| 306 |
* @return void |
|---|
| 307 |
* |
|---|
| 308 |
* @access public |
|---|
| 309 |
*/ |
|---|
| 310 |
public function setMessageSubject($subject) { |
|---|
| 311 |
$this->_subject = $this->_encodeMimeHeader($subject); |
|---|
| 312 |
} |
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
* Returns message body of email |
|---|
| 316 |
* |
|---|
| 317 |
* @return string Message body of email |
|---|
| 318 |
* |
|---|
| 319 |
* @access public |
|---|
| 320 |
*/ |
|---|
| 321 |
public function getMessageBody() { |
|---|
| 322 |
return $this->_body; |
|---|
| 323 |
} |
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
* Sets message body of email |
|---|
| 327 |
* |
|---|
| 328 |
* @param string $body Message body of email |
|---|
| 329 |
* |
|---|
| 330 |
* @return void |
|---|
| 331 |
* |
|---|
| 332 |
* @access public |
|---|
| 333 |
*/ |
|---|
| 334 |
public function setMessageBody($body) { |
|---|
| 335 |
$this->_body = $body; |
|---|
| 336 |
} |
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
* Returns the priority of the email |
|---|
| 340 |
* |
|---|
| 341 |
* @return boolean Whether high priority or not |
|---|
| 342 |
* |
|---|
| 343 |
* @access public |
|---|
| 344 |
*/ |
|---|
| 345 |
public function getHighPriority() { |
|---|
| 346 |
return $this->_highPriority; |
|---|
| 347 |
} |
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
* Sets the priority of the email |
|---|
| 351 |
* |
|---|
| 352 |
* @param boolean $boolean Whether high priority or not |
|---|
| 353 |
* |
|---|
| 354 |
* @return void |
|---|
| 355 |
* |
|---|
| 356 |
* @access public |
|---|
| 357 |
*/ |
|---|
| 358 |
public function setHighPriority($boolean) { |
|---|
| 359 |
$this->_highPriority = $boolean ? true : false; |
|---|
| 360 |
} |
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
* Packs email and sends it according to RFC822 |
|---|
| 364 |
* |
|---|
| 365 |
* @return bool True if email could be sent |
|---|
| 366 |
* |
|---|
| 367 |
* @access public |
|---|
| 368 |
*/ |
|---|
| 369 |
public function send() { |
|---|
| 370 |
$phpmailerPath = 'lib/PHPMailer_v2.0.0/'; |
|---|
| 371 |
require_once ($phpmailerPath.'class.phpmailer.php'); |
|---|
| 372 |
require_once ($phpmailerPath.'class.smtp.php'); |
|---|
| 373 |
require_once ('classes/Session.php'); |
|---|
| 374 |
$mail = new PHPMailer(); |
|---|
| 375 |
$session = Session::getObject(); |
|---|
| 376 |
$lang = substr ($session->get(SESS_LANGUAGE_VAR),0,2); |
|---|
| 377 |
$mail->SetLanguage($lang, $phpmailerPath.'language/'); |
|---|
| 378 |
$mail->CharSet = "utf-8"; |
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
$mail->Mailer = EMAIL_MAILER; |
|---|
| 382 |
if (EMAIL_MAILER == 'smtp') { |
|---|
| 383 |
$mail->IsSMTP(); |
|---|
| 384 |
$mail->Host = EMAIL_HOST; |
|---|
| 385 |
$mail->SMTPAuth = EMAIL_AUTH; |
|---|
| 386 |
|
|---|
| 387 |
if (EMAIL_AUTH) { |
|---|
| 388 |
$mail->Username = EMAIL_USERNAME; |
|---|
| 389 |
$mail->Password = EMAIL_PASSWORD; |
|---|
| 390 |
} |
|---|
| 391 |
} |
|---|
| 392 |
|
|---|
| 393 |
$mail->AddAddress($this->getRecipientEmail(), $this->getRecipientName()); |
|---|
| 394 |
$mail->From = $this->getSenderEmail(); |
|---|
| 395 |
$mail->FromName = $this->getSenderName(); |
|---|
| 396 |
$mail->Sender = $this->getSenderEmail(); |
|---|
| 397 |
if ($this->getHighPriority()) { |
|---|
| 398 |
$mail->Priority = 1; |
|---|
| 399 |
} |
|---|
| 400 |
$mail->Subject = $this->getMessageSubject(); |
|---|
| 401 |
$mail->Body = $this->getMessageBody(); |
|---|
| 402 |
|
|---|
| 403 |
$result = $mail->Send(); |
|---|
| 404 |
if (!$result) { |
|---|
| 405 |
throw new exception(sprintf(_("PHPMailer couldn't sent mail. Error was: %s"),$mail->ErrorInfo)); |
|---|
| 406 |
} |
|---|
| 407 |
return $result; |
|---|
| 408 |
} |
|---|
| 409 |
|
|---|
| 410 |
|
|---|
| 411 |
* Validates an email address |
|---|
| 412 |
* |
|---|
| 413 |
* This function will make sure an e-mail is RFC822 compliant |
|---|
| 414 |
* and is not black listed. |
|---|
| 415 |
* |
|---|
| 416 |
* @param string $mail The email address to validate |
|---|
| 417 |
* |
|---|
| 418 |
* @return bool Returns whether the email address is valid or not |
|---|
| 419 |
* |
|---|
| 420 |
* @static |
|---|
| 421 |
* @access public |
|---|
| 422 |
*/ |
|---|
| 423 |
public static function validateEmailAddress($email) { |
|---|
| 424 |
|
|---|
| 425 |
$_matches = null; |
|---|
| 426 |
$_retVal = false; |
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
$regex = "/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i"; |
|---|
| 430 |
|
|---|
| 431 |
if (preg_match_all($regex, $email, $_matches)) { |
|---|
| 432 |
|
|---|
| 433 |
$full_hostname = $_matches[2][0] . "." . $_matches[3][0]; |
|---|
| 434 |
|
|---|
| 435 |
if (!in_array(strtolower($full_hostname), self :: $_hosts_black_list)) { |
|---|
| 436 |
$_retVal = true; |
|---|
| 437 |
} |
|---|
| 438 |
} |
|---|
| 439 |
|
|---|
| 440 |
return $_retVal; |
|---|
| 441 |
} |
|---|
| 442 |
|
|---|
| 443 |
} |
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|