Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author ExpressionEngine Dev Team |
Greg Aker | 0711dc8 | 2011-01-05 10:49:40 -0600 | [diff] [blame] | 9 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html |
| 11 | * @link http://codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * CodeIgniter Email Class |
| 20 | * |
| 21 | * Permits email to be sent using Mail, Sendmail, or SMTP. |
| 22 | * |
| 23 | * @package CodeIgniter |
| 24 | * @subpackage Libraries |
| 25 | * @category Libraries |
| 26 | * @author ExpressionEngine Dev Team |
| 27 | * @link http://codeigniter.com/user_guide/libraries/email.html |
| 28 | */ |
| 29 | class CI_Email { |
| 30 | |
| 31 | var $useragent = "CodeIgniter"; |
| 32 | var $mailpath = "/usr/sbin/sendmail"; // Sendmail path |
| 33 | var $protocol = "mail"; // mail/sendmail/smtp |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 34 | var $smtp_host = ""; // SMTP Server. Example: mail.earthlink.net |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | var $smtp_user = ""; // SMTP Username |
| 36 | var $smtp_pass = ""; // SMTP Password |
| 37 | var $smtp_port = "25"; // SMTP Port |
| 38 | var $smtp_timeout = 5; // SMTP Timeout in seconds |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 39 | var $smtp_crypto = ""; // SMTP Encryption. Can be null, tls or ssl. |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 40 | var $wordwrap = TRUE; // TRUE/FALSE Turns word-wrap on/off |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 41 | var $wrapchars = "76"; // Number of characters to wrap at. |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 42 | var $mailtype = "text"; // text/html Defines email formatting |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 43 | var $charset = "utf-8"; // Default char set: iso-8859-1 or us-ascii |
| 44 | var $multipart = "mixed"; // "mixed" (in the body) or "related" (separate) |
| 45 | var $alt_message = ''; // Alternative message for HTML emails |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 46 | var $validate = FALSE; // TRUE/FALSE. Enables email validation |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 47 | var $priority = "3"; // Default priority (1 - 5) |
| 48 | var $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822) |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 49 | var $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers, |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 50 | // even on the receiving end think they need to muck with CRLFs, so using "\n", while |
| 51 | // distasteful, is the only thing that seems to work for all environments. |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 52 | var $send_multipart = TRUE; // TRUE/FALSE - Yahoo does not like multipart alternative, so this is an override. Set to FALSE for Yahoo. |
| 53 | var $bcc_batch_mode = FALSE; // TRUE/FALSE Turns on/off Bcc batch feature |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 54 | var $bcc_batch_size = 200; // If bcc_batch_mode = TRUE, sets max number of Bccs in each batch |
| 55 | var $_safe_mode = FALSE; |
| 56 | var $_subject = ""; |
| 57 | var $_body = ""; |
| 58 | var $_finalbody = ""; |
| 59 | var $_alt_boundary = ""; |
| 60 | var $_atc_boundary = ""; |
| 61 | var $_header_str = ""; |
| 62 | var $_smtp_connect = ""; |
| 63 | var $_encoding = "8bit"; |
| 64 | var $_IP = FALSE; |
| 65 | var $_smtp_auth = FALSE; |
| 66 | var $_replyto_flag = FALSE; |
| 67 | var $_debug_msg = array(); |
| 68 | var $_recipients = array(); |
| 69 | var $_cc_array = array(); |
| 70 | var $_bcc_array = array(); |
| 71 | var $_headers = array(); |
| 72 | var $_attach_name = array(); |
| 73 | var $_attach_type = array(); |
| 74 | var $_attach_disp = array(); |
| 75 | var $_protocols = array('mail', 'sendmail', 'smtp'); |
| 76 | var $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix) |
| 77 | var $_bit_depths = array('7bit', '8bit'); |
| 78 | var $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)'); |
| 79 | |
| 80 | |
| 81 | /** |
| 82 | * Constructor - Sets Email Preferences |
| 83 | * |
| 84 | * The constructor can be passed an array of config values |
| 85 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 86 | public function __construct($config = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 87 | { |
| 88 | if (count($config) > 0) |
| 89 | { |
| 90 | $this->initialize($config); |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; |
| 95 | $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; |
| 96 | } |
| 97 | |
| 98 | log_message('debug', "Email Class Initialized"); |
| 99 | } |
| 100 | |
| 101 | // -------------------------------------------------------------------- |
| 102 | |
| 103 | /** |
| 104 | * Initialize preferences |
| 105 | * |
| 106 | * @access public |
| 107 | * @param array |
| 108 | * @return void |
| 109 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 110 | public function initialize($config = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 111 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 112 | foreach ($config as $key => $val) |
| 113 | { |
| 114 | if (isset($this->$key)) |
| 115 | { |
| 116 | $method = 'set_'.$key; |
| 117 | |
| 118 | if (method_exists($this, $method)) |
| 119 | { |
| 120 | $this->$method($val); |
| 121 | } |
| 122 | else |
| 123 | { |
| 124 | $this->$key = $val; |
| 125 | } |
| 126 | } |
| 127 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 128 | $this->clear(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 129 | |
| 130 | $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; |
| 131 | $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 132 | |
| 133 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 134 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 135 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 136 | // -------------------------------------------------------------------- |
| 137 | |
| 138 | /** |
| 139 | * Initialize the Email Data |
| 140 | * |
| 141 | * @access public |
Bo-Yi Wu | 83320eb | 2011-09-15 13:28:02 +0800 | [diff] [blame] | 142 | * @param bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 143 | * @return void |
| 144 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 145 | public function clear($clear_attachments = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 146 | { |
| 147 | $this->_subject = ""; |
| 148 | $this->_body = ""; |
| 149 | $this->_finalbody = ""; |
| 150 | $this->_header_str = ""; |
| 151 | $this->_replyto_flag = FALSE; |
| 152 | $this->_recipients = array(); |
Derek Jones | d160635 | 2010-09-01 11:16:07 -0500 | [diff] [blame] | 153 | $this->_cc_array = array(); |
| 154 | $this->_bcc_array = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 155 | $this->_headers = array(); |
| 156 | $this->_debug_msg = array(); |
| 157 | |
| 158 | $this->_set_header('User-Agent', $this->useragent); |
| 159 | $this->_set_header('Date', $this->_set_date()); |
| 160 | |
| 161 | if ($clear_attachments !== FALSE) |
| 162 | { |
| 163 | $this->_attach_name = array(); |
| 164 | $this->_attach_type = array(); |
| 165 | $this->_attach_disp = array(); |
| 166 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 167 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 168 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 169 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 170 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 171 | // -------------------------------------------------------------------- |
| 172 | |
| 173 | /** |
| 174 | * Set FROM |
| 175 | * |
| 176 | * @access public |
| 177 | * @param string |
| 178 | * @param string |
| 179 | * @return void |
| 180 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 181 | public function from($from, $name = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | { |
| 183 | if (preg_match( '/\<(.*)\>/', $from, $match)) |
| 184 | { |
| 185 | $from = $match['1']; |
| 186 | } |
| 187 | |
| 188 | if ($this->validate) |
| 189 | { |
| 190 | $this->validate_email($this->_str_to_array($from)); |
| 191 | } |
| 192 | |
| 193 | // prepare the display name |
| 194 | if ($name != '') |
| 195 | { |
| 196 | // only use Q encoding if there are characters that would require it |
| 197 | if ( ! preg_match('/[\200-\377]/', $name)) |
| 198 | { |
| 199 | // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes |
Derek Jones | c630bcf | 2008-11-17 21:09:45 +0000 | [diff] [blame] | 200 | $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 201 | } |
| 202 | else |
| 203 | { |
| 204 | $name = $this->_prep_q_encoding($name, TRUE); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | $this->_set_header('From', $name.' <'.$from.'>'); |
| 209 | $this->_set_header('Return-Path', '<'.$from.'>'); |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 210 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 211 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 213 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 214 | // -------------------------------------------------------------------- |
| 215 | |
| 216 | /** |
| 217 | * Set Reply-to |
| 218 | * |
| 219 | * @access public |
| 220 | * @param string |
| 221 | * @param string |
| 222 | * @return void |
| 223 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 224 | public function reply_to($replyto, $name = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 225 | { |
| 226 | if (preg_match( '/\<(.*)\>/', $replyto, $match)) |
| 227 | { |
| 228 | $replyto = $match['1']; |
| 229 | } |
| 230 | |
| 231 | if ($this->validate) |
| 232 | { |
| 233 | $this->validate_email($this->_str_to_array($replyto)); |
| 234 | } |
| 235 | |
| 236 | if ($name == '') |
| 237 | { |
| 238 | $name = $replyto; |
| 239 | } |
| 240 | |
| 241 | if (strncmp($name, '"', 1) != 0) |
| 242 | { |
| 243 | $name = '"'.$name.'"'; |
| 244 | } |
| 245 | |
| 246 | $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); |
| 247 | $this->_replyto_flag = TRUE; |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 248 | |
| 249 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 250 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 251 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 252 | // -------------------------------------------------------------------- |
| 253 | |
| 254 | /** |
| 255 | * Set Recipients |
| 256 | * |
| 257 | * @access public |
| 258 | * @param string |
| 259 | * @return void |
| 260 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 261 | public function to($to) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 262 | { |
| 263 | $to = $this->_str_to_array($to); |
| 264 | $to = $this->clean_email($to); |
| 265 | |
| 266 | if ($this->validate) |
| 267 | { |
| 268 | $this->validate_email($to); |
| 269 | } |
| 270 | |
| 271 | if ($this->_get_protocol() != 'mail') |
| 272 | { |
| 273 | $this->_set_header('To', implode(", ", $to)); |
| 274 | } |
| 275 | |
| 276 | switch ($this->_get_protocol()) |
| 277 | { |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 278 | case 'smtp' : |
| 279 | $this->_recipients = $to; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 280 | break; |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 281 | case 'sendmail' : |
| 282 | case 'mail' : |
| 283 | $this->_recipients = implode(", ", $to); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 284 | break; |
| 285 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 286 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 287 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 289 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 290 | // -------------------------------------------------------------------- |
| 291 | |
| 292 | /** |
| 293 | * Set CC |
| 294 | * |
| 295 | * @access public |
| 296 | * @param string |
| 297 | * @return void |
| 298 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 299 | public function cc($cc) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 300 | { |
| 301 | $cc = $this->_str_to_array($cc); |
| 302 | $cc = $this->clean_email($cc); |
| 303 | |
| 304 | if ($this->validate) |
| 305 | { |
| 306 | $this->validate_email($cc); |
| 307 | } |
| 308 | |
| 309 | $this->_set_header('Cc', implode(", ", $cc)); |
| 310 | |
| 311 | if ($this->_get_protocol() == "smtp") |
| 312 | { |
| 313 | $this->_cc_array = $cc; |
| 314 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 315 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 316 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 317 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 318 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 319 | // -------------------------------------------------------------------- |
| 320 | |
| 321 | /** |
| 322 | * Set BCC |
| 323 | * |
| 324 | * @access public |
| 325 | * @param string |
| 326 | * @param string |
| 327 | * @return void |
| 328 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 329 | public function bcc($bcc, $limit = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 330 | { |
| 331 | if ($limit != '' && is_numeric($limit)) |
| 332 | { |
| 333 | $this->bcc_batch_mode = TRUE; |
| 334 | $this->bcc_batch_size = $limit; |
| 335 | } |
| 336 | |
| 337 | $bcc = $this->_str_to_array($bcc); |
| 338 | $bcc = $this->clean_email($bcc); |
| 339 | |
| 340 | if ($this->validate) |
| 341 | { |
| 342 | $this->validate_email($bcc); |
| 343 | } |
| 344 | |
| 345 | if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) |
| 346 | { |
| 347 | $this->_bcc_array = $bcc; |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | $this->_set_header('Bcc', implode(", ", $bcc)); |
| 352 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 353 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 354 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 355 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 356 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 357 | // -------------------------------------------------------------------- |
| 358 | |
| 359 | /** |
| 360 | * Set Email Subject |
| 361 | * |
| 362 | * @access public |
| 363 | * @param string |
| 364 | * @return void |
| 365 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 366 | public function subject($subject) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 367 | { |
| 368 | $subject = $this->_prep_q_encoding($subject); |
| 369 | $this->_set_header('Subject', $subject); |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 370 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 371 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 372 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 373 | // -------------------------------------------------------------------- |
| 374 | |
| 375 | /** |
| 376 | * Set Body |
| 377 | * |
| 378 | * @access public |
| 379 | * @param string |
| 380 | * @return void |
| 381 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 382 | public function message($body) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 383 | { |
diegorivera | 33c3280 | 2011-10-19 02:56:15 -0200 | [diff] [blame] | 384 | $this->_body = rtrim(str_replace("\r", "", $body)); |
| 385 | |
Andrey Andreev | af72862 | 2011-10-20 10:11:59 +0300 | [diff] [blame^] | 386 | /* strip slashes only if magic quotes is ON |
| 387 | if we do it with magic quotes OFF, it strips real, user-inputted chars. |
| 388 | |
| 389 | NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and |
| 390 | it will probably not exist in future versions at all. |
| 391 | */ |
| 392 | if ( ! is_php('5.4') && get_magic_quotes_gpc()) |
diegorivera | 9fca615 | 2011-10-19 11:18:45 -0200 | [diff] [blame] | 393 | { |
diegorivera | 33c3280 | 2011-10-19 02:56:15 -0200 | [diff] [blame] | 394 | $this->_body = stripslashes($this->_body); |
diegorivera | 9fca615 | 2011-10-19 11:18:45 -0200 | [diff] [blame] | 395 | } |
diegorivera | 33c3280 | 2011-10-19 02:56:15 -0200 | [diff] [blame] | 396 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 397 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 398 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 399 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 400 | // -------------------------------------------------------------------- |
| 401 | |
| 402 | /** |
| 403 | * Assign file attachments |
| 404 | * |
| 405 | * @access public |
| 406 | * @param string |
| 407 | * @return void |
| 408 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 409 | public function attach($filename, $disposition = 'attachment') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 410 | { |
| 411 | $this->_attach_name[] = $filename; |
Phil Sturgeon | 0aaf42b | 2011-08-10 08:06:37 -0600 | [diff] [blame] | 412 | $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 413 | $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 414 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | // -------------------------------------------------------------------- |
| 418 | |
| 419 | /** |
| 420 | * Add a Header Item |
| 421 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 422 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 423 | * @param string |
| 424 | * @param string |
| 425 | * @return void |
| 426 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 427 | protected function _set_header($header, $value) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 428 | { |
| 429 | $this->_headers[$header] = $value; |
| 430 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 431 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 432 | // -------------------------------------------------------------------- |
| 433 | |
| 434 | /** |
| 435 | * Convert a String to an Array |
| 436 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 437 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 438 | * @param string |
| 439 | * @return array |
| 440 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 441 | protected function _str_to_array($email) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 442 | { |
| 443 | if ( ! is_array($email)) |
| 444 | { |
| 445 | if (strpos($email, ',') !== FALSE) |
| 446 | { |
| 447 | $email = preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY); |
| 448 | } |
| 449 | else |
| 450 | { |
| 451 | $email = trim($email); |
| 452 | settype($email, "array"); |
| 453 | } |
| 454 | } |
| 455 | return $email; |
| 456 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 457 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 458 | // -------------------------------------------------------------------- |
| 459 | |
| 460 | /** |
| 461 | * Set Multipart Value |
| 462 | * |
| 463 | * @access public |
| 464 | * @param string |
| 465 | * @return void |
| 466 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 467 | public function set_alt_message($str = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 468 | { |
Dan Horrigan | d0ddeaf | 2011-08-21 09:07:27 -0400 | [diff] [blame] | 469 | $this->alt_message = (string) $str; |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 470 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 471 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 472 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 473 | // -------------------------------------------------------------------- |
| 474 | |
| 475 | /** |
| 476 | * Set Mailtype |
| 477 | * |
| 478 | * @access public |
| 479 | * @param string |
| 480 | * @return void |
| 481 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 482 | public function set_mailtype($type = 'text') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 483 | { |
| 484 | $this->mailtype = ($type == 'html') ? 'html' : 'text'; |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 485 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 486 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 487 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 488 | // -------------------------------------------------------------------- |
| 489 | |
| 490 | /** |
| 491 | * Set Wordwrap |
| 492 | * |
| 493 | * @access public |
Dan Horrigan | 628e660 | 2011-08-21 09:08:31 -0400 | [diff] [blame] | 494 | * @param bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 495 | * @return void |
| 496 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 497 | public function set_wordwrap($wordwrap = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 498 | { |
Dan Horrigan | 628e660 | 2011-08-21 09:08:31 -0400 | [diff] [blame] | 499 | $this->wordwrap = (bool) $wordwrap; |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 500 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 501 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 502 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 503 | // -------------------------------------------------------------------- |
| 504 | |
| 505 | /** |
| 506 | * Set Protocol |
| 507 | * |
| 508 | * @access public |
| 509 | * @param string |
| 510 | * @return void |
| 511 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 512 | public function set_protocol($protocol = 'mail') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 513 | { |
| 514 | $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 515 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 516 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 517 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 518 | // -------------------------------------------------------------------- |
| 519 | |
| 520 | /** |
| 521 | * Set Priority |
| 522 | * |
| 523 | * @access public |
| 524 | * @param integer |
| 525 | * @return void |
| 526 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 527 | public function set_priority($n = 3) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 528 | { |
| 529 | if ( ! is_numeric($n)) |
| 530 | { |
| 531 | $this->priority = 3; |
| 532 | return; |
| 533 | } |
| 534 | |
| 535 | if ($n < 1 OR $n > 5) |
| 536 | { |
| 537 | $this->priority = 3; |
| 538 | return; |
| 539 | } |
| 540 | |
| 541 | $this->priority = $n; |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 542 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 543 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 544 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 545 | // -------------------------------------------------------------------- |
| 546 | |
| 547 | /** |
| 548 | * Set Newline Character |
| 549 | * |
| 550 | * @access public |
| 551 | * @param string |
| 552 | * @return void |
| 553 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 554 | public function set_newline($newline = "\n") |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 555 | { |
| 556 | if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r") |
| 557 | { |
| 558 | $this->newline = "\n"; |
| 559 | return; |
| 560 | } |
| 561 | |
| 562 | $this->newline = $newline; |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 563 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 564 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 565 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 566 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 567 | // -------------------------------------------------------------------- |
| 568 | |
| 569 | /** |
| 570 | * Set CRLF |
| 571 | * |
| 572 | * @access public |
| 573 | * @param string |
| 574 | * @return void |
| 575 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 576 | public function set_crlf($crlf = "\n") |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 577 | { |
| 578 | if ($crlf != "\n" AND $crlf != "\r\n" AND $crlf != "\r") |
| 579 | { |
| 580 | $this->crlf = "\n"; |
| 581 | return; |
| 582 | } |
| 583 | |
| 584 | $this->crlf = $crlf; |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 585 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 586 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 587 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 588 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 589 | // -------------------------------------------------------------------- |
| 590 | |
| 591 | /** |
| 592 | * Set Message Boundary |
| 593 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 594 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 595 | * @return void |
| 596 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 597 | protected function _set_boundaries() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 598 | { |
| 599 | $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative |
| 600 | $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary |
| 601 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 602 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 603 | // -------------------------------------------------------------------- |
| 604 | |
| 605 | /** |
| 606 | * Get the Message ID |
| 607 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 608 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 609 | * @return string |
| 610 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 611 | protected function _get_message_id() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 612 | { |
| 613 | $from = $this->_headers['Return-Path']; |
| 614 | $from = str_replace(">", "", $from); |
| 615 | $from = str_replace("<", "", $from); |
| 616 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 617 | return "<".uniqid('').strstr($from, '@').">"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 618 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 619 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 620 | // -------------------------------------------------------------------- |
| 621 | |
| 622 | /** |
| 623 | * Get Mail Protocol |
| 624 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 625 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 626 | * @param bool |
| 627 | * @return string |
| 628 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 629 | protected function _get_protocol($return = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 630 | { |
| 631 | $this->protocol = strtolower($this->protocol); |
| 632 | $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; |
| 633 | |
| 634 | if ($return == TRUE) |
| 635 | { |
| 636 | return $this->protocol; |
| 637 | } |
| 638 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 639 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 640 | // -------------------------------------------------------------------- |
| 641 | |
| 642 | /** |
| 643 | * Get Mail Encoding |
| 644 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 645 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 646 | * @param bool |
| 647 | * @return string |
| 648 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 649 | protected function _get_encoding($return = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 650 | { |
| 651 | $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding; |
| 652 | |
| 653 | foreach ($this->_base_charsets as $charset) |
| 654 | { |
| 655 | if (strncmp($charset, $this->charset, strlen($charset)) == 0) |
| 656 | { |
| 657 | $this->_encoding = '7bit'; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | if ($return == TRUE) |
| 662 | { |
| 663 | return $this->_encoding; |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | // -------------------------------------------------------------------- |
| 668 | |
| 669 | /** |
| 670 | * Get content type (text/html/attachment) |
| 671 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 672 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 673 | * @return string |
| 674 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 675 | protected function _get_content_type() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 676 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 677 | if ($this->mailtype == 'html' && count($this->_attach_name) == 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 678 | { |
| 679 | return 'html'; |
| 680 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 681 | elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 682 | { |
| 683 | return 'html-attach'; |
| 684 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 685 | elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 686 | { |
| 687 | return 'plain-attach'; |
| 688 | } |
| 689 | else |
| 690 | { |
| 691 | return 'plain'; |
| 692 | } |
| 693 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 694 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 695 | // -------------------------------------------------------------------- |
| 696 | |
| 697 | /** |
| 698 | * Set RFC 822 Date |
| 699 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 700 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 701 | * @return string |
| 702 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 703 | protected function _set_date() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 704 | { |
| 705 | $timezone = date("Z"); |
| 706 | $operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+'; |
| 707 | $timezone = abs($timezone); |
| 708 | $timezone = floor($timezone/3600) * 100 + ($timezone % 3600 ) / 60; |
| 709 | |
| 710 | return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); |
| 711 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 712 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 713 | // -------------------------------------------------------------------- |
| 714 | |
| 715 | /** |
| 716 | * Mime message |
| 717 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 718 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 719 | * @return string |
| 720 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 721 | protected function _get_mime_message() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 722 | { |
| 723 | return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; |
| 724 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 725 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 726 | // -------------------------------------------------------------------- |
| 727 | |
| 728 | /** |
| 729 | * Validate Email Address |
| 730 | * |
| 731 | * @access public |
| 732 | * @param string |
| 733 | * @return bool |
| 734 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 735 | public function validate_email($email) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 736 | { |
| 737 | if ( ! is_array($email)) |
| 738 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 739 | $this->_set_error_message('lang:email_must_be_array'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 740 | return FALSE; |
| 741 | } |
| 742 | |
| 743 | foreach ($email as $val) |
| 744 | { |
| 745 | if ( ! $this->valid_email($val)) |
| 746 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 747 | $this->_set_error_message('lang:email_invalid_address', $val); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 748 | return FALSE; |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | return TRUE; |
| 753 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 754 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 755 | // -------------------------------------------------------------------- |
| 756 | |
| 757 | /** |
| 758 | * Email Validation |
| 759 | * |
| 760 | * @access public |
| 761 | * @param string |
| 762 | * @return bool |
| 763 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 764 | public function valid_email($address) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 765 | { |
| 766 | return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; |
| 767 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 768 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 769 | // -------------------------------------------------------------------- |
| 770 | |
| 771 | /** |
| 772 | * Clean Extended Email Address: Joe Smith <joe@smith.com> |
| 773 | * |
| 774 | * @access public |
| 775 | * @param string |
| 776 | * @return string |
| 777 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 778 | public function clean_email($email) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 779 | { |
| 780 | if ( ! is_array($email)) |
| 781 | { |
| 782 | if (preg_match('/\<(.*)\>/', $email, $match)) |
| 783 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 784 | return $match['1']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 785 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 786 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 787 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 788 | return $email; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 789 | } |
| 790 | } |
| 791 | |
| 792 | $clean_email = array(); |
| 793 | |
| 794 | foreach ($email as $addy) |
| 795 | { |
| 796 | if (preg_match( '/\<(.*)\>/', $addy, $match)) |
| 797 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 798 | $clean_email[] = $match['1']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 799 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 800 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 801 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 802 | $clean_email[] = $addy; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | |
| 806 | return $clean_email; |
| 807 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 808 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 809 | // -------------------------------------------------------------------- |
| 810 | |
| 811 | /** |
| 812 | * Build alternative plain text message |
| 813 | * |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 814 | * This public function provides the raw message for use |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 815 | * in plain-text headers of HTML-formatted emails. |
| 816 | * If the user hasn't specified his own alternative message |
| 817 | * it creates one by stripping the HTML |
| 818 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 819 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 820 | * @return string |
| 821 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 822 | protected function _get_alt_message() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 823 | { |
| 824 | if ($this->alt_message != "") |
| 825 | { |
| 826 | return $this->word_wrap($this->alt_message, '76'); |
| 827 | } |
| 828 | |
| 829 | if (preg_match('/\<body.*?\>(.*)\<\/body\>/si', $this->_body, $match)) |
| 830 | { |
| 831 | $body = $match['1']; |
| 832 | } |
| 833 | else |
| 834 | { |
| 835 | $body = $this->_body; |
| 836 | } |
| 837 | |
| 838 | $body = trim(strip_tags($body)); |
| 839 | $body = preg_replace( '#<!--(.*)--\>#', "", $body); |
| 840 | $body = str_replace("\t", "", $body); |
| 841 | |
| 842 | for ($i = 20; $i >= 3; $i--) |
| 843 | { |
| 844 | $n = ""; |
| 845 | |
| 846 | for ($x = 1; $x <= $i; $x ++) |
| 847 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 848 | $n .= "\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | $body = str_replace($n, "\n\n", $body); |
| 852 | } |
| 853 | |
| 854 | return $this->word_wrap($body, '76'); |
| 855 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 856 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 857 | // -------------------------------------------------------------------- |
| 858 | |
| 859 | /** |
| 860 | * Word Wrap |
| 861 | * |
| 862 | * @access public |
| 863 | * @param string |
| 864 | * @param integer |
| 865 | * @return string |
| 866 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 867 | public function word_wrap($str, $charlim = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 868 | { |
| 869 | // Se the character limit |
| 870 | if ($charlim == '') |
| 871 | { |
| 872 | $charlim = ($this->wrapchars == "") ? "76" : $this->wrapchars; |
| 873 | } |
| 874 | |
| 875 | // Reduce multiple spaces |
| 876 | $str = preg_replace("| +|", " ", $str); |
| 877 | |
| 878 | // Standardize newlines |
| 879 | if (strpos($str, "\r") !== FALSE) |
| 880 | { |
| 881 | $str = str_replace(array("\r\n", "\r"), "\n", $str); |
| 882 | } |
| 883 | |
| 884 | // If the current word is surrounded by {unwrap} tags we'll |
| 885 | // strip the entire chunk and replace it with a marker. |
| 886 | $unwrap = array(); |
| 887 | if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) |
| 888 | { |
| 889 | for ($i = 0; $i < count($matches['0']); $i++) |
| 890 | { |
| 891 | $unwrap[] = $matches['1'][$i]; |
| 892 | $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); |
| 893 | } |
| 894 | } |
| 895 | |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 896 | // Use PHP's native public function to do the initial wordwrap. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 897 | // We set the cut flag to FALSE so that any individual words that are |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 898 | // too long get left alone. In the next step we'll deal with them. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 899 | $str = wordwrap($str, $charlim, "\n", FALSE); |
| 900 | |
| 901 | // Split the string into individual lines of text and cycle through them |
| 902 | $output = ""; |
| 903 | foreach (explode("\n", $str) as $line) |
| 904 | { |
| 905 | // Is the line within the allowed character count? |
| 906 | // If so we'll join it to the output and continue |
| 907 | if (strlen($line) <= $charlim) |
| 908 | { |
| 909 | $output .= $line.$this->newline; |
| 910 | continue; |
| 911 | } |
| 912 | |
| 913 | $temp = ''; |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 914 | while ((strlen($line)) > $charlim) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 915 | { |
| 916 | // If the over-length word is a URL we won't wrap it |
| 917 | if (preg_match("!\[url.+\]|://|wwww.!", $line)) |
| 918 | { |
| 919 | break; |
| 920 | } |
| 921 | |
| 922 | // Trim the word down |
| 923 | $temp .= substr($line, 0, $charlim-1); |
| 924 | $line = substr($line, $charlim-1); |
| 925 | } |
| 926 | |
| 927 | // If $temp contains data it means we had to split up an over-length |
| 928 | // word into smaller chunks so we'll add it back to our current line |
| 929 | if ($temp != '') |
| 930 | { |
| 931 | $output .= $temp.$this->newline.$line; |
| 932 | } |
| 933 | else |
| 934 | { |
| 935 | $output .= $line; |
| 936 | } |
| 937 | |
| 938 | $output .= $this->newline; |
| 939 | } |
| 940 | |
| 941 | // Put our markers back |
| 942 | if (count($unwrap) > 0) |
| 943 | { |
| 944 | foreach ($unwrap as $key => $val) |
| 945 | { |
| 946 | $output = str_replace("{{unwrapped".$key."}}", $val, $output); |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | return $output; |
| 951 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 952 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 953 | // -------------------------------------------------------------------- |
| 954 | |
| 955 | /** |
| 956 | * Build final headers |
| 957 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 958 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 959 | * @param string |
| 960 | * @return string |
| 961 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 962 | protected function _build_headers() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 963 | { |
| 964 | $this->_set_header('X-Sender', $this->clean_email($this->_headers['From'])); |
| 965 | $this->_set_header('X-Mailer', $this->useragent); |
| 966 | $this->_set_header('X-Priority', $this->_priorities[$this->priority - 1]); |
| 967 | $this->_set_header('Message-ID', $this->_get_message_id()); |
| 968 | $this->_set_header('Mime-Version', '1.0'); |
| 969 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 970 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 971 | // -------------------------------------------------------------------- |
| 972 | |
| 973 | /** |
| 974 | * Write Headers as a string |
| 975 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 976 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 977 | * @return void |
| 978 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 979 | protected function _write_headers() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 980 | { |
| 981 | if ($this->protocol == 'mail') |
| 982 | { |
| 983 | $this->_subject = $this->_headers['Subject']; |
| 984 | unset($this->_headers['Subject']); |
| 985 | } |
| 986 | |
| 987 | reset($this->_headers); |
| 988 | $this->_header_str = ""; |
| 989 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 990 | foreach ($this->_headers as $key => $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 991 | { |
| 992 | $val = trim($val); |
| 993 | |
| 994 | if ($val != "") |
| 995 | { |
| 996 | $this->_header_str .= $key.": ".$val.$this->newline; |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | if ($this->_get_protocol() == 'mail') |
| 1001 | { |
Derek Jones | 1d89088 | 2009-02-10 20:32:14 +0000 | [diff] [blame] | 1002 | $this->_header_str = rtrim($this->_header_str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1003 | } |
| 1004 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1005 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1006 | // -------------------------------------------------------------------- |
| 1007 | |
| 1008 | /** |
| 1009 | * Build Final Body and attachments |
| 1010 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1011 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1012 | * @return void |
| 1013 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1014 | protected function _build_message() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1015 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1016 | if ($this->wordwrap === TRUE AND $this->mailtype != 'html') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1017 | { |
| 1018 | $this->_body = $this->word_wrap($this->_body); |
| 1019 | } |
| 1020 | |
| 1021 | $this->_set_boundaries(); |
| 1022 | $this->_write_headers(); |
| 1023 | |
| 1024 | $hdr = ($this->_get_protocol() == 'mail') ? $this->newline : ''; |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1025 | $body = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1026 | |
| 1027 | switch ($this->_get_content_type()) |
| 1028 | { |
| 1029 | case 'plain' : |
| 1030 | |
| 1031 | $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; |
| 1032 | $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding(); |
| 1033 | |
| 1034 | if ($this->_get_protocol() == 'mail') |
| 1035 | { |
| 1036 | $this->_header_str .= $hdr; |
| 1037 | $this->_finalbody = $this->_body; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1038 | } |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1039 | else |
| 1040 | { |
| 1041 | $this->_finalbody = $hdr . $this->newline . $this->newline . $this->_body; |
| 1042 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1043 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1044 | return; |
| 1045 | |
| 1046 | break; |
| 1047 | case 'html' : |
| 1048 | |
| 1049 | if ($this->send_multipart === FALSE) |
| 1050 | { |
| 1051 | $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; |
| 1052 | $hdr .= "Content-Transfer-Encoding: quoted-printable"; |
| 1053 | } |
| 1054 | else |
| 1055 | { |
Derek Jones | a45e761 | 2009-02-10 18:33:01 +0000 | [diff] [blame] | 1056 | $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1057 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1058 | $body .= $this->_get_mime_message() . $this->newline . $this->newline; |
| 1059 | $body .= "--" . $this->_alt_boundary . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1060 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1061 | $body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; |
| 1062 | $body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; |
| 1063 | $body .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; |
| 1064 | |
| 1065 | $body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; |
| 1066 | $body .= "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1067 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1068 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1069 | $this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline; |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1070 | |
| 1071 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1072 | if ($this->_get_protocol() == 'mail') |
| 1073 | { |
| 1074 | $this->_header_str .= $hdr; |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1075 | } |
| 1076 | else |
| 1077 | { |
| 1078 | $this->_finalbody = $hdr . $this->_finalbody; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1081 | |
| 1082 | if ($this->send_multipart !== FALSE) |
| 1083 | { |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1084 | $this->_finalbody .= "--" . $this->_alt_boundary . "--"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1087 | return; |
| 1088 | |
| 1089 | break; |
| 1090 | case 'plain-attach' : |
| 1091 | |
Derek Jones | a45e761 | 2009-02-10 18:33:01 +0000 | [diff] [blame] | 1092 | $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1093 | |
| 1094 | if ($this->_get_protocol() == 'mail') |
| 1095 | { |
| 1096 | $this->_header_str .= $hdr; |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1097 | } |
| 1098 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1099 | $body .= $this->_get_mime_message() . $this->newline . $this->newline; |
| 1100 | $body .= "--" . $this->_atc_boundary . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1101 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1102 | $body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; |
| 1103 | $body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1104 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1105 | $body .= $this->_body . $this->newline . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1106 | |
| 1107 | break; |
| 1108 | case 'html-attach' : |
| 1109 | |
Derek Jones | a45e761 | 2009-02-10 18:33:01 +0000 | [diff] [blame] | 1110 | $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline; |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1111 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1112 | if ($this->_get_protocol() == 'mail') |
| 1113 | { |
| 1114 | $this->_header_str .= $hdr; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1117 | $body .= $this->_get_mime_message() . $this->newline . $this->newline; |
| 1118 | $body .= "--" . $this->_atc_boundary . $this->newline; |
| 1119 | |
| 1120 | $body .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline; |
| 1121 | $body .= "--" . $this->_alt_boundary . $this->newline; |
| 1122 | |
| 1123 | $body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; |
| 1124 | $body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; |
| 1125 | $body .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; |
| 1126 | |
| 1127 | $body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; |
| 1128 | $body .= "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline; |
| 1129 | |
| 1130 | $body .= $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline; |
| 1131 | $body .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1132 | |
| 1133 | break; |
| 1134 | } |
| 1135 | |
| 1136 | $attachment = array(); |
| 1137 | |
| 1138 | $z = 0; |
| 1139 | |
| 1140 | for ($i=0; $i < count($this->_attach_name); $i++) |
| 1141 | { |
| 1142 | $filename = $this->_attach_name[$i]; |
| 1143 | $basename = basename($filename); |
| 1144 | $ctype = $this->_attach_type[$i]; |
| 1145 | |
| 1146 | if ( ! file_exists($filename)) |
| 1147 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1148 | $this->_set_error_message('lang:email_attachment_missing', $filename); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1149 | return FALSE; |
| 1150 | } |
| 1151 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1152 | $h = "--".$this->_atc_boundary.$this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1153 | $h .= "Content-type: ".$ctype."; "; |
| 1154 | $h .= "name=\"".$basename."\"".$this->newline; |
| 1155 | $h .= "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline; |
| 1156 | $h .= "Content-Transfer-Encoding: base64".$this->newline; |
| 1157 | |
| 1158 | $attachment[$z++] = $h; |
| 1159 | $file = filesize($filename) +1; |
| 1160 | |
| 1161 | if ( ! $fp = fopen($filename, FOPEN_READ)) |
| 1162 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1163 | $this->_set_error_message('lang:email_attachment_unreadable', $filename); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1164 | return FALSE; |
| 1165 | } |
| 1166 | |
| 1167 | $attachment[$z++] = chunk_split(base64_encode(fread($fp, $file))); |
| 1168 | fclose($fp); |
| 1169 | } |
| 1170 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1171 | $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--"; |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1172 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1173 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1174 | if ($this->_get_protocol() == 'mail') |
| 1175 | { |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1176 | $this->_finalbody = $body; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1177 | } |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1178 | else |
| 1179 | { |
| 1180 | $this->_finalbody = $hdr . $body; |
| 1181 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1182 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1183 | return; |
| 1184 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1185 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1186 | // -------------------------------------------------------------------- |
| 1187 | |
| 1188 | /** |
| 1189 | * Prep Quoted Printable |
| 1190 | * |
| 1191 | * Prepares string for Quoted-Printable Content-Transfer-Encoding |
| 1192 | * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt |
| 1193 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1194 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1195 | * @param string |
| 1196 | * @param integer |
| 1197 | * @return string |
| 1198 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1199 | protected function _prep_quoted_printable($str, $charlim = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1200 | { |
| 1201 | // Set the character limit |
| 1202 | // Don't allow over 76, as that will make servers and MUAs barf |
| 1203 | // all over quoted-printable data |
| 1204 | if ($charlim == '' OR $charlim > '76') |
| 1205 | { |
| 1206 | $charlim = '76'; |
| 1207 | } |
| 1208 | |
| 1209 | // Reduce multiple spaces |
| 1210 | $str = preg_replace("| +|", " ", $str); |
| 1211 | |
| 1212 | // kill nulls |
| 1213 | $str = preg_replace('/\x00+/', '', $str); |
| 1214 | |
| 1215 | // Standardize newlines |
| 1216 | if (strpos($str, "\r") !== FALSE) |
| 1217 | { |
| 1218 | $str = str_replace(array("\r\n", "\r"), "\n", $str); |
| 1219 | } |
| 1220 | |
| 1221 | // We are intentionally wrapping so mail servers will encode characters |
| 1222 | // properly and MUAs will behave, so {unwrap} must go! |
| 1223 | $str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str); |
| 1224 | |
| 1225 | // Break into an array of lines |
| 1226 | $lines = explode("\n", $str); |
| 1227 | |
| 1228 | $escape = '='; |
| 1229 | $output = ''; |
| 1230 | |
| 1231 | foreach ($lines as $line) |
| 1232 | { |
| 1233 | $length = strlen($line); |
| 1234 | $temp = ''; |
| 1235 | |
| 1236 | // Loop through each character in the line to add soft-wrap |
| 1237 | // characters at the end of a line " =\r\n" and add the newly |
| 1238 | // processed line(s) to the output (see comment on $crlf class property) |
| 1239 | for ($i = 0; $i < $length; $i++) |
| 1240 | { |
| 1241 | // Grab the next character |
| 1242 | $char = substr($line, $i, 1); |
| 1243 | $ascii = ord($char); |
| 1244 | |
| 1245 | // Convert spaces and tabs but only if it's the end of the line |
| 1246 | if ($i == ($length - 1)) |
| 1247 | { |
| 1248 | $char = ($ascii == '32' OR $ascii == '9') ? $escape.sprintf('%02s', dechex($ascii)) : $char; |
| 1249 | } |
| 1250 | |
| 1251 | // encode = signs |
| 1252 | if ($ascii == '61') |
| 1253 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1254 | $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | // If we're at the character limit, add the line to the output, |
| 1258 | // reset our temp variable, and keep on chuggin' |
| 1259 | if ((strlen($temp) + strlen($char)) >= $charlim) |
| 1260 | { |
| 1261 | $output .= $temp.$escape.$this->crlf; |
| 1262 | $temp = ''; |
| 1263 | } |
| 1264 | |
| 1265 | // Add the character to our temporary line |
| 1266 | $temp .= $char; |
| 1267 | } |
| 1268 | |
| 1269 | // Add our completed line to the output |
| 1270 | $output .= $temp.$this->crlf; |
| 1271 | } |
| 1272 | |
| 1273 | // get rid of extra CRLF tacked onto the end |
| 1274 | $output = substr($output, 0, strlen($this->crlf) * -1); |
| 1275 | |
| 1276 | return $output; |
| 1277 | } |
| 1278 | |
| 1279 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1280 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1281 | /** |
| 1282 | * Prep Q Encoding |
| 1283 | * |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1284 | * Performs "Q Encoding" on a string for use in email headers. It's related |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1285 | * but not identical to quoted-printable, so it has its own method |
| 1286 | * |
| 1287 | * @access public |
| 1288 | * @param str |
| 1289 | * @param bool // set to TRUE for processing From: headers |
| 1290 | * @return str |
| 1291 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1292 | protected function _prep_q_encoding($str, $from = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1293 | { |
| 1294 | $str = str_replace(array("\r", "\n"), array('', ''), $str); |
| 1295 | |
| 1296 | // Line length must not exceed 76 characters, so we adjust for |
| 1297 | // a space, 7 extra characters =??Q??=, and the charset that we will add to each line |
| 1298 | $limit = 75 - 7 - strlen($this->charset); |
| 1299 | |
| 1300 | // these special characters must be converted too |
| 1301 | $convert = array('_', '=', '?'); |
| 1302 | |
| 1303 | if ($from === TRUE) |
| 1304 | { |
| 1305 | $convert[] = ','; |
| 1306 | $convert[] = ';'; |
| 1307 | } |
| 1308 | |
| 1309 | $output = ''; |
| 1310 | $temp = ''; |
| 1311 | |
| 1312 | for ($i = 0, $length = strlen($str); $i < $length; $i++) |
| 1313 | { |
| 1314 | // Grab the next character |
| 1315 | $char = substr($str, $i, 1); |
| 1316 | $ascii = ord($char); |
| 1317 | |
| 1318 | // convert ALL non-printable ASCII characters and our specials |
| 1319 | if ($ascii < 32 OR $ascii > 126 OR in_array($char, $convert)) |
| 1320 | { |
| 1321 | $char = '='.dechex($ascii); |
| 1322 | } |
| 1323 | |
| 1324 | // handle regular spaces a bit more compactly than =20 |
| 1325 | if ($ascii == 32) |
| 1326 | { |
| 1327 | $char = '_'; |
| 1328 | } |
| 1329 | |
| 1330 | // If we're at the character limit, add the line to the output, |
| 1331 | // reset our temp variable, and keep on chuggin' |
| 1332 | if ((strlen($temp) + strlen($char)) >= $limit) |
| 1333 | { |
| 1334 | $output .= $temp.$this->crlf; |
| 1335 | $temp = ''; |
| 1336 | } |
| 1337 | |
| 1338 | // Add the character to our temporary line |
| 1339 | $temp .= $char; |
| 1340 | } |
| 1341 | |
| 1342 | $str = $output.$temp; |
| 1343 | |
| 1344 | // wrap each line with the shebang, charset, and transfer encoding |
| 1345 | // the preceding space on successive lines is required for header "folding" |
| 1346 | $str = trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str)); |
| 1347 | |
| 1348 | return $str; |
| 1349 | } |
| 1350 | |
| 1351 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1352 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1353 | /** |
| 1354 | * Send Email |
| 1355 | * |
| 1356 | * @access public |
| 1357 | * @return bool |
| 1358 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 1359 | public function send() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1360 | { |
| 1361 | if ($this->_replyto_flag == FALSE) |
| 1362 | { |
| 1363 | $this->reply_to($this->_headers['From']); |
| 1364 | } |
| 1365 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1366 | if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1367 | ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND |
| 1368 | ( ! isset($this->_headers['Cc']))) |
| 1369 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1370 | $this->_set_error_message('lang:email_no_recipients'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1371 | return FALSE; |
| 1372 | } |
| 1373 | |
| 1374 | $this->_build_headers(); |
| 1375 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1376 | if ($this->bcc_batch_mode AND count($this->_bcc_array) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1377 | { |
| 1378 | if (count($this->_bcc_array) > $this->bcc_batch_size) |
| 1379 | return $this->batch_bcc_send(); |
| 1380 | } |
| 1381 | |
| 1382 | $this->_build_message(); |
| 1383 | |
| 1384 | if ( ! $this->_spool_email()) |
| 1385 | { |
| 1386 | return FALSE; |
| 1387 | } |
| 1388 | else |
| 1389 | { |
| 1390 | return TRUE; |
| 1391 | } |
| 1392 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1393 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1394 | // -------------------------------------------------------------------- |
| 1395 | |
| 1396 | /** |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1397 | * Batch Bcc Send. Sends groups of BCCs in batches |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1398 | * |
| 1399 | * @access public |
| 1400 | * @return bool |
| 1401 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 1402 | public function batch_bcc_send() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1403 | { |
| 1404 | $float = $this->bcc_batch_size -1; |
| 1405 | |
| 1406 | $set = ""; |
| 1407 | |
| 1408 | $chunk = array(); |
| 1409 | |
| 1410 | for ($i = 0; $i < count($this->_bcc_array); $i++) |
| 1411 | { |
| 1412 | if (isset($this->_bcc_array[$i])) |
| 1413 | { |
| 1414 | $set .= ", ".$this->_bcc_array[$i]; |
| 1415 | } |
| 1416 | |
| 1417 | if ($i == $float) |
| 1418 | { |
| 1419 | $chunk[] = substr($set, 1); |
| 1420 | $float = $float + $this->bcc_batch_size; |
| 1421 | $set = ""; |
| 1422 | } |
| 1423 | |
| 1424 | if ($i == count($this->_bcc_array)-1) |
| 1425 | { |
| 1426 | $chunk[] = substr($set, 1); |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | for ($i = 0; $i < count($chunk); $i++) |
| 1431 | { |
| 1432 | unset($this->_headers['Bcc']); |
| 1433 | unset($bcc); |
| 1434 | |
| 1435 | $bcc = $this->_str_to_array($chunk[$i]); |
| 1436 | $bcc = $this->clean_email($bcc); |
| 1437 | |
| 1438 | if ($this->protocol != 'smtp') |
| 1439 | { |
| 1440 | $this->_set_header('Bcc', implode(", ", $bcc)); |
| 1441 | } |
| 1442 | else |
| 1443 | { |
| 1444 | $this->_bcc_array = $bcc; |
| 1445 | } |
| 1446 | |
| 1447 | $this->_build_message(); |
| 1448 | $this->_spool_email(); |
| 1449 | } |
| 1450 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1451 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1452 | // -------------------------------------------------------------------- |
| 1453 | |
| 1454 | /** |
| 1455 | * Unwrap special elements |
| 1456 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1457 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1458 | * @return void |
| 1459 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1460 | protected function _unwrap_specials() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1461 | { |
| 1462 | $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody); |
| 1463 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1464 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1465 | // -------------------------------------------------------------------- |
| 1466 | |
| 1467 | /** |
| 1468 | * Strip line-breaks via callback |
| 1469 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1470 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1471 | * @return string |
| 1472 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1473 | protected function _remove_nl_callback($matches) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1474 | { |
| 1475 | if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE) |
| 1476 | { |
| 1477 | $matches[1] = str_replace(array("\r\n", "\r", "\n"), '', $matches[1]); |
| 1478 | } |
| 1479 | |
| 1480 | return $matches[1]; |
| 1481 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1482 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1483 | // -------------------------------------------------------------------- |
| 1484 | |
| 1485 | /** |
| 1486 | * Spool mail to the mail server |
| 1487 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1488 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1489 | * @return bool |
| 1490 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1491 | protected function _spool_email() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1492 | { |
| 1493 | $this->_unwrap_specials(); |
| 1494 | |
| 1495 | switch ($this->_get_protocol()) |
| 1496 | { |
| 1497 | case 'mail' : |
| 1498 | |
| 1499 | if ( ! $this->_send_with_mail()) |
| 1500 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1501 | $this->_set_error_message('lang:email_send_failure_phpmail'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1502 | return FALSE; |
| 1503 | } |
| 1504 | break; |
| 1505 | case 'sendmail' : |
| 1506 | |
| 1507 | if ( ! $this->_send_with_sendmail()) |
| 1508 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1509 | $this->_set_error_message('lang:email_send_failure_sendmail'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1510 | return FALSE; |
| 1511 | } |
| 1512 | break; |
| 1513 | case 'smtp' : |
| 1514 | |
| 1515 | if ( ! $this->_send_with_smtp()) |
| 1516 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1517 | $this->_set_error_message('lang:email_send_failure_smtp'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1518 | return FALSE; |
| 1519 | } |
| 1520 | break; |
| 1521 | |
| 1522 | } |
| 1523 | |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1524 | $this->_set_error_message('lang:email_sent', $this->_get_protocol()); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1525 | return TRUE; |
| 1526 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1527 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1528 | // -------------------------------------------------------------------- |
| 1529 | |
| 1530 | /** |
| 1531 | * Send using mail() |
| 1532 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1533 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1534 | * @return bool |
| 1535 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1536 | protected function _send_with_mail() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1537 | { |
| 1538 | if ($this->_safe_mode == TRUE) |
| 1539 | { |
| 1540 | if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str)) |
| 1541 | { |
| 1542 | return FALSE; |
| 1543 | } |
| 1544 | else |
| 1545 | { |
| 1546 | return TRUE; |
| 1547 | } |
| 1548 | } |
| 1549 | else |
| 1550 | { |
| 1551 | // most documentation of sendmail using the "-f" flag lacks a space after it, however |
| 1552 | // we've encountered servers that seem to require it to be in place. |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1553 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1554 | if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) |
| 1555 | { |
| 1556 | return FALSE; |
| 1557 | } |
| 1558 | else |
| 1559 | { |
| 1560 | return TRUE; |
| 1561 | } |
| 1562 | } |
| 1563 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1564 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1565 | // -------------------------------------------------------------------- |
| 1566 | |
| 1567 | /** |
| 1568 | * Send using Sendmail |
| 1569 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1570 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1571 | * @return bool |
| 1572 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1573 | protected function _send_with_sendmail() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1574 | { |
| 1575 | $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w'); |
| 1576 | |
Derek Jones | 4cefaa4 | 2009-04-29 19:13:56 +0000 | [diff] [blame] | 1577 | if ($fp === FALSE OR $fp === NULL) |
| 1578 | { |
| 1579 | // server probably has popen disabled, so nothing we can do to get a verbose error. |
| 1580 | return FALSE; |
| 1581 | } |
Derek Jones | 71141ce | 2010-03-02 16:41:20 -0600 | [diff] [blame] | 1582 | |
Derek Jones | c630bcf | 2008-11-17 21:09:45 +0000 | [diff] [blame] | 1583 | fputs($fp, $this->_header_str); |
| 1584 | fputs($fp, $this->_finalbody); |
| 1585 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1586 | $status = pclose($fp); |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1587 | |
Derek Jones | c630bcf | 2008-11-17 21:09:45 +0000 | [diff] [blame] | 1588 | if (version_compare(PHP_VERSION, '4.2.3') == -1) |
| 1589 | { |
| 1590 | $status = $status >> 8 & 0xFF; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1591 | } |
Derek Jones | 71141ce | 2010-03-02 16:41:20 -0600 | [diff] [blame] | 1592 | |
Derek Jones | 604873f | 2008-11-18 15:57:24 +0000 | [diff] [blame] | 1593 | if ($status != 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1594 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1595 | $this->_set_error_message('lang:email_exit_status', $status); |
| 1596 | $this->_set_error_message('lang:email_no_socket'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1597 | return FALSE; |
| 1598 | } |
| 1599 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1600 | return TRUE; |
| 1601 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1602 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1603 | // -------------------------------------------------------------------- |
| 1604 | |
| 1605 | /** |
| 1606 | * Send using SMTP |
| 1607 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1608 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1609 | * @return bool |
| 1610 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1611 | protected function _send_with_smtp() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1612 | { |
| 1613 | if ($this->smtp_host == '') |
| 1614 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1615 | $this->_set_error_message('lang:email_no_hostname'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1616 | return FALSE; |
| 1617 | } |
| 1618 | |
| 1619 | $this->_smtp_connect(); |
| 1620 | $this->_smtp_authenticate(); |
| 1621 | |
| 1622 | $this->_send_command('from', $this->clean_email($this->_headers['From'])); |
| 1623 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1624 | foreach ($this->_recipients as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1625 | { |
| 1626 | $this->_send_command('to', $val); |
| 1627 | } |
| 1628 | |
| 1629 | if (count($this->_cc_array) > 0) |
| 1630 | { |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1631 | foreach ($this->_cc_array as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1632 | { |
| 1633 | if ($val != "") |
| 1634 | { |
| 1635 | $this->_send_command('to', $val); |
| 1636 | } |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | if (count($this->_bcc_array) > 0) |
| 1641 | { |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1642 | foreach ($this->_bcc_array as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1643 | { |
| 1644 | if ($val != "") |
| 1645 | { |
| 1646 | $this->_send_command('to', $val); |
| 1647 | } |
| 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | $this->_send_command('data'); |
| 1652 | |
| 1653 | // perform dot transformation on any lines that begin with a dot |
| 1654 | $this->_send_data($this->_header_str . preg_replace('/^\./m', '..$1', $this->_finalbody)); |
| 1655 | |
| 1656 | $this->_send_data('.'); |
| 1657 | |
| 1658 | $reply = $this->_get_smtp_data(); |
| 1659 | |
| 1660 | $this->_set_error_message($reply); |
| 1661 | |
| 1662 | if (strncmp($reply, '250', 3) != 0) |
| 1663 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1664 | $this->_set_error_message('lang:email_smtp_error', $reply); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1665 | return FALSE; |
| 1666 | } |
| 1667 | |
| 1668 | $this->_send_command('quit'); |
| 1669 | return TRUE; |
| 1670 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1671 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1672 | // -------------------------------------------------------------------- |
| 1673 | |
| 1674 | /** |
| 1675 | * SMTP Connect |
| 1676 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1677 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1678 | * @param string |
| 1679 | * @return string |
| 1680 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1681 | protected function _smtp_connect() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1682 | { |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1683 | $ssl = NULL; |
Radu Potop | 4c589ae | 2011-09-29 10:19:55 +0300 | [diff] [blame] | 1684 | |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1685 | if ($this->smtp_crypto == 'ssl') |
Radu Potop | 4c589ae | 2011-09-29 10:19:55 +0300 | [diff] [blame] | 1686 | { |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1687 | $ssl = 'ssl://'; |
Radu Potop | 4c589ae | 2011-09-29 10:19:55 +0300 | [diff] [blame] | 1688 | } |
| 1689 | |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1690 | $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1691 | $this->smtp_port, |
| 1692 | $errno, |
| 1693 | $errstr, |
| 1694 | $this->smtp_timeout); |
| 1695 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1696 | if ( ! is_resource($this->_smtp_connect)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1697 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1698 | $this->_set_error_message('lang:email_smtp_error', $errno." ".$errstr); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1699 | return FALSE; |
| 1700 | } |
| 1701 | |
| 1702 | $this->_set_error_message($this->_get_smtp_data()); |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1703 | |
| 1704 | if ($this->smtp_crypto == 'tls') |
| 1705 | { |
| 1706 | $this->_send_command('hello'); |
| 1707 | $this->_send_command('starttls'); |
Radu Potop | 4c589ae | 2011-09-29 10:19:55 +0300 | [diff] [blame] | 1708 | $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); |
| 1709 | } |
| 1710 | |
| 1711 | if ($crypto !== TRUE) |
| 1712 | { |
| 1713 | $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data()); |
| 1714 | return FALSE; |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1715 | } |
| 1716 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1717 | return $this->_send_command('hello'); |
| 1718 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1719 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1720 | // -------------------------------------------------------------------- |
| 1721 | |
| 1722 | /** |
| 1723 | * Send SMTP command |
| 1724 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1725 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1726 | * @param string |
| 1727 | * @param string |
| 1728 | * @return string |
| 1729 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1730 | protected function _send_command($cmd, $data = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1731 | { |
| 1732 | switch ($cmd) |
| 1733 | { |
| 1734 | case 'hello' : |
| 1735 | |
| 1736 | if ($this->_smtp_auth OR $this->_get_encoding() == '8bit') |
| 1737 | $this->_send_data('EHLO '.$this->_get_hostname()); |
| 1738 | else |
| 1739 | $this->_send_data('HELO '.$this->_get_hostname()); |
| 1740 | |
| 1741 | $resp = 250; |
| 1742 | break; |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1743 | case 'starttls' : |
| 1744 | |
| 1745 | $this->_send_data('STARTTLS'); |
| 1746 | |
| 1747 | $resp = 220; |
| 1748 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1749 | case 'from' : |
| 1750 | |
| 1751 | $this->_send_data('MAIL FROM:<'.$data.'>'); |
| 1752 | |
| 1753 | $resp = 250; |
| 1754 | break; |
| 1755 | case 'to' : |
| 1756 | |
| 1757 | $this->_send_data('RCPT TO:<'.$data.'>'); |
| 1758 | |
| 1759 | $resp = 250; |
| 1760 | break; |
| 1761 | case 'data' : |
| 1762 | |
| 1763 | $this->_send_data('DATA'); |
| 1764 | |
| 1765 | $resp = 354; |
| 1766 | break; |
| 1767 | case 'quit' : |
| 1768 | |
| 1769 | $this->_send_data('QUIT'); |
| 1770 | |
| 1771 | $resp = 221; |
| 1772 | break; |
| 1773 | } |
| 1774 | |
| 1775 | $reply = $this->_get_smtp_data(); |
| 1776 | |
| 1777 | $this->_debug_msg[] = "<pre>".$cmd.": ".$reply."</pre>"; |
| 1778 | |
| 1779 | if (substr($reply, 0, 3) != $resp) |
| 1780 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1781 | $this->_set_error_message('lang:email_smtp_error', $reply); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1782 | return FALSE; |
| 1783 | } |
| 1784 | |
| 1785 | if ($cmd == 'quit') |
| 1786 | { |
| 1787 | fclose($this->_smtp_connect); |
| 1788 | } |
| 1789 | |
| 1790 | return TRUE; |
| 1791 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1792 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1793 | // -------------------------------------------------------------------- |
| 1794 | |
| 1795 | /** |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1796 | * SMTP Authenticate |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1797 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1798 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1799 | * @return bool |
| 1800 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1801 | protected function _smtp_authenticate() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1802 | { |
| 1803 | if ( ! $this->_smtp_auth) |
| 1804 | { |
| 1805 | return TRUE; |
| 1806 | } |
| 1807 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1808 | if ($this->smtp_user == "" AND $this->smtp_pass == "") |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1809 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1810 | $this->_set_error_message('lang:email_no_smtp_unpw'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1811 | return FALSE; |
| 1812 | } |
| 1813 | |
| 1814 | $this->_send_data('AUTH LOGIN'); |
| 1815 | |
| 1816 | $reply = $this->_get_smtp_data(); |
| 1817 | |
| 1818 | if (strncmp($reply, '334', 3) != 0) |
| 1819 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1820 | $this->_set_error_message('lang:email_failed_smtp_login', $reply); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1821 | return FALSE; |
| 1822 | } |
| 1823 | |
| 1824 | $this->_send_data(base64_encode($this->smtp_user)); |
| 1825 | |
| 1826 | $reply = $this->_get_smtp_data(); |
| 1827 | |
| 1828 | if (strncmp($reply, '334', 3) != 0) |
| 1829 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1830 | $this->_set_error_message('lang:email_smtp_auth_un', $reply); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1831 | return FALSE; |
| 1832 | } |
| 1833 | |
| 1834 | $this->_send_data(base64_encode($this->smtp_pass)); |
| 1835 | |
| 1836 | $reply = $this->_get_smtp_data(); |
| 1837 | |
| 1838 | if (strncmp($reply, '235', 3) != 0) |
| 1839 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1840 | $this->_set_error_message('lang:email_smtp_auth_pw', $reply); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1841 | return FALSE; |
| 1842 | } |
| 1843 | |
| 1844 | return TRUE; |
| 1845 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1846 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1847 | // -------------------------------------------------------------------- |
| 1848 | |
| 1849 | /** |
| 1850 | * Send SMTP data |
| 1851 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1852 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1853 | * @return bool |
| 1854 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1855 | protected function _send_data($data) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1856 | { |
| 1857 | if ( ! fwrite($this->_smtp_connect, $data . $this->newline)) |
| 1858 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1859 | $this->_set_error_message('lang:email_smtp_data_failure', $data); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1860 | return FALSE; |
| 1861 | } |
| 1862 | else |
| 1863 | { |
| 1864 | return TRUE; |
| 1865 | } |
| 1866 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1867 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1868 | // -------------------------------------------------------------------- |
| 1869 | |
| 1870 | /** |
| 1871 | * Get SMTP data |
| 1872 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1873 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1874 | * @return string |
| 1875 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1876 | protected function _get_smtp_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1877 | { |
| 1878 | $data = ""; |
| 1879 | |
| 1880 | while ($str = fgets($this->_smtp_connect, 512)) |
| 1881 | { |
| 1882 | $data .= $str; |
| 1883 | |
| 1884 | if (substr($str, 3, 1) == " ") |
| 1885 | { |
| 1886 | break; |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | return $data; |
| 1891 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1892 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1893 | // -------------------------------------------------------------------- |
| 1894 | |
| 1895 | /** |
| 1896 | * Get Hostname |
| 1897 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1898 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1899 | * @return string |
| 1900 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1901 | protected function _get_hostname() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1902 | { |
| 1903 | return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain'; |
| 1904 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1905 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1906 | // -------------------------------------------------------------------- |
| 1907 | |
| 1908 | /** |
| 1909 | * Get IP |
| 1910 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1911 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1912 | * @return string |
| 1913 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1914 | protected function _get_ip() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1915 | { |
| 1916 | if ($this->_IP !== FALSE) |
| 1917 | { |
| 1918 | return $this->_IP; |
| 1919 | } |
| 1920 | |
| 1921 | $cip = (isset($_SERVER['HTTP_CLIENT_IP']) AND $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE; |
| 1922 | $rip = (isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE; |
| 1923 | $fip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE; |
| 1924 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1925 | if ($cip && $rip) $this->_IP = $cip; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1926 | elseif ($rip) $this->_IP = $rip; |
| 1927 | elseif ($cip) $this->_IP = $cip; |
| 1928 | elseif ($fip) $this->_IP = $fip; |
| 1929 | |
Robin Sowell | 76b369e | 2010-03-19 11:15:28 -0400 | [diff] [blame] | 1930 | if (strpos($this->_IP, ',') !== FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1931 | { |
| 1932 | $x = explode(',', $this->_IP); |
| 1933 | $this->_IP = end($x); |
| 1934 | } |
| 1935 | |
| 1936 | if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP)) |
| 1937 | { |
| 1938 | $this->_IP = '0.0.0.0'; |
| 1939 | } |
| 1940 | |
| 1941 | unset($cip); |
| 1942 | unset($rip); |
| 1943 | unset($fip); |
| 1944 | |
| 1945 | return $this->_IP; |
| 1946 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1947 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1948 | // -------------------------------------------------------------------- |
| 1949 | |
| 1950 | /** |
| 1951 | * Get Debug Message |
| 1952 | * |
| 1953 | * @access public |
| 1954 | * @return string |
| 1955 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 1956 | public function print_debugger() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1957 | { |
| 1958 | $msg = ''; |
| 1959 | |
| 1960 | if (count($this->_debug_msg) > 0) |
| 1961 | { |
| 1962 | foreach ($this->_debug_msg as $val) |
| 1963 | { |
| 1964 | $msg .= $val; |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | $msg .= "<pre>".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>'; |
| 1969 | return $msg; |
| 1970 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1971 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1972 | // -------------------------------------------------------------------- |
| 1973 | |
| 1974 | /** |
| 1975 | * Set Message |
| 1976 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1977 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1978 | * @param string |
| 1979 | * @return string |
| 1980 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1981 | protected function _set_error_message($msg, $val = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1982 | { |
| 1983 | $CI =& get_instance(); |
| 1984 | $CI->lang->load('email'); |
| 1985 | |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1986 | if (substr($msg, 0, 5) != 'lang:' || FALSE === ($line = $CI->lang->line(substr($msg, 5)))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1987 | { |
| 1988 | $this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />"; |
| 1989 | } |
| 1990 | else |
| 1991 | { |
| 1992 | $this->_debug_msg[] = str_replace('%s', $val, $line)."<br />"; |
| 1993 | } |
| 1994 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1995 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1996 | // -------------------------------------------------------------------- |
| 1997 | |
| 1998 | /** |
| 1999 | * Mime Types |
| 2000 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 2001 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2002 | * @param string |
| 2003 | * @return string |
| 2004 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 2005 | protected function _mime_types($ext = "") |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2006 | { |
| 2007 | $mimes = array( 'hqx' => 'application/mac-binhex40', |
| 2008 | 'cpt' => 'application/mac-compactpro', |
| 2009 | 'doc' => 'application/msword', |
| 2010 | 'bin' => 'application/macbinary', |
| 2011 | 'dms' => 'application/octet-stream', |
| 2012 | 'lha' => 'application/octet-stream', |
| 2013 | 'lzh' => 'application/octet-stream', |
| 2014 | 'exe' => 'application/octet-stream', |
| 2015 | 'class' => 'application/octet-stream', |
| 2016 | 'psd' => 'application/octet-stream', |
| 2017 | 'so' => 'application/octet-stream', |
| 2018 | 'sea' => 'application/octet-stream', |
| 2019 | 'dll' => 'application/octet-stream', |
| 2020 | 'oda' => 'application/oda', |
| 2021 | 'pdf' => 'application/pdf', |
| 2022 | 'ai' => 'application/postscript', |
| 2023 | 'eps' => 'application/postscript', |
| 2024 | 'ps' => 'application/postscript', |
| 2025 | 'smi' => 'application/smil', |
| 2026 | 'smil' => 'application/smil', |
| 2027 | 'mif' => 'application/vnd.mif', |
| 2028 | 'xls' => 'application/vnd.ms-excel', |
| 2029 | 'ppt' => 'application/vnd.ms-powerpoint', |
| 2030 | 'wbxml' => 'application/vnd.wap.wbxml', |
| 2031 | 'wmlc' => 'application/vnd.wap.wmlc', |
| 2032 | 'dcr' => 'application/x-director', |
| 2033 | 'dir' => 'application/x-director', |
| 2034 | 'dxr' => 'application/x-director', |
| 2035 | 'dvi' => 'application/x-dvi', |
| 2036 | 'gtar' => 'application/x-gtar', |
| 2037 | 'php' => 'application/x-httpd-php', |
| 2038 | 'php4' => 'application/x-httpd-php', |
| 2039 | 'php3' => 'application/x-httpd-php', |
| 2040 | 'phtml' => 'application/x-httpd-php', |
| 2041 | 'phps' => 'application/x-httpd-php-source', |
| 2042 | 'js' => 'application/x-javascript', |
| 2043 | 'swf' => 'application/x-shockwave-flash', |
| 2044 | 'sit' => 'application/x-stuffit', |
| 2045 | 'tar' => 'application/x-tar', |
| 2046 | 'tgz' => 'application/x-tar', |
| 2047 | 'xhtml' => 'application/xhtml+xml', |
| 2048 | 'xht' => 'application/xhtml+xml', |
| 2049 | 'zip' => 'application/zip', |
| 2050 | 'mid' => 'audio/midi', |
| 2051 | 'midi' => 'audio/midi', |
| 2052 | 'mpga' => 'audio/mpeg', |
| 2053 | 'mp2' => 'audio/mpeg', |
| 2054 | 'mp3' => 'audio/mpeg', |
| 2055 | 'aif' => 'audio/x-aiff', |
| 2056 | 'aiff' => 'audio/x-aiff', |
| 2057 | 'aifc' => 'audio/x-aiff', |
| 2058 | 'ram' => 'audio/x-pn-realaudio', |
| 2059 | 'rm' => 'audio/x-pn-realaudio', |
| 2060 | 'rpm' => 'audio/x-pn-realaudio-plugin', |
| 2061 | 'ra' => 'audio/x-realaudio', |
| 2062 | 'rv' => 'video/vnd.rn-realvideo', |
| 2063 | 'wav' => 'audio/x-wav', |
| 2064 | 'bmp' => 'image/bmp', |
| 2065 | 'gif' => 'image/gif', |
| 2066 | 'jpeg' => 'image/jpeg', |
| 2067 | 'jpg' => 'image/jpeg', |
| 2068 | 'jpe' => 'image/jpeg', |
| 2069 | 'png' => 'image/png', |
| 2070 | 'tiff' => 'image/tiff', |
| 2071 | 'tif' => 'image/tiff', |
| 2072 | 'css' => 'text/css', |
| 2073 | 'html' => 'text/html', |
| 2074 | 'htm' => 'text/html', |
| 2075 | 'shtml' => 'text/html', |
| 2076 | 'txt' => 'text/plain', |
| 2077 | 'text' => 'text/plain', |
| 2078 | 'log' => 'text/plain', |
| 2079 | 'rtx' => 'text/richtext', |
| 2080 | 'rtf' => 'text/rtf', |
| 2081 | 'xml' => 'text/xml', |
| 2082 | 'xsl' => 'text/xml', |
| 2083 | 'mpeg' => 'video/mpeg', |
| 2084 | 'mpg' => 'video/mpeg', |
| 2085 | 'mpe' => 'video/mpeg', |
| 2086 | 'qt' => 'video/quicktime', |
| 2087 | 'mov' => 'video/quicktime', |
| 2088 | 'avi' => 'video/x-msvideo', |
| 2089 | 'movie' => 'video/x-sgi-movie', |
| 2090 | 'doc' => 'application/msword', |
| 2091 | 'word' => 'application/msword', |
| 2092 | 'xl' => 'application/excel', |
| 2093 | 'eml' => 'message/rfc822' |
| 2094 | ); |
| 2095 | |
| 2096 | return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)]; |
| 2097 | } |
| 2098 | |
| 2099 | } |
| 2100 | // END CI_Email class |
| 2101 | |
| 2102 | /* End of file Email.php */ |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 2103 | /* Location: ./system/libraries/Email.php */ |