| 50 | | // Business domain attributes |
| 51 | | private $from_name; |
| 52 | | private $from_email; |
| 53 | | private $to_name; |
| 54 | | private $to_email; |
| 55 | | private $subject; |
| 56 | | private $body; |
| | 51 | // List of fake e-mails hosts |
| | 52 | private static $_hosts_black_list = array ("simplicato.net", "mytrashmail.com", "spamhole.com", "mailexpire.com", "sneakemail.com", "spamex.com", "emailias.com", "mymailoasis.com", "spamcon.org", "spamgourmet.com", "spammotel.com", "dodgeit.com"); |
| 62 | | private function encodeMimeHeader($header) |
| 63 | | { |
| 64 | | // BASE 64 according to the RFC |
| 65 | | // Taken from : www.php.net mb_send_mail comments |
| 66 | | $header = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $header); |
| 67 | | $header = str_replace(' ', '_', $header); |
| 68 | | return "=?utf-8?Q?$header?="; |
| 69 | | } |
| | 62 | public function __construct() |
| | 63 | { |
| | 64 | } |
| 71 | | public function getMessageBody() |
| 72 | | { |
| 73 | | return $this->body; |
| 74 | | } |
| | 66 | private function encodeMimeHeader($header) |
| | 67 | { |
| | 68 | // BASE 64 according to the RFC |
| | 69 | // Taken from : www.php.net mb_send_mail comments |
| | 70 | $header = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $header); |
| | 71 | $header = str_replace(' ', '_', $header); |
| | 72 | return "=?utf-8?Q?$header?="; |
| | 73 | } |
| 101 | | // Packs e-mail and send it according to RFC822 |
| 102 | | public function send() |
| 103 | | { |
| 104 | | $headers = "From: \"".$this->getSenderName()."\" <".$this->getSenderEmail().">\r\n"; |
| 105 | | $headers .= "Reply-To: ".$this->getSenderEmail()."\r\n"; |
| 106 | | $headers .= "Content-Type: text/plain; charset=utf-8"; |
| 107 | | $args = "-f".$this->getSenderEmail(); |
| 108 | | return mail($this->getRecipientEmail(), $this->getMessageSubject(), $this->getMessageBody(), $headers, $args); |
| 109 | | } |
| | 100 | public function getSenderEmail() |
| | 101 | { |
| | 102 | return $this->from_email; |
| | 103 | } |
| 111 | | public function setMessageBody($body) |
| 112 | | { |
| 113 | | $this->body = $body; |
| 114 | | } |
| | 105 | // Packs e-mail and send it according to RFC822 |
| | 106 | public function send() |
| | 107 | { |
| | 108 | $headers = "From: \"".$this->getSenderName()."\" <".$this->getSenderEmail().">\r\n"; |
| | 109 | $headers .= "Reply-To: ".$this->getSenderEmail()."\r\n"; |
| | 110 | $headers .= "Content-Type: text/plain; charset=utf-8"; |
| | 111 | $args = "-f".$this->getSenderEmail(); |
| | 112 | return mail($this->getRecipientEmail(), $this->getMessageSubject(), $this->getMessageBody(), $headers, $args); |
| | 113 | } |
| 132 | | public function setSenderEmail($mail) |
| 133 | | { |
| 134 | | $this->from_email = $mail; |
| 135 | | } |
| | 130 | public function setSenderName($name) |
| | 131 | { |
| | 132 | // Encode header |
| | 133 | $this->from_name = $this->encodeMimeHeader($name); |
| | 134 | } |
| | 135 | |
| | 136 | public function setSenderEmail($mail) |
| | 137 | { |
| | 138 | $this->from_email = $mail; |
| | 139 | } |
| | 140 | |
| | 141 | /** |
| | 142 | * Validates an e-mail address |
| | 143 | * |
| | 144 | * This function will make sure an e-mail is RFC822 compliant |
| | 145 | * and is not black listed. |
| | 146 | * |
| | 147 | * Here's an example of how to use the function: |
| | 148 | * <code> |
| | 149 | * Mail::validateEmailAddress($mail); |
| | 150 | * </code> |
| | 151 | * |
| | 152 | * @param string $mail The e-mail address to validate |
| | 153 | * |
| | 154 | * @return boolean Returns whether the e-mail is valid or not |
| | 155 | * |
| | 156 | * @access public |
| | 157 | * @static |
| | 158 | */ |
| | 159 | public static function validateEmailAddress($email) |
| | 160 | { |
| | 161 | $matches = null; |
| | 162 | // Test if the email matches the regexp |
| | 163 | $regex = "/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i"; |
| | 164 | if (preg_match_all($regex, $email, $matches)) |
| | 165 | { |
| | 166 | // If the hostname is black listed, reject the e-mail. |
| | 167 | $full_hostname = $matches[2][0].".".$matches[3][0]; |
| | 168 | if(in_array($full_hostname, self::$_hosts_black_list)) |
| | 169 | return false; |
| | 170 | else |
| | 171 | return true; |
| | 172 | } |
| | 173 | else |
| | 174 | return false; |
| | 175 | } |
| | 176 | |