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