· 10 years ago · Aug 02, 2016, 03:42 PM
1<?php
2class SMTP
3{
4 const VERSION = '5.2.9';
5 const CRLF = "\r\n";
6 const DEFAULT_SMTP_PORT = 25;
7 const MAX_LINE_LENGTH = 998;
8 const DEBUG_OFF = 0;
9 const DEBUG_CLIENT = 1;
10 const DEBUG_SERVER = 2;
11 const DEBUG_CONNECTION = 3;
12 const DEBUG_LOWLEVEL = 4;
13 public $Version = '5.2.9';
14 public $SMTP_PORT = 25;
15 public $CRLF = "\r\n";
16 public $do_debug = self::DEBUG_OFF;
17 public $Debugoutput = 'echo';
18 public $do_verp = false;
19 public $Timeout = 300;
20 public $Timelimit = 300;
21 protected $smtp_conn;
22 protected $error = array();
23 protected $helo_rply = null;
24 protected $server_caps = null;
25 protected $last_reply = '';
26 public function connect($host, $port = null, $timeout = 30, $options = array())
27 {
28 static $streamok;
29 if (is_null($streamok)) {
30 $streamok = function_exists('stream_socket_client');
31 }
32 $this->error = array();
33 if ($this->connected()) {
34 $this->error = array('error' => 'Already connected to a server');
35 return false;
36 }
37 if (empty($port)) {
38 $port = self::DEFAULT_SMTP_PORT;
39 }
40 $this->edebug("Connection: opening to $host:$port, t=$timeout, opt=" . var_export($options, true), self::DEBUG_CONNECTION);
41 $errno = 0;
42 $errstr = '';
43 if ($streamok) {
44 $socket_context = stream_context_create($options);
45 $this->smtp_conn = @stream_socket_client($host . ":" . $port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $socket_context);
46 } else {
47 $this->edebug("Connection: stream_socket_client not available, falling back to fsockopen", self::DEBUG_CONNECTION);
48 $this->smtp_conn = fsockopen($host, $port, $errno, $errstr, $timeout);
49 }
50 if (!is_resource($this->smtp_conn)) {
51 $this->error = array('error' => 'Failed to connect to server', 'errno' => $errno, 'errstr' => $errstr);
52 $this->edebug('SMTP ERROR: ' . $this->error['error'] . ": $errstr ($errno)", self::DEBUG_CLIENT);
53 return false;
54 }
55 $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
56 if (substr(PHP_OS, 0, 3) != 'WIN') {
57 $max = ini_get('max_execution_time');
58 if ($max != 0 && $timeout > $max) {
59 @set_time_limit($timeout);
60 }
61 stream_set_timeout($this->smtp_conn, $timeout, 0);
62 }
63 $announce = $this->get_lines();
64 $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
65 return true;
66 }
67 public function connected()
68 {
69 if (is_resource($this->smtp_conn)) {
70 $sock_status = stream_get_meta_data($this->smtp_conn);
71 if ($sock_status['eof']) {
72 $this->edebug('SMTP NOTICE: EOF caught while checking if connected', self::DEBUG_CLIENT);
73 $this->close();
74 return false;
75 }
76 return true;
77 }
78 return false;
79 }
80 protected function edebug($str, $level = 0)
81 {
82 if ($level > $this->do_debug) {
83 return;
84 }
85 if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
86 call_user_func($this->Debugoutput, $str, $this->do_debug);
87 return;
88 }
89 switch ($this->Debugoutput) {
90 case 'error_log':
91 error_log($str);
92 break;
93 case 'html':
94 echo htmlentities(preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, 'UTF-8') . "<br>\n";
95 break;
96 case 'echo':
97 default:
98 $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
99 echo gmdate('Y-m-d H:i:s') . "\t" . str_replace("\n", "\n \t ", trim($str)) . "\n";
100 }
101 }
102 public function close()
103 {
104 $this->error = array();
105 $this->server_caps = null;
106 $this->helo_rply = null;
107 if (is_resource($this->smtp_conn)) {
108 fclose($this->smtp_conn);
109 $this->smtp_conn = null;
110 $this->edebug('Connection: closed', self::DEBUG_CONNECTION);
111 }
112 }
113 protected function get_lines()
114 {
115 if (!is_resource($this->smtp_conn)) {
116 return '';
117 }
118 $data = '';
119 $endtime = 0;
120 stream_set_timeout($this->smtp_conn, $this->Timeout);
121 if ($this->Timelimit > 0) {
122 $endtime = time() + $this->Timelimit;
123 }
124 while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
125 $str = @fgets($this->smtp_conn, 515);
126 $this->edebug("SMTP -> get_lines(): \$data was \"$data\"", self::DEBUG_LOWLEVEL);
127 $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL);
128 $data .= $str;
129 $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
130 if ((isset($str[3]) and $str[3] == ' ')) {
131 break;
132 }
133 $info = stream_get_meta_data($this->smtp_conn);
134 if ($info['timed_out']) {
135 $this->edebug('SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)', self::DEBUG_LOWLEVEL);
136 break;
137 }
138 if ($endtime and time() > $endtime) {
139 $this->edebug('SMTP -> get_lines(): timelimit reached (' . $this->Timelimit . ' sec)', self::DEBUG_LOWLEVEL);
140 break;
141 }
142 }
143 return $data;
144 }
145 public function startTLS()
146 {
147 if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
148 return false;
149 }
150 if (!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
151 return false;
152 }
153 return true;
154 }
155 protected function sendCommand($command, $commandstring, $expect)
156 {
157 if (!$this->connected()) {
158 $this->error = array('error' => "Called $command without being connected");
159 return false;
160 }
161 $this->client_send($commandstring . self::CRLF);
162 $this->last_reply = $this->get_lines();
163 $matches = array();
164 if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) {
165 $code = $matches[1];
166 $code_ex = (count($matches) > 2 ? $matches[2] : null);
167 $detail = preg_replace("/{$code}[ -]" . ($code_ex ? str_replace('.', '\\.', $code_ex) . ' ' : '') . "/m", '', $this->last_reply);
168 } else {
169 $code = substr($this->last_reply, 0, 3);
170 $code_ex = null;
171 $detail = substr($this->last_reply, 4);
172 }
173 $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
174 if (!in_array($code, (array)$expect)) {
175 $this->error = array('error' => "$command command failed", 'smtp_code' => $code, 'smtp_code_ex' => $code_ex, 'detail' => $detail);
176 $this->edebug('SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply, self::DEBUG_CLIENT);
177 return false;
178 }
179 $this->error = array();
180 return true;
181 }
182 public function client_send($data)
183 {
184 $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT);
185 return fwrite($this->smtp_conn, $data);
186 }
187 public function authenticate($username, $password, $authtype = null, $realm = '', $workstation = '')
188 {
189 if (!$this->server_caps) {
190 $this->error = array('error' => 'Authentication is not allowed before HELO/EHLO');
191 return false;
192 }
193 if (array_key_exists('EHLO', $this->server_caps)) {
194 if (!array_key_exists('AUTH', $this->server_caps)) {
195 $this->error = array('error' => 'Authentication is not allowed at this stage');
196 return false;
197 }
198 self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
199 self::edebug('Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']), self::DEBUG_LOWLEVEL);
200 if (empty($authtype)) {
201 foreach (array('LOGIN', 'CRAM-MD5', 'NTLM', 'PLAIN') as $method) {
202 if (in_array($method, $this->server_caps['AUTH'])) {
203 $authtype = $method;
204 break;
205 }
206 }
207 if (empty($authtype)) {
208 $this->error = array('error' => 'No supported authentication methods found');
209 return false;
210 }
211 self::edebug('Auth method selected: ' . $authtype, self::DEBUG_LOWLEVEL);
212 }
213 if (!in_array($authtype, $this->server_caps['AUTH'])) {
214 $this->error = array('error' => 'The requested authentication method "' . $authtype . '" is not supported by the server');
215 return false;
216 }
217 } elseif (empty($authtype)) {
218 $authtype = 'LOGIN';
219 }
220 switch ($authtype) {
221 case 'PLAIN':
222 if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) {
223 return false;
224 }
225 if (!$this->sendCommand('User & Password', base64_encode("\0" . $username . "\0" . $password), 235)) {
226 return false;
227 }
228 break;
229 case 'LOGIN':
230 if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
231 return false;
232 }
233 if (!$this->sendCommand("Username", base64_encode($username), 334)) {
234 return false;
235 }
236 if (!$this->sendCommand("Password", base64_encode($password), 235)) {
237 return false;
238 }
239 break;
240 case 'NTLM':
241 require_once 'extras/ntlm_sasl_client.php';
242 $temp = new stdClass();
243 $ntlm_client = new ntlm_sasl_client_class;
244 if (!$ntlm_client->Initialize($temp)) {
245 $this->error = array('error' => $temp->error);
246 $this->edebug('You need to enable some modules in your php.ini file: ' . $this->error['error'], self::DEBUG_CLIENT);
247 return false;
248 }
249 $msg1 = $ntlm_client->TypeMsg1($realm, $workstation);
250 if (!$this->sendCommand('AUTH NTLM', 'AUTH NTLM ' . base64_encode($msg1), 334)) {
251 return false;
252 }
253 $challenge = substr($this->last_reply, 3);
254 $challenge = base64_decode($challenge);
255 $ntlm_res = $ntlm_client->NTLMResponse(substr($challenge, 24, 8), $password);
256 $msg3 = $ntlm_client->TypeMsg3($ntlm_res, $username, $realm, $workstation);
257 return $this->sendCommand('Username', base64_encode($msg3), 235);
258 case 'CRAM-MD5':
259 if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) {
260 return false;
261 }
262 $challenge = base64_decode(substr($this->last_reply, 4));
263 $response = $username . ' ' . $this->hmac($challenge, $password);
264 return $this->sendCommand('Username', base64_encode($response), 235);
265 default:
266 $this->error = array('error' => 'Authentication method "' . $authtype . '" is not supported');
267 return false;
268 }
269 return true;
270 }
271 protected function hmac($data, $key)
272 {
273 if (function_exists('hash_hmac')) {
274 return hash_hmac('md5', $data, $key);
275 }
276 $bytelen = 64;
277 if (strlen($key) > $bytelen) {
278 $key = pack('H*', md5($key));
279 }
280 $key = str_pad($key, $bytelen, chr(0x00));
281 $ipad = str_pad('', $bytelen, chr(0x36));
282 $opad = str_pad('', $bytelen, chr(0x5c));
283 $k_ipad = $key ^ $ipad;
284 $k_opad = $key ^ $opad;
285 return md5($k_opad . pack('H*', md5($k_ipad . $data)));
286 }
287 public function data($msg_data)
288 {
289 if (!$this->sendCommand('DATA', 'DATA', 354)) {
290 return false;
291 }
292 $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));
293 $field = substr($lines[0], 0, strpos($lines[0], ':'));
294 $in_headers = false;
295 if (!empty($field) && strpos($field, ' ') === false) {
296 $in_headers = true;
297 }
298 foreach ($lines as $line) {
299 $lines_out = array();
300 if ($in_headers and $line == '') {
301 $in_headers = false;
302 }
303 while (isset($line[self::MAX_LINE_LENGTH])) {
304 $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
305 if (!$pos) {
306 $pos = self::MAX_LINE_LENGTH - 1;
307 $lines_out[] = substr($line, 0, $pos);
308 $line = substr($line, $pos);
309 } else {
310 $lines_out[] = substr($line, 0, $pos);
311 $line = substr($line, $pos + 1);
312 }
313 if ($in_headers) {
314 $line = "\t" . $line;
315 }
316 }
317 $lines_out[] = $line;
318 foreach ($lines_out as $line_out) {
319 if (!empty($line_out) and $line_out[0] == '.') {
320 $line_out = '.' . $line_out;
321 }
322 $this->client_send($line_out . self::CRLF);
323 }
324 }
325 $savetimelimit = $this->Timelimit;
326 $this->Timelimit = $this->Timelimit * 2;
327 $result = $this->sendCommand('DATA END', '.', 250);
328 $this->Timelimit = $savetimelimit;
329 return $result;
330 }
331 public function hello($host = '')
332 {
333 return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
334 }
335 protected function sendHello($hello, $host)
336 {
337 $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250);
338 $this->helo_rply = $this->last_reply;
339 if ($noerror) {
340 $this->parseHelloFields($hello);
341 } else {
342 $this->server_caps = null;
343 }
344 return $noerror;
345 }
346 protected function parseHelloFields($type)
347 {
348 $this->server_caps = array();
349 $lines = explode("\n", $this->last_reply);
350 foreach ($lines as $n => $s) {
351 $s = trim(substr($s, 4));
352 if (!$s) {
353 continue;
354 }
355 $fields = explode(' ', $s);
356 if ($fields) {
357 if (!$n) {
358 $name = $type;
359 $fields = $fields[0];
360 } else {
361 $name = array_shift($fields);
362 if ($name == 'SIZE') {
363 $fields = ($fields) ? $fields[0] : 0;
364 }
365 }
366 $this->server_caps[$name] = ($fields ? $fields : true);
367 }
368 }
369 }
370 public function mail($from)
371 {
372 $useVerp = ($this->do_verp ? ' XVERP' : '');
373 return $this->sendCommand('MAIL FROM', 'MAIL FROM:<' . $from . '>' . $useVerp, 250);
374 }
375 public function quit($close_on_error = true)
376 {
377 $noerror = $this->sendCommand('QUIT', 'QUIT', 221);
378 $err = $this->error;
379 if ($noerror or $close_on_error) {
380 $this->close();
381 $this->error = $err;
382 }
383 return $noerror;
384 }
385 public function recipient($toaddr)
386 {
387 return $this->sendCommand('RCPT TO', 'RCPT TO:<' . $toaddr . '>', array(250, 251));
388 }
389 public function reset()
390 {
391 return $this->sendCommand('RSET', 'RSET', 250);
392 }
393 public function sendAndMail($from)
394 {
395 return $this->sendCommand('SAML', "SAML FROM:$from", 250);
396 }
397 public function verify($name)
398 {
399 return $this->sendCommand('VRFY', "VRFY $name", array(250, 251));
400 }
401 public function noop()
402 {
403 return $this->sendCommand('NOOP', 'NOOP', 250);
404 }
405 public function turn()
406 {
407 $this->error = array('error' => 'The SMTP TURN command is not implemented');
408 $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT);
409 return false;
410 }
411 public function getError()
412 {
413 return $this->error;
414 }
415 public function getServerExtList()
416 {
417 return $this->server_caps;
418 }
419 public function getServerExt($name)
420 {
421 if (!$this->server_caps) {
422 $this->error = array('No HELO/EHLO was sent');
423 return null;
424 }
425 if (!array_key_exists($name, $this->server_caps)) {
426 if ($name == 'HELO') {
427 return $this->server_caps['EHLO'];
428 }
429 if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) {
430 return false;
431 }
432 $this->error = array('HELO handshake was used. Client knows nothing about server extensions');
433 return null;
434 }
435 return $this->server_caps[$name];
436 }
437 public function getLastReply()
438 {
439 return $this->last_reply;
440 }
441 public function setVerp($enabled = false)
442 {
443 $this->do_verp = $enabled;
444 }
445 public function getVerp()
446 {
447 return $this->do_verp;
448 }
449 public function getDebugOutput()
450 {
451 return $this->Debugoutput;
452 }
453 public function setDebugOutput($method = 'echo')
454 {
455 $this->Debugoutput = $method;
456 }
457 public function setDebugLevel($level = 0)
458 {
459 $this->do_debug = $level;
460 }
461 public function getDebugLevel()
462 {
463 return $this->do_debug;
464 }
465 public function getTimeout()
466 {
467 return $this->Timeout;
468 }
469 public function setTimeout($timeout = 0)
470 {
471 $this->Timeout = $timeout;
472 }
473}
474class Mailer
475{
476 const STOP_MESSAGE = 0;
477 const STOP_CONTINUE = 1;
478 const STOP_CRITICAL = 2;
479 const CRLF = "\r\n";
480 public $Version = '3.1.1';
481 public $Priority = 3;
482 public $CharSet = 'iso-8859-1';
483 public $ContentType = 'text/plain';
484 public $Encoding = '8bit';
485 public $ErrorInfo = '';
486 public $From = 'root@localhost';
487 public $FromName = 'Root User';
488 public $Sender = '';
489 public $ReturnPath = '';
490 public $Subject = '';
491 public $Body = '';
492 public $AltBody = '';
493 public $Ical = '';
494 public $WordWrap = 0;
495 public $Mailer = 'mail';
496 public $Sendmail = '/usr/sbin/sendmail';
497 public $UseSendmailOptions = true;
498 public $PluginDir = '';
499 public $ConfirmReadingTo = '';
500 public $Hostname = '';
501 public $MessageID = '';
502 public $MessageDate = '';
503 public $Host = 'localhost';
504 public $Port = 25;
505 public $Helo = '';
506 public $SMTPSecure = '';
507 public $SMTPAuth = false;
508 public $Username = '';
509 public $Password = '';
510 public $AuthType = '';
511 public $Realm = '';
512 public $Workstation = '';
513 public $Timeout = 10;
514 public $SMTPDebug = 0;
515 public $Debugoutput = 'echo';
516 public $SMTPKeepAlive = false;
517 public $SingleTo = false;
518 public $SingleToArray = array();
519 public $do_verp = false;
520 public $AllowEmpty = false;
521 public $LE = "\n";
522 public $DKIM_selector = '';
523 public $DKIM_identity = '';
524 public $DKIM_passphrase = '';
525 public $DKIM_domain = '';
526 public $DKIM_private = '';
527 public $action_function = '';
528 public $XMailer = '';
529 protected $MIMEBody = '';
530 protected $MIMEHeader = '';
531 protected $mailHeader = '';
532 protected $smtp = null;
533 protected $to = array();
534 protected $cc = array();
535 protected $bcc = array();
536 protected $ReplyTo = array();
537 protected $all_recipients = array();
538 protected $attachment = array();
539 protected $CustomHeader = array();
540 protected $lastMessageID = '';
541 protected $message_type = '';
542 protected $boundary = array();
543 protected $language = array();
544 protected $error_count = 0;
545 protected $sign_cert_file = '';
546 protected $sign_key_file = '';
547 protected $sign_key_pass = '';
548 protected $exceptions = false;
549 public function __construct($exceptions = false)
550 {
551 $this->exceptions = ($exceptions == true);
552 if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
553 $autoload = spl_autoload_functions();
554 if ($autoload === false or !in_array('PHPMailerAutoload', $autoload)) {
555 }
556 }
557 }
558 public function __destruct()
559 {
560 if ($this->Mailer == 'smtp') {
561 $this->smtpClose();
562 }
563 }
564 public function smtpClose()
565 {
566 if ($this->smtp !== null) {
567 if ($this->smtp->connected()) {
568 $this->smtp->quit();
569 $this->smtp->close();
570 }
571 }
572 }
573 public function isSMTP()
574 {
575 $this->Mailer = 'smtp';
576 }
577 public function isMail()
578 {
579 $this->Mailer = 'mail';
580 }
581 public function isSendmail()
582 {
583 $ini_sendmail_path = ini_get('sendmail_path');
584 if (!stristr($ini_sendmail_path, 'sendmail')) {
585 $this->Sendmail = '/usr/sbin/sendmail';
586 } else {
587 $this->Sendmail = $ini_sendmail_path;
588 }
589 $this->Mailer = 'sendmail';
590 }
591 public function isQmail()
592 {
593 $ini_sendmail_path = ini_get('sendmail_path');
594 if (!stristr($ini_sendmail_path, 'qmail')) {
595 $this->Sendmail = '/var/qmail/bin/qmail-inject';
596 } else {
597 $this->Sendmail = $ini_sendmail_path;
598 }
599 $this->Mailer = 'qmail';
600 }
601 public function addAddress($address, $name = '')
602 {
603 return $this->addAnAddress('to', $address, $name);
604 }
605 protected function addAnAddress($kind, $address, $name = '')
606 {
607 if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
608 $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
609 $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
610 if ($this->exceptions) {
611 throw new phpmailerException('Invalid recipient array: ' . $kind);
612 }
613 return false;
614 }
615 $address = trim($address);
616 $name = trim(preg_replace('/[\r\n]+/', '', $name));
617 if (!$this->validateAddress($address)) {
618 $this->setError($this->lang('invalid_address') . ': ' . $address);
619 $this->edebug($this->lang('invalid_address') . ': ' . $address);
620 if ($this->exceptions) {
621 throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
622 }
623 return false;
624 }
625 if ($kind != 'Reply-To') {
626 if (!isset($this->all_recipients[strtolower($address)])) {
627 array_push($this->$kind, array($address, $name));
628 $this->all_recipients[strtolower($address)] = true;
629 return true;
630 }
631 } else {
632 if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
633 $this->ReplyTo[strtolower($address)] = array($address, $name);
634 return true;
635 }
636 }
637 return false;
638 }
639 protected function setError($msg)
640 {
641 $this->error_count++;
642 if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
643 $lasterror = $this->smtp->getError();
644 if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
645 $msg .= '<p>' . $this->lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
646 }
647 }
648 $this->ErrorInfo = $msg;
649 }
650 protected function lang($key)
651 {
652 if (count($this->language) < 1) {
653 $this->setLanguage('en');
654 }
655 if (isset($this->language[$key])) {
656 return $this->language[$key];
657 } else {
658 return 'Language string failed to load: ' . $key;
659 }
660 }
661 public function setLanguage($langcode = 'en', $lang_path = '')
662 {
663 $PHPMAILER_LANG = array('authenticate' => 'SMTP Error: Could not authenticate.', 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', 'data_not_accepted' => 'SMTP Error: data not accepted.', 'empty_message' => 'Message body empty', 'encoding' => 'Unknown encoding: ', 'execute' => 'Could not execute: ', 'file_access' => 'Could not access file: ', 'file_open' => 'File Error: Could not open file: ', 'from_failed' => 'The following From address failed: ', 'instantiate' => 'Could not instantiate mail function.', 'invalid_address' => 'Invalid address', 'mailer_not_supported' => ' mailer is not supported.', 'provide_address' => 'You must provide at least one recipient email address.', 'recipients_failed' => 'SMTP Error: The following recipients failed: ', 'signing' => 'Signing Error: ', 'smtp_connect_failed' => 'SMTP connect() failed.', 'smtp_error' => 'SMTP server error: ', 'variable_set' => 'Cannot set or reset variable: ');
664 if (empty($lang_path)) {
665 $lang_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR;
666 }
667 $foundlang = true;
668 $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
669 if ($langcode != 'en') {
670 if (!is_readable($lang_file)) {
671 $foundlang = false;
672 } else {
673 $foundlang = include $lang_file;
674 }
675 }
676 $this->language = $PHPMAILER_LANG;
677 return ($foundlang == true);
678 }
679 protected function edebug($str)
680 {
681 if (!$this->SMTPDebug) {
682 return;
683 }
684 switch ($this->Debugoutput) {
685 case 'error_log':
686 error_log($str);
687 break;
688 case 'html':
689 echo htmlentities(preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, $this->CharSet) . "<br>\n";
690 break;
691 case 'echo':
692 default:
693 echo $str . "\n";
694 }
695 }
696 public static function validateAddress($address, $patternselect = 'auto')
697 {
698 if (!$patternselect or $patternselect == 'auto') {
699 if (defined('PCRE_VERSION')) {
700 if (version_compare(PCRE_VERSION, '8.0') >= 0) {
701 $patternselect = 'pcre8';
702 } else {
703 $patternselect = 'pcre';
704 }
705 } else {
706 if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
707 $patternselect = 'php';
708 } else {
709 $patternselect = 'noregex';
710 }
711 }
712 }
713 switch ($patternselect) {
714 case 'pcre8':
715 return (boolean)preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' . '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' . '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' . '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' . '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' . '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' . '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' . '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' . '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);
716 case 'pcre':
717 return (boolean)preg_match('/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' . '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' . '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' . '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' . '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' . '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' . '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' . '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' . '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' . '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD', $address);
718 case 'html5':
719 return (boolean)preg_match('/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' . '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD', $address);
720 case 'noregex':
721 return (strlen($address) >= 3 and strpos($address, '@') >= 1 and strpos($address, '@') != strlen($address) - 1);
722 case 'php':
723 default:
724 return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
725 }
726 }
727 public function addCC($address, $name = '')
728 {
729 return $this->addAnAddress('cc', $address, $name);
730 }
731 public function addBCC($address, $name = '')
732 {
733 return $this->addAnAddress('bcc', $address, $name);
734 }
735 public function addReplyTo($address, $name = '')
736 {
737 return $this->addAnAddress('Reply-To', $address, $name);
738 }
739 public function setFrom($address, $name = '', $auto = true)
740 {
741 $address = trim($address);
742 $name = trim(preg_replace('/[\r\n]+/', '', $name));
743 if (!$this->validateAddress($address)) {
744 $this->setError($this->lang('invalid_address') . ': ' . $address);
745 $this->edebug($this->lang('invalid_address') . ': ' . $address);
746 if ($this->exceptions) {
747 throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
748 }
749 return false;
750 }
751 $this->From = $address;
752 $this->FromName = $name;
753 if ($auto) {
754 if (empty($this->Sender)) {
755 $this->Sender = $address;
756 }
757 }
758 return true;
759 }
760 public function getLastMessageID()
761 {
762 return $this->lastMessageID;
763 }
764 public function send()
765 {
766 try {
767 if (!$this->preSend()) {
768 return false;
769 }
770 return $this->postSend();
771 } catch (phpmailerException $exc) {
772 $this->mailHeader = '';
773 $this->setError($exc->getMessage());
774 if ($this->exceptions) {
775 throw $exc;
776 }
777 return false;
778 }
779 }
780 public function preSend()
781 {
782 try {
783 $this->mailHeader = '';
784 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
785 throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
786 }
787 if (!empty($this->AltBody)) {
788 $this->ContentType = 'multipart/alternative';
789 }
790 $this->error_count = 0;
791 $this->setMessageType();
792 if (!$this->AllowEmpty and empty($this->Body)) {
793 throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
794 }
795 $this->MIMEHeader = $this->createHeader();
796 $this->MIMEBody = $this->createBody();
797 if ($this->Mailer == 'mail') {
798 if (count($this->to) > 0) {
799 $this->mailHeader .= $this->addrAppend('To', $this->to);
800 } else {
801 $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;
802');
803 }
804 $this->mailHeader .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader(trim($this->Subject))));
805 }
806 if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && !empty($this->DKIM_domain) && file_exists($this->DKIM_private)) {
807 $header_dkim = $this->DKIM_Add($this->MIMEHeader . $this->mailHeader, $this->encodeHeader($this->secureHeader($this->Subject)), $this->MIMEBody);
808 $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF . str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
809 }
810 return true;
811 } catch (phpmailerException $exc) {
812 $this->setError($exc->getMessage());
813 if ($this->exceptions) {
814 throw $exc;
815 }
816 return false;
817 }
818 }
819 protected function setMessageType()
820 {
821 $this->message_type = array();
822 if ($this->alternativeExists()) {
823 $this->message_type[] = 'alt';
824 }
825 if ($this->inlineImageExists()) {
826 $this->message_type[] = 'inline';
827 }
828 if ($this->attachmentExists()) {
829 $this->message_type[] = 'attach';
830 }
831 $this->message_type = implode('_', $this->message_type);
832 if ($this->message_type == '') {
833 $this->message_type = 'plain';
834 }
835 }
836 public function alternativeExists()
837 {
838 return !empty($this->AltBody);
839 }
840 public function inlineImageExists()
841 {
842 foreach ($this->attachment as $attachment) {
843 if ($attachment[6] == 'inline') {
844 return true;
845 }
846 }
847 return false;
848 }
849 public function attachmentExists()
850 {
851 foreach ($this->attachment as $attachment) {
852 if ($attachment[6] == 'attachment') {
853 return true;
854 }
855 }
856 return false;
857 }
858 public function createHeader()
859 {
860 $result = '';
861 $uniq_id = uniqid("priv8uts") . md5(time());
862 $this->boundary[1] = 'b1_' . $uniq_id;
863 $this->boundary[2] = 'b2_' . $uniq_id;
864 $this->boundary[3] = 'b3_' . $uniq_id;
865 if ($this->MessageDate == '') {
866 $this->MessageDate = self::rfcDate();
867 }
868 $result .= $this->headerLine('Date', $this->MessageDate);
869 if ($this->SingleTo === true) {
870 if ($this->Mailer != 'mail') {
871 foreach ($this->to as $toaddr) {
872 $this->SingleToArray[] = $this->addrFormat($toaddr);
873 }
874 }
875 } else {
876 if (count($this->to) > 0) {
877 if ($this->Mailer != 'mail') {
878 $result .= $this->addrAppend('To', $this->to);
879 }
880 } elseif (count($this->cc) == 0) {
881 $result .= $this->headerLine('To', 'undisclosed-recipients:;
882');
883 }
884 }
885 $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
886 if (count($this->cc) > 0) {
887 $result .= $this->addrAppend('Cc', $this->cc);
888 }
889 if (($this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail') and count($this->bcc) > 0) {
890 $result .= $this->addrAppend('Bcc', $this->bcc);
891 }
892 if (count($this->ReplyTo) > 0) {
893 $result .= $this->addrAppend('Reply-To', $this->ReplyTo);
894 }
895 if ($this->Mailer != 'mail') {
896 $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
897 }
898 if ($this->MessageID != '') {
899 $this->lastMessageID = $this->MessageID;
900 } else {
901 $this->lastMessageID = sprintf('<%s@%s>', $uniq_id, $this->ServerHostname());
902 }
903 $result .= $this->HeaderLine('Message-ID', $this->lastMessageID);
904 $result .= $this->headerLine('X-Priority', $this->Priority);
905 if ($this->XMailer == '') {
906 $result .= $this->headerLine('X-Mailer', 'TJMailer' . $this->Version);
907 } else {
908 $myXmailer = trim($this->XMailer);
909 if ($myXmailer) {
910 $result .= $this->headerLine('X-Mailer', $myXmailer);
911 }
912 }
913 if ($this->ConfirmReadingTo != '') {
914 $result .= $this->headerLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
915 }
916 for ($index = 0;
917 $index < count($this->CustomHeader);
918 $index++) {
919 $result .= $this->headerLine(trim($this->CustomHeader[$index][0]), $this->encodeHeader(trim($this->CustomHeader[$index][1])));
920 }
921 if (!$this->sign_key_file) {
922 $result .= $this->headerLine('MIME-Version', '1.0');
923 $result .= $this->getMailMIME();
924 }
925 return $result;
926 }
927 public static function rfcDate()
928 {
929 date_default_timezone_set(@date_default_timezone_get());
930 return date('D, j M Y H:i:s O');
931 }
932 public function headerLine($name, $value)
933 {
934 return $name . ': ' . $value . $this->LE;
935 }
936 public function addrFormat($addr)
937 {
938 if (empty($addr[1])) {
939 return $this->secureHeader($addr[0]);
940 } else {
941 return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader($addr[0]) . '>';
942 }
943 }
944 public function secureHeader($str)
945 {
946 return trim(str_replace(array("\r", "\n"), '', $str));
947 }
948 public function encodeHeader($str, $position = 'text')
949 {
950 $matchcount = 0;
951 switch (strtolower($position)) {
952 case 'phrase':
953 if (!preg_match('/[\200-\377]/', $str)) {
954 $encoded = addcslashes($str, "\0..\37\177\\\"");
955 if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
956 return ($encoded);
957 } else {
958 return ("\"$encoded\"");
959 }
960 }
961 $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
962 break;
963 case 'comment':
964 $matchcount = preg_match_all('/[()"]/', $str, $matches);
965 case 'text':
966 default:
967 $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
968 break;
969 }
970 if ($matchcount == 0) {
971 return ($str);
972 }
973 $maxlen = 75 - 7 - strlen($this->CharSet);
974 if ($matchcount > strlen($str) / 3) {
975 $encoding = 'B';
976 if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) {
977 $encoded = $this->base64EncodeWrapMB($str, "\n");
978 } else {
979 $encoded = base64_encode($str);
980 $maxlen -= $maxlen % 4;
981 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
982 }
983 } else {
984 $encoding = 'Q';
985 $encoded = $this->encodeQ($str, $position);
986 $encoded = $this->wrapText($encoded, $maxlen, true);
987 $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
988 }
989 $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
990 $encoded = trim(str_replace("\n", $this->LE, $encoded));
991 return $encoded;
992 }
993 public function hasMultiBytes($str)
994 {
995 if (function_exists('mb_strlen')) {
996 return (strlen($str) > mb_strlen($str, $this->CharSet));
997 } else {
998 return false;
999 }
1000 }
1001 public function base64EncodeWrapMB($str, $linebreak = null)
1002 {
1003 $start = '=?' . $this->CharSet . '?B?';
1004 $end = '?=';
1005 $encoded = '';
1006 if ($linebreak === null) {
1007 $linebreak = $this->LE;
1008 }
1009 $mb_length = mb_strlen($str, $this->CharSet);
1010 $length = 75 - strlen($start) - strlen($end);
1011 $ratio = $mb_length / strlen($str);
1012 $avgLength = floor($length * $ratio * .75);
1013 for ($i = 0;
1014 $i < $mb_length;
1015 $i += $offset) {
1016 $lookBack = 0;
1017 do {
1018 $offset = $avgLength - $lookBack;
1019 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
1020 $chunk = base64_encode($chunk);
1021 $lookBack++;
1022 } while (strlen($chunk) > $length);
1023 $encoded .= $chunk . $linebreak;
1024 }
1025 $encoded = substr($encoded, 0, -strlen($linebreak));
1026 return $encoded;
1027 }
1028 public function encodeQ($str, $position = 'text')
1029 {
1030 $pattern = '';
1031 $encoded = str_replace(array("\r", "\n"), '', $str);
1032 switch (strtolower($position)) {
1033 case 'phrase':
1034 $pattern = '^A-Za-z0-9!*+\/ -';
1035 break;
1036 case 'comment':
1037 $pattern = '\(\)"';
1038 case 'text':
1039 default:
1040 $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
1041 break;
1042 }
1043 $matches = array();
1044 if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
1045 $eqkey = array_search('=', $matches[0]);
1046 if ($eqkey !== false) {
1047 unset($matches[0][$eqkey]);
1048 array_unshift($matches[0], '=');
1049 }
1050 foreach (array_unique($matches[0]) as $char) {
1051 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
1052 }
1053 }
1054 return str_replace(' ', '_', $encoded);
1055 }
1056 public function wrapText($message, $length, $qp_mode = false)
1057 {
1058 $soft_break = ($qp_mode) ? sprintf(' =%s', $this->LE) : $this->LE;
1059 $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
1060 $lelen = strlen($this->LE);
1061 $crlflen = strlen(self::CRLF);
1062 $message = $this->fixEOL($message);
1063 if (substr($message, -$lelen) == $this->LE) {
1064 $message = substr($message, 0, -$lelen);
1065 }
1066 $line = explode($this->LE, $message);
1067 $message = '';
1068 for ($i = 0;
1069 $i < count($line);
1070 $i++) {
1071 $line_part = explode(' ', $line[$i]);
1072 $buf = '';
1073 for ($e = 0;
1074 $e < count($line_part);
1075 $e++) {
1076 $word = $line_part[$e];
1077 if ($qp_mode and (strlen($word) > $length)) {
1078 $space_left = $length - strlen($buf) - $crlflen;
1079 if ($e != 0) {
1080 if ($space_left > 20) {
1081 $len = $space_left;
1082 if ($is_utf8) {
1083 $len = $this->utf8CharBoundary($word, $len);
1084 } elseif (substr($word, $len - 1, 1) == '=') {
1085 $len--;
1086 } elseif (substr($word, $len - 2, 1) == '=') {
1087 $len -= 2;
1088 }
1089 $part = substr($word, 0, $len);
1090 $word = substr($word, $len);
1091 $buf .= ' ' . $part;
1092 $message .= $buf . sprintf('=%s', self::CRLF);
1093 } else {
1094 $message .= $buf . $soft_break;
1095 }
1096 $buf = '';
1097 }
1098 while (strlen($word) > 0) {
1099 if ($length <= 0) {
1100 break;
1101 }
1102 $len = $length;
1103 if ($is_utf8) {
1104 $len = $this->utf8CharBoundary($word, $len);
1105 } elseif (substr($word, $len - 1, 1) == '=') {
1106 $len--;
1107 } elseif (substr($word, $len - 2, 1) == '=') {
1108 $len -= 2;
1109 }
1110 $part = substr($word, 0, $len);
1111 $word = substr($word, $len);
1112 if (strlen($word) > 0) {
1113 $message .= $part . sprintf('=%s', self::CRLF);
1114 } else {
1115 $buf = $part;
1116 }
1117 }
1118 } else {
1119 $buf_o = $buf;
1120 $buf .= ($e == 0) ? $word : (' ' . $word);
1121 if (strlen($buf) > $length and $buf_o != '') {
1122 $message .= $buf_o . $soft_break;
1123 $buf = $word;
1124 }
1125 }
1126 }
1127 $message .= $buf . self::CRLF;
1128 }
1129 return $message;
1130 }
1131 public function fixEOL($str)
1132 {
1133 $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
1134 if ($this->LE !== "\n") {
1135 $nstr = str_replace("\n", $this->LE, $nstr);
1136 }
1137 return $nstr;
1138 }
1139 public function utf8CharBoundary($encodedText, $maxLength)
1140 {
1141 $foundSplitPos = false;
1142 $lookBack = 3;
1143 while (!$foundSplitPos) {
1144 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
1145 $encodedCharPos = strpos($lastChunk, '=');
1146 if ($encodedCharPos !== false) {
1147 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
1148 $dec = hexdec($hex);
1149 if ($dec < 128) {
1150 $maxLength = ($encodedCharPos == 0) ? $maxLength : $maxLength - ($lookBack - $encodedCharPos);
1151 $foundSplitPos = true;
1152 } elseif ($dec >= 192) {
1153 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
1154 $foundSplitPos = true;
1155 } elseif ($dec < 192) {
1156 $lookBack += 3;
1157 }
1158 } else {
1159 $foundSplitPos = true;
1160 }
1161 }
1162 return $maxLength;
1163 }
1164 public function addrAppend($type, $addr)
1165 {
1166 $addresses = array();
1167 foreach ($addr as $address) {
1168 $addresses[] = $this->addrFormat($address);
1169 }
1170 return $type . ': ' . implode(', ', $addresses) . $this->LE;
1171 }
1172 protected function serverHostname()
1173 {
1174 $result = 'localhost.localdomain';
1175 if (!empty($this->Hostname)) {
1176 $result = $this->Hostname;
1177 } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
1178 $result = $_SERVER['SERVER_NAME'];
1179 } elseif (function_exists('gethostname') && gethostname() !== false) {
1180 $result = gethostname();
1181 } elseif (php_uname('n') !== false) {
1182 $result = php_uname('n');
1183 }
1184 return $result;
1185 }
1186 public function getMailMIME()
1187 {
1188 $result = '';
1189 $ismultipart = true;
1190 switch ($this->message_type) {
1191 case 'inline':
1192 $result .= $this->headerLine('Content-Type', 'multipart/related;');
1193 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
1194 break;
1195 case 'attach':
1196 case 'inline_attach':
1197 case 'alt_attach':
1198 case 'alt_inline_attach':
1199 $result .= $this->headerLine('Content-Type', 'multipart/mixed;');
1200 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
1201 break;
1202 case 'alt':
1203 case 'alt_inline':
1204 $result .= $this->headerLine('Content-Type', 'multipart/alternative;');
1205 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
1206 break;
1207 default:
1208 $result .= $this->textLine('Content-Type: ' . $this->ContentType . ';charset=' . $this->CharSet);
1209 $ismultipart = false;
1210 break;
1211 }
1212 if ($this->Encoding != '7bit') {
1213 if ($ismultipart) {
1214 if ($this->Encoding == '8bit') {
1215 $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
1216 }
1217 } else {
1218 $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
1219 }
1220 }
1221 if ($this->Mailer != 'mail') {
1222 $result .= $this->LE;
1223 }
1224 return $result;
1225 }
1226 public function textLine($value)
1227 {
1228 return $value . $this->LE;
1229 }
1230 public function createBody()
1231 {
1232 $body = '';
1233 if ($this->sign_key_file) {
1234 $body .= $this->getMailMIME() . $this->LE;
1235 }
1236 $this->setWordWrap();
1237 $bodyEncoding = $this->Encoding;
1238 $bodyCharSet = $this->CharSet;
1239 if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
1240 $bodyEncoding = '7bit';
1241 $bodyCharSet = 'us-ascii';
1242 }
1243 $altBodyEncoding = $this->Encoding;
1244 $altBodyCharSet = $this->CharSet;
1245 if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
1246 $altBodyEncoding = '7bit';
1247 $altBodyCharSet = 'us-ascii';
1248 }
1249 switch ($this->message_type) {
1250 case 'inline':
1251 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
1252 $body .= $this->encodeString($this->Body, $bodyEncoding);
1253 $body .= $this->LE . $this->LE;
1254 $body .= $this->attachAll('inline', $this->boundary[1]);
1255 break;
1256 case 'attach':
1257 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
1258 $body .= $this->encodeString($this->Body, $bodyEncoding);
1259 $body .= $this->LE . $this->LE;
1260 $body .= $this->attachAll('attachment', $this->boundary[1]);
1261 break;
1262 case 'inline_attach':
1263 $body .= $this->textLine('--' . $this->boundary[1]);
1264 $body .= $this->headerLine('Content-Type', 'multipart/related;');
1265 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
1266 $body .= $this->LE;
1267 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
1268 $body .= $this->encodeString($this->Body, $bodyEncoding);
1269 $body .= $this->LE . $this->LE;
1270 $body .= $this->attachAll('inline', $this->boundary[2]);
1271 $body .= $this->LE;
1272 $body .= $this->attachAll('attachment', $this->boundary[1]);
1273 break;
1274 case 'alt':
1275 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
1276 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
1277 $body .= $this->LE . $this->LE;
1278 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
1279 $body .= $this->encodeString($this->Body, $bodyEncoding);
1280 $body .= $this->LE . $this->LE;
1281 if (!empty($this->Ical)) {
1282 $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
1283 $body .= $this->encodeString($this->Ical, $this->Encoding);
1284 $body .= $this->LE . $this->LE;
1285 }
1286 $body .= $this->endBoundary($this->boundary[1]);
1287 break;
1288 case 'alt_inline':
1289 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
1290 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
1291 $body .= $this->LE . $this->LE;
1292 $body .= $this->textLine('--' . $this->boundary[1]);
1293 $body .= $this->headerLine('Content-Type', 'multipart/related;');
1294 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
1295 $body .= $this->LE;
1296 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
1297 $body .= $this->encodeString($this->Body, $bodyEncoding);
1298 $body .= $this->LE . $this->LE;
1299 $body .= $this->attachAll('inline', $this->boundary[2]);
1300 $body .= $this->LE;
1301 $body .= $this->endBoundary($this->boundary[1]);
1302 break;
1303 case 'alt_attach':
1304 $body .= $this->textLine('--' . $this->boundary[1]);
1305 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
1306 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
1307 $body .= $this->LE;
1308 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
1309 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
1310 $body .= $this->LE . $this->LE;
1311 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
1312 $body .= $this->encodeString($this->Body, $bodyEncoding);
1313 $body .= $this->LE . $this->LE;
1314 $body .= $this->endBoundary($this->boundary[2]);
1315 $body .= $this->LE;
1316 $body .= $this->attachAll('attachment', $this->boundary[1]);
1317 break;
1318 case 'alt_inline_attach':
1319 $body .= $this->textLine('--' . $this->boundary[1]);
1320 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
1321 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
1322 $body .= $this->LE;
1323 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
1324 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
1325 $body .= $this->LE . $this->LE;
1326 $body .= $this->textLine('--' . $this->boundary[2]);
1327 $body .= $this->headerLine('Content-Type', 'multipart/related;');
1328 $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
1329 $body .= $this->LE;
1330 $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
1331 $body .= $this->encodeString($this->Body, $bodyEncoding);
1332 $body .= $this->LE . $this->LE;
1333 $body .= $this->attachAll('inline', $this->boundary[3]);
1334 $body .= $this->LE;
1335 $body .= $this->endBoundary($this->boundary[2]);
1336 $body .= $this->LE;
1337 $body .= $this->attachAll('attachment', $this->boundary[1]);
1338 break;
1339 default:
1340 $body .= $this->encodeString($this->Body, $bodyEncoding);
1341 break;
1342 }
1343 if ($this->isError()) {
1344 $body = '';
1345 } elseif ($this->sign_key_file) {
1346 try {
1347 if (!defined('PKCS7_TEXT')) {
1348 throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
1349 }
1350 $file = tempnam(sys_get_temp_dir(), 'mail');
1351 file_put_contents($file, $body);
1352 $signed = tempnam(sys_get_temp_dir(), 'signed');
1353 if (@openssl_pkcs7_sign($file, $signed, 'file://' . realpath($this->sign_cert_file), array('file://' . realpath($this->sign_key_file), $this->sign_key_pass), null)) {
1354 @unlink($file);
1355 $body = file_get_contents($signed);
1356 @unlink($signed);
1357 } else {
1358 @unlink($file);
1359 @unlink($signed);
1360 throw new phpmailerException($this->lang('signing') . openssl_error_string());
1361 }
1362 } catch (phpmailerException $exc) {
1363 $body = '';
1364 if ($this->exceptions) {
1365 throw $exc;
1366 }
1367 }
1368 }
1369 return $body;
1370 }
1371 public function setWordWrap()
1372 {
1373 if ($this->WordWrap < 1) {
1374 return;
1375 }
1376 switch ($this->message_type) {
1377 case 'alt':
1378 case 'alt_inline':
1379 case 'alt_attach':
1380 case 'alt_inline_attach':
1381 $this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
1382 break;
1383 default:
1384 $this->Body = $this->wrapText($this->Body, $this->WordWrap);
1385 break;
1386 }
1387 }
1388 public function has8bitChars($text)
1389 {
1390 return (boolean)preg_match('/[\x80-\xFF]/', $text);
1391 }
1392 protected function getBoundary($boundary, $charSet, $contentType, $encoding)
1393 {
1394 $result = '';
1395 if ($charSet == '') {
1396 $charSet = $this->CharSet;
1397 }
1398 if ($contentType == '') {
1399 $contentType = $this->ContentType;
1400 }
1401 if ($encoding == '') {
1402 $encoding = $this->Encoding;
1403 }
1404 $result .= $this->textLine('--' . $boundary);
1405 $result .= sprintf('Content-Type: %s;charset=%s', $contentType, $charSet);
1406 $result .= $this->LE;
1407 if ($encoding != '7bit') {
1408 $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
1409 }
1410 $result .= $this->LE;
1411 return $result;
1412 }
1413 public function encodeString($str, $encoding = 'base64')
1414 {
1415 $encoded = '';
1416 switch (strtolower($encoding)) {
1417 case 'base64':
1418 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
1419 break;
1420 case '7bit':
1421 case '8bit':
1422 $encoded = $this->fixEOL($str);
1423 if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
1424 $encoded .= $this->LE;
1425 }
1426 break;
1427 case 'binary':
1428 $encoded = $str;
1429 break;
1430 case 'quoted-printable':
1431 $encoded = $this->encodeQP($str);
1432 break;
1433 default:
1434 $this->setError($this->lang('encoding') . $encoding);
1435 break;
1436 }
1437 return $encoded;
1438 }
1439 public function encodeQP($string, $line_max = 76)
1440 {
1441 if (function_exists('quoted_printable_encode')) {
1442 return $this->fixEOL(quoted_printable_encode($string));
1443 }
1444 $string = str_replace(array('%20', '%0D%0A.', '%0D%0A', '%'), array(' ', "\r\n=2E", "\r\n", '='), rawurlencode($string));
1445 $string = preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
1446 return $this->fixEOL($string);
1447 }
1448 protected function attachAll($disposition_type, $boundary)
1449 {
1450 $mime = array();
1451 $cidUniq = array();
1452 $incl = array();
1453 foreach ($this->attachment as $attachment) {
1454 if ($attachment[6] == $disposition_type) {
1455 $string = '';
1456 $path = '';
1457 $bString = $attachment[5];
1458 if ($bString) {
1459 $string = $attachment[0];
1460 } else {
1461 $path = $attachment[0];
1462 }
1463 $inclhash = md5(serialize($attachment));
1464 if (in_array($inclhash, $incl)) {
1465 continue;
1466 }
1467 $incl[] = $inclhash;
1468 $name = $attachment[2];
1469 $encoding = $attachment[3];
1470 $type = $attachment[4];
1471 $disposition = $attachment[6];
1472 $cid = $attachment[7];
1473 if ($disposition == 'inline' && isset($cidUniq[$cid])) {
1474 continue;
1475 }
1476 $cidUniq[$cid] = true;
1477 $mime[] = sprintf('--%s%s', $boundary, $this->LE);
1478 $mime[] = sprintf('Content-Type: %s; name="%s"%s', $type, $this->encodeHeader($this->secureHeader($name)), $this->LE);
1479 if ($encoding != '7bit') {
1480 $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
1481 }
1482 if ($disposition == 'inline') {
1483 $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
1484 }
1485 if (!(empty($disposition))) {
1486 if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $name)) {
1487 $mime[] = sprintf('Content-Disposition: %s;filename="%s"%s', $disposition, $this->encodeHeader($this->secureHeader($name)), $this->LE . $this->LE);
1488 } else {
1489 $mime[] = sprintf('Content-Disposition: %s; filename=%s%s', $disposition, $this->encodeHeader($this->secureHeader($name)), $this->LE . $this->LE);
1490 }
1491 } else {
1492 $mime[] = $this->LE;
1493 }
1494 if ($bString) {
1495 $mime[] = $this->encodeString($string, $encoding);
1496 if ($this->isError()) {
1497 return '';
1498 }
1499 $mime[] = $this->LE . $this->LE;
1500 } else {
1501 $mime[] = $this->encodeFile($path, $encoding);
1502 if ($this->isError()) {
1503 return '';
1504 }
1505 $mime[] = $this->LE . $this->LE;
1506 }
1507 }
1508 }
1509 $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
1510 return implode('', $mime);
1511 }
1512 public function isError()
1513 {
1514 return ($this->error_count > 0);
1515 }
1516 protected function encodeFile($path, $encoding = 'base64')
1517 {
1518 try {
1519 if (!is_readable($path)) {
1520 throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
1521 }
1522 $magic_quotes = get_magic_quotes_runtime();
1523 if ($magic_quotes) {
1524 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
1525 set_magic_quotes_runtime(false);
1526 } else {
1527 ini_set('magic_quotes_runtime', 0);
1528 }
1529 }
1530 $file_buffer = file_get_contents($path);
1531 $file_buffer = $this->encodeString($file_buffer, $encoding);
1532 if ($magic_quotes) {
1533 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
1534 set_magic_quotes_runtime($magic_quotes);
1535 } else {
1536 ini_set('magic_quotes_runtime', ($magic_quotes ? '1' : '0'));
1537 }
1538 }
1539 return $file_buffer;
1540 } catch (Exception $exc) {
1541 $this->setError($exc->getMessage());
1542 return '';
1543 }
1544 }
1545 protected function endBoundary($boundary)
1546 {
1547 return $this->LE . '--' . $boundary . '--' . $this->LE;
1548 }
1549 public function DKIM_Add($headers_line, $subject, $body)
1550 {
1551 $DKIMsignatureType = 'rsa-sha1';
1552 $DKIMcanonicalization = 'relaxed/simple';
1553 $DKIMquery = 'dns/txt';
1554 $DKIMtime = time();
1555 $subject_header = "Subject: $subject";
1556 $headers = explode($this->LE, $headers_line);
1557 $from_header = '';
1558 $to_header = '';
1559 $current = '';
1560 foreach ($headers as $header) {
1561 if (strpos($header, 'From:') === 0) {
1562 $from_header = $header;
1563 $current = 'from_header';
1564 } elseif (strpos($header, 'To:') === 0) {
1565 $to_header = $header;
1566 $current = 'to_header';
1567 } else {
1568 if ($current && strpos($header, ' =?') === 0) {
1569 $current .= $header;
1570 } else {
1571 $current = '';
1572 }
1573 }
1574 }
1575 $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
1576 $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
1577 $subject = str_replace('|', '=7C', $this->DKIM_QP($subject_header));
1578 $body = $this->DKIM_BodyC($body);
1579 $DKIMlen = strlen($body);
1580 $DKIMb64 = base64_encode(pack('H*', sha1($body)));
1581 $ident = ($this->DKIM_identity == '') ? '' : ' i=' . $this->DKIM_identity . ';';
1582 $dkimhdrs = 'DKIM-Signature: v=1; a=' . $DKIMsignatureType . '; q=' . $DKIMquery . '; l=' . $DKIMlen . '; s=' . $this->DKIM_selector . ";\r\n" . "\tt=" . $DKIMtime . ';c=' . $DKIMcanonicalization . ";\r\n" . "\th=From:To:Subject;\r\n" . "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" . "\tz=$from\r\n" . "\t|$to\r\n" . "\t|$subject;\r\n" . "\tbh=" . $DKIMb64 . ";\r\n" . "\tb=";
1583 $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
1584 $signed = $this->DKIM_Sign($toSign);
1585 return $dkimhdrs . $signed . "\r\n";
1586 }
1587 public function DKIM_QP($txt)
1588 {
1589 $line = '';
1590 for ($i = 0;
1591 $i < strlen($txt);
1592 $i++) {
1593 $ord = ord($txt[$i]);
1594 if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
1595 $line .= $txt[$i];
1596 } else {
1597 $line .= '=' . sprintf('%02X', $ord);
1598 }
1599 }
1600 return $line;
1601 }
1602 public function DKIM_BodyC($body)
1603 {
1604 if ($body == '') {
1605 return "\r\n";
1606 }
1607 $body = str_replace("\r\n", "\n", $body);
1608 $body = str_replace("\n", "\r\n", $body);
1609 while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
1610 $body = substr($body, 0, strlen($body) - 2);
1611 }
1612 return $body;
1613 }
1614 public function DKIM_HeaderC($signHeader)
1615 {
1616 $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
1617 $lines = explode("\r\n", $signHeader);
1618 foreach ($lines as $key => $line) {
1619 list($heading, $value) = explode(':', $line, 2);
1620 $heading = strtolower($heading);
1621 $value = preg_replace('/\s+/', ' ', $value);
1622 $lines[$key] = $heading . ':' . trim($value);
1623 }
1624 $signHeader = implode("\r\n", $lines);
1625 return $signHeader;
1626 }
1627 public function DKIM_Sign($signHeader)
1628 {
1629 if (!defined('PKCS7_TEXT')) {
1630 if ($this->exceptions) {
1631 throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
1632 }
1633 return '';
1634 }
1635 $privKeyStr = file_get_contents($this->DKIM_private);
1636 if ($this->DKIM_passphrase != '') {
1637 $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
1638 } else {
1639 $privKey = $privKeyStr;
1640 }
1641 if (openssl_sign($signHeader, $signature, $privKey)) {
1642 return base64_encode($signature);
1643 }
1644 return '';
1645 }
1646 public function postSend()
1647 {
1648 try {
1649 switch ($this->Mailer) {
1650 case 'sendmail':
1651 case 'qmail':
1652 return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
1653 case 'smtp':
1654 return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
1655 case 'mail':
1656 return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
1657 default:
1658 $sendMethod = $this->Mailer . 'Send';
1659 if (method_exists($this, $sendMethod)) {
1660 return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
1661 }
1662 return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
1663 }
1664 } catch (phpmailerException $exc) {
1665 $this->setError($exc->getMessage());
1666 $this->edebug($exc->getMessage());
1667 if ($this->exceptions) {
1668 throw $exc;
1669 }
1670 }
1671 return false;
1672 }
1673 protected function sendmailSend($header, $body)
1674 {
1675 if ($this->Sender != '') {
1676 if ($this->Mailer == 'qmail') {
1677 $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
1678 } else {
1679 $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
1680 }
1681 } else {
1682 if ($this->Mailer == 'qmail') {
1683 $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
1684 } else {
1685 $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
1686 }
1687 }
1688 if ($this->SingleTo === true) {
1689 foreach ($this->SingleToArray as $toAddr) {
1690 if (!@$mail = popen($sendmail, 'w')) {
1691 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1692 }
1693 fputs($mail, 'To: ' . $toAddr . "\n");
1694 fputs($mail, $header);
1695 fputs($mail, $body);
1696 $result = pclose($mail);
1697 $this->doCallback(($result == 0), array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1698 if ($result != 0) {
1699 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1700 }
1701 }
1702 } else {
1703 if (!@$mail = popen($sendmail, 'w')) {
1704 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1705 }
1706 fputs($mail, $header);
1707 fputs($mail, $body);
1708 $result = pclose($mail);
1709 $this->doCallback(($result == 0), $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1710 if ($result != 0) {
1711 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1712 }
1713 }
1714 return true;
1715 }
1716 protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
1717 {
1718 if (!empty($this->action_function) && is_callable($this->action_function)) {
1719 $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
1720 call_user_func_array($this->action_function, $params);
1721 }
1722 }
1723 protected function smtpSend($header, $body)
1724 {
1725 $bad_rcpt = array();
1726 if (!$this->smtpConnect()) {
1727 throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
1728 }
1729 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
1730 if (!$this->smtp->mail($smtp_from)) {
1731 $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
1732 throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
1733 }
1734 foreach ($this->to as $to) {
1735 if (!$this->smtp->recipient($to[0])) {
1736 $bad_rcpt[] = $to[0];
1737 $isSent = false;
1738 } else {
1739 $isSent = true;
1740 }
1741 $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
1742 }
1743 foreach ($this->cc as $cc) {
1744 if (!$this->smtp->recipient($cc[0])) {
1745 $bad_rcpt[] = $cc[0];
1746 $isSent = false;
1747 } else {
1748 $isSent = true;
1749 }
1750 $this->doCallback($isSent, array(), array($cc[0]), array(), $this->Subject, $body, $this->From);
1751 }
1752 foreach ($this->bcc as $bcc) {
1753 if (!$this->smtp->recipient($bcc[0])) {
1754 $bad_rcpt[] = $bcc[0];
1755 $isSent = false;
1756 } else {
1757 $isSent = true;
1758 }
1759 $this->doCallback($isSent, array(), array(), array($bcc[0]), $this->Subject, $body, $this->From);
1760 }
1761 if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
1762 throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
1763 }
1764 if ($this->SMTPKeepAlive == true) {
1765 $this->smtp->reset();
1766 } else {
1767 $this->smtp->quit();
1768 $this->smtp->close();
1769 }
1770 if (count($bad_rcpt) > 0) {
1771 throw new phpmailerException($this->lang('recipients_failed') . implode(', ', $bad_rcpt), self::STOP_CONTINUE);
1772 }
1773 return true;
1774 }
1775 public function smtpConnect($options = array())
1776 {
1777 if (is_null($this->smtp)) {
1778 $this->smtp = $this->getSMTPInstance();
1779 }
1780 if ($this->smtp->connected()) {
1781 return true;
1782 }
1783 $this->smtp->setTimeout($this->Timeout);
1784 $this->smtp->setDebugLevel($this->SMTPDebug);
1785 $this->smtp->setDebugOutput($this->Debugoutput);
1786 $this->smtp->setVerp($this->do_verp);
1787 $hosts = explode(';
1788', $this->Host);
1789 $lastexception = null;
1790 foreach ($hosts as $hostentry) {
1791 $hostinfo = array();
1792 if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
1793 continue;
1794 }
1795 $prefix = '';
1796 $tls = ($this->SMTPSecure == 'tls');
1797 if ($hostinfo[2] == 'ssl' or ($hostinfo[2] == '' and $this->SMTPSecure == 'ssl')) {
1798 $prefix = 'ssl://';
1799 $tls = false;
1800 } elseif ($hostinfo[2] == 'tls') {
1801 $tls = true;
1802 }
1803 $host = $hostinfo[3];
1804 $port = $this->Port;
1805 $tport = (integer)$hostinfo[4];
1806 if ($tport > 0 and $tport < 65536) {
1807 $port = $tport;
1808 }
1809 if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
1810 try {
1811 if ($this->Helo) {
1812 $hello = $this->Helo;
1813 } else {
1814 $hello = $this->serverHostname();
1815 }
1816 $this->smtp->hello($hello);
1817 if ($tls) {
1818 if (!$this->smtp->startTLS()) {
1819 throw new phpmailerException($this->lang('connect_host'));
1820 }
1821 $this->smtp->hello($hello);
1822 }
1823 if ($this->SMTPAuth) {
1824 if (!$this->smtp->authenticate($this->Username, $this->Password, $this->AuthType, $this->Realm, $this->Workstation)) {
1825 throw new phpmailerException($this->lang('authenticate'));
1826 }
1827 }
1828 return true;
1829 } catch (phpmailerException $exc) {
1830 $lastexception = $exc;
1831 $this->smtp->quit();
1832 }
1833 }
1834 }
1835 $this->smtp->close();
1836 if ($this->exceptions and !is_null($lastexception)) {
1837 throw $lastexception;
1838 }
1839 return false;
1840 }
1841 public function getSMTPInstance()
1842 {
1843 if (!is_object($this->smtp)) {
1844 $this->smtp = new SMTP;
1845 }
1846 return $this->smtp;
1847 }
1848 protected function mailSend($header, $body)
1849 {
1850 $toArr = array();
1851 foreach ($this->to as $toaddr) {
1852 $toArr[] = $this->addrFormat($toaddr);
1853 }
1854 $to = implode(', ', $toArr);
1855 if (empty($this->Sender)) {
1856 $params = ' ';
1857 } else {
1858 $params = sprintf('-f%s', $this->Sender);
1859 }
1860 if ($this->Sender != '' and !ini_get('safe_mode')) {
1861 $old_from = ini_get('sendmail_from');
1862 ini_set('sendmail_from', $this->Sender);
1863 }
1864 $result = false;
1865 if ($this->SingleTo === true && count($toArr) > 1) {
1866 foreach ($toArr as $toAddr) {
1867 $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
1868 $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1869 }
1870 } else {
1871 $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
1872 $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1873 }
1874 if (isset($old_from)) {
1875 ini_set('sendmail_from', $old_from);
1876 }
1877 if (!$result) {
1878 throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
1879 }
1880 return true;
1881 }
1882 private function mailPassthru($to, $subject, $body, $header, $params)
1883 {
1884 if (ini_get('mbstring.func_overload') & 1) {
1885 $subject = $this->secureHeader($subject);
1886 } else {
1887 $subject = $this->encodeHeader($this->secureHeader($subject));
1888 }
1889 if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
1890 $result = @mail($to, $subject, $body, $header);
1891 } else {
1892 $result = @mail($to, $subject, $body, $header, $params);
1893 }
1894 return $result;
1895 }
1896 public function getTranslations()
1897 {
1898 return $this->language;
1899 }
1900 public function getSentMIMEMessage()
1901 {
1902 return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
1903 }
1904 public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
1905 {
1906 try {
1907 if (!@is_file($path)) {
1908 throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
1909 }
1910 if ($type == '') {
1911 $type = self::filenameToType($path);
1912 }
1913 $filename = basename($path);
1914 if ($name == '') {
1915 $name = $filename;
1916 }
1917 $this->attachment[] = array(0 => $path, 1 => $filename, 2 => $name, 3 => $encoding, 4 => $type, 5 => false, 6 => $disposition, 7 => 0);
1918 } catch (phpmailerException $exc) {
1919 $this->setError($exc->getMessage());
1920 $this->edebug($exc->getMessage());
1921 if ($this->exceptions) {
1922 throw $exc;
1923 }
1924 return false;
1925 }
1926 return true;
1927 }
1928 public static function filenameToType($filename)
1929 {
1930 $qpos = strpos($filename, '?');
1931 if ($qpos !== false) {
1932 $filename = substr($filename, 0, $qpos);
1933 }
1934 $pathinfo = self::mb_pathinfo($filename);
1935 return self::_mime_types($pathinfo['extension']);
1936 }
1937 public static function mb_pathinfo($path, $options = null)
1938 {
1939 $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
1940 $pathinfo = array();
1941 if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
1942 if (array_key_exists(1, $pathinfo)) {
1943 $ret['dirname'] = $pathinfo[1];
1944 }
1945 if (array_key_exists(2, $pathinfo)) {
1946 $ret['basename'] = $pathinfo[2];
1947 }
1948 if (array_key_exists(5, $pathinfo)) {
1949 $ret['extension'] = $pathinfo[5];
1950 }
1951 if (array_key_exists(3, $pathinfo)) {
1952 $ret['filename'] = $pathinfo[3];
1953 }
1954 }
1955 switch ($options) {
1956 case PATHINFO_DIRNAME:
1957 case 'dirname':
1958 return $ret['dirname'];
1959 case PATHINFO_BASENAME:
1960 case 'basename':
1961 return $ret['basename'];
1962 case PATHINFO_EXTENSION:
1963 case 'extension':
1964 return $ret['extension'];
1965 case PATHINFO_FILENAME:
1966 case 'filename':
1967 return $ret['filename'];
1968 default:
1969 return $ret;
1970 }
1971 }
1972 public static function _mime_types($ext = '')
1973 {
1974 $mimes = array('xl' => 'application/excel', 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', 'bin' => 'application/macbinary', 'doc' => 'application/msword', 'word' => 'application/msword', 'class' => 'application/octet-stream', 'dll' => 'application/octet-stream', 'dms' => 'application/octet-stream', 'exe' => 'application/octet-stream', 'lha' => 'application/octet-stream', 'lzh' => 'application/octet-stream', 'psd' => 'application/octet-stream', 'sea' => 'application/octet-stream', 'so' => 'application/octet-stream', 'oda' => 'application/oda', 'pdf' => 'application/pdf', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'smi' => 'application/smil', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'wbxml' => 'application/vnd.wap.wbxml', 'wmlc' => 'application/vnd.wap.wmlc', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 'dxr' => 'application/x-director', 'dvi' => 'application/x-dvi', 'gtar' => 'application/x-gtar', 'php3' => 'application/x-httpd-php', 'php4' => 'application/x-httpd-php', 'php' => 'application/x-httpd-php', 'phtml' => 'application/x-httpd-php', 'phps' => 'application/x-httpd-php-source', 'js' => 'application/x-javascript', 'swf' => 'application/x-shockwave-flash', 'sit' => 'application/x-stuffit', 'tar' => 'application/x-tar', 'tgz' => 'application/x-tar', 'xht' => 'application/xhtml+xml', 'xhtml' => 'application/xhtml+xml', 'zip' => 'application/zip', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 'mpga' => 'audio/mpeg', 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio', 'rpm' => 'audio/x-pn-realaudio-plugin', 'ra' => 'audio/x-realaudio', 'wav' => 'audio/x-wav', 'bmp' => 'image/bmp', 'gif' => 'image/gif', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'jpg' => 'image/jpeg', 'png' => 'image/png', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'eml' => 'message/rfc822', 'css' => 'text/css', 'html' => 'text/html', 'htm' => 'text/html', 'shtml' => 'text/html', 'log' => 'text/plain', 'text' => 'text/plain', 'txt' => 'text/plain', 'rtx' => 'text/richtext', 'rtf' => 'text/rtf', 'vcf' => 'text/vcard', 'vcard' => 'text/vcard', 'xml' => 'text/xml', 'xsl' => 'text/xml', 'mpeg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mov' => 'video/quicktime', 'qt' => 'video/quicktime', 'rv' => 'video/vnd.rn-realvideo', 'avi' => 'video/x-msvideo', 'movie' => 'video/x-sgi-movie');
1975 return (array_key_exists(strtolower($ext), $mimes) ? $mimes[strtolower($ext)] : 'application/octet-stream');
1976 }
1977 public function getAttachments()
1978 {
1979 return $this->attachment;
1980 }
1981 public function encodeQPphp($string, $line_max = 76, $space_conv = false)
1982 {
1983 return $this->encodeQP($string, $line_max);
1984 }
1985 public function addStringAttachment($string, $filename, $encoding = 'base64', $type = '', $disposition = 'attachment')
1986 {
1987 if ($type == '') {
1988 $type = self::filenameToType($filename);
1989 }
1990 $this->attachment[] = array(0 => $string, 1 => $filename, 2 => basename($filename), 3 => $encoding, 4 => $type, 5 => true, 6 => $disposition, 7 => 0);
1991 }
1992 public function addStringEmbeddedImage($string, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
1993 {
1994 if ($type == '') {
1995 $type = self::filenameToType($name);
1996 }
1997 $this->attachment[] = array(0 => $string, 1 => $name, 2 => $name, 3 => $encoding, 4 => $type, 5 => true, 6 => $disposition, 7 => $cid);
1998 return true;
1999 }
2000 public function clearAddresses()
2001 {
2002 foreach ($this->to as $to) {
2003 unset($this->all_recipients[strtolower($to[0])]);
2004 }
2005 $this->to = array();
2006 }
2007 public function clearCCs()
2008 {
2009 foreach ($this->cc as $cc) {
2010 unset($this->all_recipients[strtolower($cc[0])]);
2011 }
2012 $this->cc = array();
2013 }
2014 public function clearBCCs()
2015 {
2016 foreach ($this->bcc as $bcc) {
2017 unset($this->all_recipients[strtolower($bcc[0])]);
2018 }
2019 $this->bcc = array();
2020 }
2021 public function clearReplyTos()
2022 {
2023 $this->ReplyTo = array();
2024 }
2025 public function clearAllRecipients()
2026 {
2027 $this->to = array();
2028 $this->cc = array();
2029 $this->bcc = array();
2030 $this->all_recipients = array();
2031 }
2032 public function clearAttachments()
2033 {
2034 $this->attachment = array();
2035 }
2036 public function clearCustomHeaders()
2037 {
2038 $this->CustomHeader = array();
2039 }
2040 public function addCustomHeader($name, $value = null)
2041 {
2042 if ($value === null) {
2043 $this->CustomHeader[] = explode(':', $name, 2);
2044 } else {
2045 $this->CustomHeader[] = array($name, $value);
2046 }
2047 }
2048 public function msgHTML($message, $basedir = '', $advanced = false)
2049 {
2050 preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
2051 if (isset($images[2])) {
2052 foreach ($images[2] as $imgindex => $url) {
2053 if (!preg_match('#^[A-z]+://#', $url)) {
2054 $filename = basename($url);
2055 $directory = dirname($url);
2056 if ($directory == '.') {
2057 $directory = '';
2058 }
2059 $cid = md5($url) . '@phpmailer.0';
2060 if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
2061 $basedir .= '/';
2062 }
2063 if (strlen($directory) > 1 && substr($directory, -1) != '/') {
2064 $directory .= '/';
2065 }
2066 if ($this->addEmbeddedImage($basedir . $directory . $filename, $cid, $filename, 'base64', self::_mime_types(self::mb_pathinfo($filename, PATHINFO_EXTENSION)))) {
2067 $message = preg_replace('/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui', $images[1][$imgindex] . '="cid:' . $cid . '"', $message);
2068 }
2069 }
2070 }
2071 }
2072 $this->isHTML(true);
2073 $this->Body = $this->normalizeBreaks($message);
2074 $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
2075 if (empty($this->AltBody)) {
2076 $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . self::CRLF . self::CRLF;
2077 }
2078 return $this->Body;
2079 }
2080 public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
2081 {
2082 if (!@is_file($path)) {
2083 $this->setError($this->lang('file_access') . $path);
2084 return false;
2085 }
2086 if ($type == '') {
2087 $type = self::filenameToType($path);
2088 }
2089 $filename = basename($path);
2090 if ($name == '') {
2091 $name = $filename;
2092 }
2093 $this->attachment[] = array(0 => $path, 1 => $filename, 2 => $name, 3 => $encoding, 4 => $type, 5 => false, 6 => $disposition, 7 => $cid);
2094 return true;
2095 }
2096 public function isHTML($isHtml = true)
2097 {
2098 if ($isHtml) {
2099 $this->ContentType = 'text/html';
2100 } else {
2101 $this->ContentType = 'text/plain';
2102 }
2103 }
2104 public static function normalizeBreaks($text, $breaktype = "\r\n")
2105 {
2106 return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
2107 }
2108 public function html2text($html, $advanced = false)
2109 {
2110 if ($advanced) {
2111 $htmlconverter = new html2text($html);
2112 return $htmlconverter->get_text();
2113 }
2114 return html_entity_decode(trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))), ENT_QUOTES, $this->CharSet);
2115 }
2116 public function set($name, $value = '')
2117 {
2118 try {
2119 if (isset($this->$name)) {
2120 $this->$name = $value;
2121 } else {
2122 throw new phpmailerException($this->lang('variable_set') . $name, self::STOP_CRITICAL);
2123 }
2124 } catch (Exception $exc) {
2125 $this->setError($exc->getMessage());
2126 if ($exc->getCode() == self::STOP_CRITICAL) {
2127 return false;
2128 }
2129 }
2130 return true;
2131 }
2132 public function sign($cert_filename, $key_filename, $key_pass)
2133 {
2134 $this->sign_cert_file = $cert_filename;
2135 $this->sign_key_file = $key_filename;
2136 $this->sign_key_pass = $key_pass;
2137 }
2138 public function getToAddresses()
2139 {
2140 return $this->to;
2141 }
2142 public function getCcAddresses()
2143 {
2144 return $this->cc;
2145 }
2146 public function getBccAddresses()
2147 {
2148 return $this->bcc;
2149 }
2150 public function getReplyToAddresses()
2151 {
2152 return $this->ReplyTo;
2153 }
2154 public function getAllRecipientAddresses()
2155 {
2156 return $this->all_recipients;
2157 }
2158}
2159class Html2Text
2160{
2161 protected $html;
2162 protected $text;
2163 protected $width = 70;
2164 protected $search = array(
2165 "/\r/", // Non-legal carriage return
2166 "/[\n\t]+/", // Newlines and tabs
2167 '/<head[^>]*>.*?<\/head>/i', // <head>
2168 '/<script[^>]*>.*?<\/script>/i', // <script>s -- which strip_tags supposedly has problems with
2169 '/<style[^>]*>.*?<\/style>/i', // <style>s -- which strip_tags supposedly has problems with
2170 '/<p[^>]*>/i', // <P>
2171 '/<br[^>]*>/i', // <br>
2172 '/<i[^>]*>(.*?)<\/i>/i', // <i>
2173 '/<em[^>]*>(.*?)<\/em>/i', // <em>
2174 '/(<ul[^>]*>|<\/ul>)/i', // <ul> and </ul>
2175 '/(<ol[^>]*>|<\/ol>)/i', // <ol> and </ol>
2176 '/(<dl[^>]*>|<\/dl>)/i', // <dl> and </dl>
2177 '/<li[^>]*>(.*?)<\/li>/i', // <li> and </li>
2178 '/<dd[^>]*>(.*?)<\/dd>/i', // <dd> and </dd>
2179 '/<dt[^>]*>(.*?)<\/dt>/i', // <dt> and </dt>
2180 '/<li[^>]*>/i', // <li>
2181 '/<hr[^>]*>/i', // <hr>
2182 '/<div[^>]*>/i', // <div>
2183 '/(<table[^>]*>|<\/table>)/i', // <table> and </table>
2184 '/(<tr[^>]*>|<\/tr>)/i', // <tr> and </tr>
2185 '/<td[^>]*>(.*?)<\/td>/i', // <td> and </td>
2186 '/<span class="_html2text_ignore">.+?<\/span>/i' // <span class="_html2text_ignore">...</span>
2187 );
2188 protected $replace = array(
2189 '', // Non-legal carriage return
2190 ' ', // Newlines and tabs
2191 '', // <head>
2192 '', // <script>s -- which strip_tags supposedly has problems with
2193 '', // <style>s -- which strip_tags supposedly has problems with
2194 "\n\n", // <P>
2195 "\n", // <br>
2196 '_\\1_', // <i>
2197 '_\\1_', // <em>
2198 "\n\n", // <ul> and </ul>
2199 "\n\n", // <ol> and </ol>
2200 "\n\n", // <dl> and </dl>
2201 "\t* \\1\n", // <li> and </li>
2202 " \\1\n", // <dd> and </dd>
2203 "\t* \\1", // <dt> and </dt>
2204 "\n\t* ", // <li>
2205 "\n-------------------------\n", // <hr>
2206 "<div>\n", // <div>
2207 "\n\n", // <table> and </table>
2208 "\n", // <tr> and </tr>
2209 "\t\t\\1\n", // <td> and </td>
2210 "" // <span class="_html2text_ignore">...</span>
2211 );
2212 protected $ent_search = array(
2213 '/&(nbsp|#160);/i', // Non-breaking space
2214 '/&(quot|rdquo|ldquo|#8220|#8221|#147|#148);/i',
2215 // Double quotes
2216 '/&(apos|rsquo|lsquo|#8216|#8217);/i', // Single quotes
2217 '/>/i', // Greater-than
2218 '/</i', // Less-than
2219 '/&(copy|#169);/i', // Copyright
2220 '/&(trade|#8482|#153);/i', // Trademark
2221 '/&(reg|#174);/i', // Registered
2222 '/&(mdash|#151|#8212);/i', // mdash
2223 '/&(ndash|minus|#8211|#8722);/i', // ndash
2224 '/&(bull|#149|#8226);/i', // Bullet
2225 '/&(pound|#163);/i', // Pound sign
2226 '/&(euro|#8364);/i', // Euro sign
2227 '/&(amp|#38);/i', // Ampersand: see _converter()
2228 '/[ ]{2,}/', // Runs of spaces, post-handling
2229 );
2230 protected $ent_replace = array(
2231 ' ', // Non-breaking space
2232 '"', // Double quotes
2233 "'", // Single quotes
2234 '>',
2235 '<',
2236 '(c)',
2237 '(tm)',
2238 '(R)',
2239 '--',
2240 '-',
2241 '*',
2242 '£',
2243 'EUR', // Euro sign. € ?
2244 '|+|amp|+|', // Ampersand: see _converter()
2245 ' ', // Runs of spaces, post-handling
2246 );
2247 protected $callback_search = array(
2248 '/<(a) [^>]*href=("|\')([^"\']+)\2([^>]*)>(.*?)<\/a>/i', // <a href="">
2249 '/<(h)[123456]( [^>]*)?>(.*?)<\/h[123456]>/i', // h1 - h6
2250 '/<(b)( [^>]*)?>(.*?)<\/b>/i', // <b>
2251 '/<(strong)( [^>]*)?>(.*?)<\/strong>/i', // <strong>
2252 '/<(th)( [^>]*)?>(.*?)<\/th>/i', // <th> and </th>
2253 );
2254 protected $pre_search = array(
2255 "/\n/",
2256 "/\t/",
2257 '/ /',
2258 '/<pre[^>]*>/',
2259 '/<\/pre>/'
2260 );
2261 protected $pre_replace = array(
2262 '<br>',
2263 ' ',
2264 ' ',
2265 '',
2266 ''
2267 );
2268 protected $pre_content = '';
2269 protected $allowed_tags = '';
2270 protected $url;
2271 protected $_converted = false;
2272 protected $_link_list = array();
2273 protected $_options = array(
2274 // 'none'
2275 // 'inline' (show links inline)
2276 // 'nextline' (show links on the next line)
2277 // 'table' (if a table of link URLs should be listed after the text.
2278 'do_links' => 'inline',
2279 // Maximum width of the formatted text, in columns.
2280 // Set this value to 0 (or less) to ignore word wrapping
2281 // and not constrain text to a fixed-width column.
2282 'width' => -1,
2283 );
2284 public function __construct($source = '', $from_file = false, $options = array())
2285 {
2286 $this->_options = array_merge($this->_options, $options);
2287 if (!empty($source)) {
2288 $this->set_html($source, $from_file);
2289 }
2290 $this->set_base_url();
2291 }
2292 public function set_html($source, $from_file = false)
2293 {
2294 if ($from_file && file_exists($source)) {
2295 $this->html = file_get_contents($source);
2296 } else {
2297 $this->html = $source;
2298 }
2299 $this->_converted = false;
2300 }
2301 public function get_text()
2302 {
2303 if (!$this->_converted) {
2304 $this->_convert();
2305 }
2306 return $this->text;
2307 }
2308 public function print_text()
2309 {
2310 print $this->get_text();
2311 }
2312 public function p()
2313 {
2314 print $this->get_text();
2315 }
2316 public function set_allowed_tags($allowed_tags = '')
2317 {
2318 if (!empty($allowed_tags)) {
2319 $this->allowed_tags = $allowed_tags;
2320 }
2321 }
2322 public function set_base_url($url = '')
2323 {
2324 if (empty($url)) {
2325 if (!empty($_SERVER['HTTP_HOST'])) {
2326 $this->url = 'http://' . $_SERVER['HTTP_HOST'];
2327 } else {
2328 $this->url = '';
2329 }
2330 } else {
2331 // Strip any trailing slashes for consistency (relative
2332 // URLs may already start with a slash like "/file.html")
2333 if (substr($url, -1) == '/') {
2334 $url = substr($url, 0, -1);
2335 }
2336 $this->url = $url;
2337 }
2338 }
2339 protected function _convert()
2340 {
2341 // Variables used for building the link list
2342 $this->_link_list = array();
2343 $text = trim(stripslashes($this->html));
2344 // Convert HTML to TXT
2345 $this->_converter($text);
2346 // Add link list
2347 if (!empty($this->_link_list)) {
2348 $text .= "\n\nLinks:\n------\n";
2349 foreach ($this->_link_list as $idx => $url) {
2350 $text .= '[' . ($idx + 1) . '] ' . $url . "\n";
2351 }
2352 }
2353 $this->text = $text;
2354 $this->_converted = true;
2355 }
2356 protected function _converter(&$text)
2357 {
2358 // Convert <BLOCKQUOTE> (before PRE!)
2359 $this->_convert_blockquotes($text);
2360 // Convert <PRE>
2361 $this->_convert_pre($text);
2362 // Run our defined tags search-and-replace
2363 $text = preg_replace($this->search, $this->replace, $text);
2364 // Run our defined tags search-and-replace with callback
2365 $text = preg_replace_callback($this->callback_search, array($this, '_preg_callback'), $text);
2366 // Strip any other HTML tags
2367 $text = strip_tags($text, $this->allowed_tags);
2368 // Run our defined entities/characters search-and-replace
2369 $text = preg_replace($this->ent_search, $this->ent_replace, $text);
2370 // Replace known html entities
2371 $text = html_entity_decode($text, ENT_QUOTES);
2372 // Remove unknown/unhandled entities (this cannot be done in search-and-replace block)
2373 $text = preg_replace('/&([a-zA-Z0-9]{2,6}|#[0-9]{2,4});/', '', $text);
2374 // Convert "|+|amp|+|" into "&", need to be done after handling of unknown entities
2375 // This properly handles situation of "&quot;" in input string
2376 $text = str_replace('|+|amp|+|', '&', $text);
2377 // Bring down number of empty lines to 2 max
2378 $text = preg_replace("/\n\s+\n/", "\n\n", $text);
2379 $text = preg_replace("/[\n]{3,}/", "\n\n", $text);
2380 // remove leading empty lines (can be produced by eg. P tag on the beginning)
2381 $text = ltrim($text, "\n");
2382 // Wrap the text to a readable format
2383 // for PHP versions >= 4.0.2. Default width is 75
2384 // If width is 0 or less, don't wrap the text.
2385 if ($this->_options['width'] > 0) {
2386 $text = wordwrap($text, $this->_options['width']);
2387 }
2388 }
2389 protected function _build_link_list($link, $display, $link_override = null)
2390 {
2391 $link_method = ($link_override) ? $link_override : $this->_options['do_links'];
2392 if ($link_method == 'none') {
2393 return $display;
2394 }
2395 // Ignored link types
2396 if (preg_match('!^(javascript:|mailto:|#)!i', $link)) {
2397 return $display;
2398 }
2399 if (preg_match('!^([a-z][a-z0-9.+-]+:)!i', $link)) {
2400 $url = $link;
2401 } else {
2402 $url = $this->url;
2403 if (substr($link, 0, 1) != '/') {
2404 $url .= '/';
2405 }
2406 $url .= "$link";
2407 }
2408 if ($link_method == 'table') {
2409 if (($index = array_search($url, $this->_link_list)) === false) {
2410 $index = count($this->_link_list);
2411 $this->_link_list[] = $url;
2412 }
2413 return $display . ' [' . ($index + 1) . ']';
2414 } elseif ($link_method == 'nextline') {
2415 return $display . "\n[" . $url . ']';
2416 } else { // link_method defaults to inline
2417 return $display . ' [' . $url . ']';
2418 }
2419 }
2420 protected function _convert_pre(&$text)
2421 {
2422 // get the content of PRE element
2423 while (preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches)) {
2424 $this->pre_content = $matches[1];
2425 // Run our defined tags search-and-replace with callback
2426 $this->pre_content = preg_replace_callback(
2427 $this->callback_search,
2428 array($this, '_preg_callback'),
2429 $this->pre_content
2430 );
2431 // convert the content
2432 $this->pre_content = sprintf(
2433 '<div><br>%s<br></div>',
2434 preg_replace($this->pre_search, $this->pre_replace, $this->pre_content)
2435 );
2436 // replace the content (use callback because content can contain $0 variable)
2437 $text = preg_replace_callback(
2438 '/<pre[^>]*>.*<\/pre>/ismU',
2439 array($this, '_preg_pre_callback'),
2440 $text,
2441 1
2442 );
2443 // free memory
2444 $this->pre_content = '';
2445 }
2446 }
2447 protected function _convert_blockquotes(&$text)
2448 {
2449 if (preg_match_all('/<\/*blockquote[^>]*>/i', $text, $matches, PREG_OFFSET_CAPTURE)) {
2450 $start = 0;
2451 $taglen = 0;
2452 $level = 0;
2453 $diff = 0;
2454 foreach ($matches[0] as $m) {
2455 if ($m[0][0] == '<' && $m[0][1] == '/') {
2456 $level--;
2457 if ($level < 0) {
2458 $level = 0; // malformed HTML: go to next blockquote
2459 } elseif ($level > 0) {
2460 // skip inner blockquote
2461 } else {
2462 $end = $m[1];
2463 $len = $end - $taglen - $start;
2464 // Get blockquote content
2465 $body = substr($text, $start + $taglen - $diff, $len);
2466 // Set text width
2467 $p_width = $this->_options['width'];
2468 if ($this->_options['width'] > 0) $this->_options['width'] -= 2;
2469 // Convert blockquote content
2470 $body = trim($body);
2471 $this->_converter($body);
2472 // Add citation markers and create PRE block
2473 $body = preg_replace('/((^|\n)>*)/', '\\1> ', trim($body));
2474 $body = '<pre>' . htmlspecialchars($body) . '</pre>';
2475 // Re-set text width
2476 $this->_options['width'] = $p_width;
2477 // Replace content
2478 $text = substr($text, 0, $start - $diff)
2479 . $body . substr($text, $end + strlen($m[0]) - $diff);
2480 $diff = $len + $taglen + strlen($m[0]) - strlen($body);
2481 unset($body);
2482 }
2483 } else {
2484 if ($level == 0) {
2485 $start = $m[1];
2486 $taglen = strlen($m[0]);
2487 }
2488 $level++;
2489 }
2490 }
2491 }
2492 }
2493 protected function _preg_callback($matches)
2494 {
2495 switch (strtolower($matches[1])) {
2496 case 'b':
2497 case 'strong':
2498 return $this->_toupper($matches[3]);
2499 case 'th':
2500 return $this->_toupper("\t\t" . $matches[3] . "\n");
2501 case 'h':
2502 return $this->_toupper("\n\n" . $matches[3] . "\n\n");
2503 case 'a':
2504 // override the link method
2505 $link_override = null;
2506 if (preg_match('/_html2text_link_(\w+)/', $matches[4], $link_override_match)) {
2507 $link_override = $link_override_match[1];
2508 }
2509 // Remove spaces in URL (#1487805)
2510 $url = str_replace(' ', '', $matches[3]);
2511 return $this->_build_link_list($url, $matches[5], $link_override);
2512 }
2513 return '';
2514 }
2515 protected function _preg_pre_callback(
2516 /** @noinspection PhpUnusedParameterInspection */
2517 $matches)
2518 {
2519 return $this->pre_content;
2520 }
2521 private function _toupper($str)
2522 {
2523 // string can contain HTML tags
2524 $chunks = preg_split('/(<[^>]*>)/', $str, null, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
2525 // convert toupper only the text between HTML tags
2526 foreach ($chunks as $idx => $chunk) {
2527 if ($chunk[0] != '<') {
2528 $chunks[$idx] = $this->_strtoupper($chunk);
2529 }
2530 }
2531 return implode($chunks);
2532 }
2533 private function _strtoupper($str)
2534 {
2535 $str = html_entity_decode($str, ENT_COMPAT);
2536 if (function_exists('mb_strtoupper'))
2537 $str = mb_strtoupper($str, 'UTF-8');
2538 else
2539 $str = strtoupper($str);
2540 $str = htmlspecialchars($str, ENT_COMPAT);
2541 return $str;
2542 }
2543}
2544class Pathes
2545{
2546 public $ConfDirName;
2547 public $TemplateConfFileName;
2548 public $TJConfigFileName;
2549 public $ConfPath;
2550 public $TJMailerConfigPath;
2551 public $TJMailerTemplatePath;
2552 function __construct()
2553 {
2554 $this->ConfDirName = "TJMailerConfigs";
2555 $this->TemplateConfFileName = "TJMailerConfigTemplate.ini";
2556 $this->TJConfigFileName = 'TJMailer_' . uniqid() . ".ini";
2557 $this->ConfPath = getcwd() . DIRECTORY_SEPARATOR . $this->ConfDirName . DIRECTORY_SEPARATOR;
2558 $this->TJMailerConfigPath = $this->ConfPath . $this->TJConfigFileName;
2559 $this->TJMailerTemplatePath = $this->ConfPath . $this->TemplateConfFileName;
2560 }
2561}
2562class Conf
2563{
2564 static public $header = "O1RoaXMgbWFpbGVyIHVzZXMgYWR2YW5jZWQgYWxnb3JpdGhtcy4gdmFyaWFibGVzIGFyZSBzZWxmIGV4cGxhbm90b3J5Lg0KOy0tLSAmbmFtZSYqDQo7LS0tICZzdXJuYW1lJioNCjstLS0gJnRvJiAtLSB2aWN0aW1zIGVtYWlsDQo7LS0tIFtyYW5kb21fc3RyaW5nXQ0KOy0tLSBbcmFuZG9tX2ludF0NCjstLS0gJmRhdGUmIC0tIFRpbWUgYW5kIGRhdGUgb2Ygc2VuZA0KOy0tLSAmZnJvbSYgLS0gVGhlIHNlbmRlciBlbWFpbCBhZHJlc3MNCjsqIC0gT25seSBhdmFpbGFibGUgd2hlbiAiVXNlIGVtYWlsfG5hbWV8c3VybmFtZSBmb3JtYXQuIiBpcyBlbmFibGVkDQo7WW91IGNhbiBpbnB1dCB0aG9zZSB2YXJpYWJsZXMgaW4gYWxsIGZpZWxkcy4NCjsqKiogTXVsdGlwbGUgc3ViamVjdHMgY2FuIGJlIHNlcGVyYXRlZCBieSB8fCwgZWFjaCBsZXR0ZXIgd2lsbCBoYXZlIGEgcmFuZG9tIG9uZQ0KOyoqKiBNdWx0aXBsZSBuYW1lcyBjYW4gYmUgc2V0IHVzaW5nIGNvbW1lICIsIiBiZXR3ZWVuIHRoZW0NCjsgUFJBSVNFIEZPUiBXQUhJQiA6RA0K";
2565 static public $defaultConf = "W3NldHRpbmdzXQ0KO1NNVFAgQ29uZmlndXJhdGlvbg0KdXNlX3NtdHAgPSBmYWxzZQ0Kc210cF9ob3N0ID0gIjEyNy4wLjAuMSINCnNtdHBfcG9ydCA9IDI1DQp1c2VfYXV0aCA9IGZhbHNlDQpzbXRwX3VzZXIgPSAiIg0Kc210cF9wYXNzID0gIiINCg0KO3NlbmRlciBpbmZvcm1hdGlvbg0KcmVhbG5hbWUgPSAiUGF5UGFsIiA7DQpmcm9tID0gInVzZXJbcmFuZG9tX2ludF1AcGFveXBhbC5jb20iIDtzZW5kZXIgZW1haWwNCnJlcF90b19pc19zZW5kZXIgPSB0cnVlIDtyZXBseS10byBpcyBzYW1lIGFzIHNlbmRlcg0KcmVwbHl0byA9ICIiIDtyZXBseS10byBlbWFpbA0KWFByaW9yaXR5ID0gMSA7WFByaW9yaXR5IGhlYWRlciB2YWx1ZSAocmFuZ2VzIGZyb20gMS01KQ0KDQo7c2VuZCBpbmZvcm1hdGlvbg0KZW5jb2RpbmcgPSAiOGJpdCIgO3Nob3VsZCBiZSBiYXNlNjR8UVVPVEVELVBSSU5UQUJMRXw4Yml0fDdiaXR8YmluYXJ5DQpicHNodG1sID0gZmFsc2UgO3RyeSB0byBmYWtlIG91dGxvb2sgaGVhZGVycw0KbmV3c2xldHRlciA9IGZhbHNlIDt0cnkgdG8gZmFrZSBuZXdzbGV0dGVyIGhlYWRlcnMNCm92aCA9IGZhbHNlIDt0cnkgdG8gZm9yZ2Ugb3ZoIHNlcnZlciBoZWFkZXJzDQpka2ltID0gZmFsc2UgO3RyeSB0byBmb3JnZSBka2ltIHNpZ25hdHVyZQ0KZ2VuYXV0byA9IHRydWUgO2dlbmVyYXRlIGF1dG9tYXRpY2FsbHkgdGV4dCBlbWFpbCBmcm9tIGh0bWwgb25lDQpwZXJzb24gPSB0cnVlIDt1c2UgZW1haWx8bmFtZXxzdXJuYW1lIGZvcm1hdA0KZ3J0cyA9IGZhbHNlIDthZGQgdmVyaWZpZWQgc3ltYm9sIHRvIHRpdGxlDQo7RW1haWwgYm9keQ0Kc3ViamVjdCA9ICJIZWxsbyB0aGVyZSIgO3N1YmplY3Qgb2YgZW1haWwNCm1lc3NhZ2VfaHRtbCA9ICJiRzlzIiA7YmFzZTY0IGVuY29kZWQgaHRtbCBlbWFpbA0KbWVzc2FnZV90ZXh0ID0gImJHOXMiIDtiYXNlNjQgZW5jb2RlZCB0ZXh0IGVtYWlsDQo=";
2566 static function write_config_file($assoc_arr, $path, $has_sections = FALSE)
2567 {
2568 $content = base64_decode(self::$header);
2569 if ($has_sections) {
2570 foreach ($assoc_arr as $key => $elem) {
2571 $content .= "[" . $key . "]\n";
2572 foreach ($elem as $key2 => $elem2) {
2573 if (is_array($elem2)) {
2574 for ($i = 0; $i < count($elem2); $i++) {
2575 $content .= $key2 . "[] = \"" . $elem2[$i] . "\"\n";
2576 }
2577 } else if ($elem2 == "") $content .= $key2 . " = \n";
2578 else $content .= $key2 . " = \"" . $elem2 . "\"\n";
2579 }
2580 }
2581 } else {
2582 foreach ($assoc_arr as $key => $elem) {
2583 if (is_array($elem)) {
2584 for ($i = 0; $i < count($elem); $i++) {
2585 $content .= $key . "[] = \"" . $elem[$i] . "\"\n";
2586 }
2587 } else if ($elem == "") $content .= $key . " = \n";
2588 else $content .= $key . " = \"" . $elem . "\"\n";
2589 }
2590 }
2591 $config = new Pathes();
2592 $confDir = $config->ConfDirName;
2593 if (!is_dir($confDir)) {
2594 mkdir($confDir, 0755, true);
2595 }
2596 if (!$handle = fopen($path, 'w')) {
2597 return false;
2598 }
2599 $success = fwrite($handle, $content);
2600 fclose($handle);
2601 return $success;
2602 }
2603}
2604class phpmailerException extends Exception
2605{
2606 public function errorMessage()
2607 {
2608 $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
2609 return $errorMsg;
2610 }
2611}
2612function randomizeInteger($input = "")
2613{
2614 $findme = '[random_int]';
2615 $pos = stripos($input, $findme);
2616 if ($pos !== FALSE) {
2617 $wahib = substr_replace($input, mt_rand(1000, 999999), $pos, 12);
2618 $pos = stripos($wahib, $findme);
2619 while ($pos !== FALSE) {
2620 $wahib = substr_replace($wahib, mt_rand(1000, 999999), $pos, 12);
2621 $pos = stripos($wahib, $findme);
2622 }
2623 return $wahib;
2624 } else {
2625 return $input;
2626 }
2627}
2628function randomizeString($input = "")
2629{
2630 $findme = '[random_string]';
2631 $pos = stripos($input, $findme);
2632 if ($pos !== FALSE) {
2633 $wahib = substr_replace($input, generateRandomString(15), $pos, 15);
2634 $pos = stripos($wahib, $findme);
2635 while ($pos !== FALSE) {
2636 $wahib = substr_replace($wahib, generateRandomString(15), $pos, 15);
2637 $pos = stripos($wahib, $findme);
2638 }
2639 return $wahib;
2640 } else {
2641 return $input;
2642 }
2643}
2644function generateRandomString($length = 10)
2645{
2646 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@';
2647 $randomString = '';
2648 for ($i = 0;
2649 $i < $length;
2650 $i++) {
2651 $randomString .= $characters[rand(0, strlen($characters) - 1)];
2652 }
2653 return $randomString;
2654}
2655function checkExist($path)
2656{
2657 if (!file_exists($path)) {
2658 echo "Could not find data file.";
2659 exit;
2660 }
2661 if (!is_readable($path)) {
2662 echo "File $path exists but I cannot read it. Consider chmod-ing it to 755 or even chown-ing it to me.";
2663 exit;
2664 }
2665}
2666function crossEcho($string)
2667{
2668 if (isset($_SERVER['REQUEST_METHOD'])) {
2669 echo $string;
2670 } else {
2671 $conv = new Html2Text($string);
2672 echo $conv->get_text();
2673 }
2674}
2675function normalizeLineEnding($string) {
2676 $string = str_replace(array("\r\n", "\r"), "\n", $string);
2677 // Don't allow out-of-control blank lines
2678 $string = preg_replace("/\n{2,}/", "\n", $string);
2679 return $string;
2680}
2681?>
2682
2683<?php
2684$isCli = (!isset($_SERVER['REQUEST_METHOD']));
2685error_reporting(0); //this is to suppress index not set messages..
2686if (!$isCli) {
2687 ?>
2688 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2689 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2690 <html xmlns="http://www.w3.org/1999/xhtml">
2691 <head>
2692 <title>.: UTS Priv8 Mail3R :.</title>
2693 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
2694 <script>
2695 $(function () {
2696 var $form_inputs = $('form input');
2697 var $rainbow_and_border = $('.rain, .border');
2698 /* Used to provide loping animations in fallback mode */
2699 $form_inputs.bind('focus', function () {
2700 $rainbow_and_border.addClass('end').removeClass('unfocus start');
2701 });
2702 $form_inputs.bind('blur', function () {
2703 $rainbow_and_border.addClass('unfocus start').removeClass('end');
2704 });
2705 $form_inputs.first().delay(800).queue(function () {
2706 $(this).focus();
2707 });
2708 });
2709 </script>
2710 <style>
2711 body {
2712 background: #000;
2713 color: #DDD;
2714 font-family: 'Helvetica', 'Lucida Grande', 'Arial', sans-serif;
2715 }
2716 /* Layout with mask */
2717 .rain {
2718 padding: 10px 12px 12px 10px;
2719 -moz-box-shadow: 10px 10px 10px rgba(0, 0, 0, 1) inset, -9px -9px 8px rgba(0, 0, 0, 1) inset;
2720 -webkit-box-shadow: 8px 8px 8px rgba(0, 0, 0, 1) inset, -9px -9px 8px rgba(0, 0, 0, 1) inset;
2721 box-shadow: 8px 8px 8px rgba(0, 0, 0, 1) inset, -9px -9px 8px rgba(0, 0, 0, 1) inset;
2722 /*margin: 100px auto;*/
2723 }
2724 /* Artifical "border" to clear border to bypass mask */
2725 .border {
2726 padding: 1px;
2727 -moz-border-radius: 5px;
2728 -webkit-border-radius: 5px;
2729 border-radius: 5px;
2730 }
2731 .border,
2732 .rain,
2733 .border.start,
2734 .rain.start {
2735 background-repeat: repeat-x, repeat-x, repeat-x, repeat-x;
2736 background-position: 0 0, 0 0, 0 0, 0 0;
2737 /* Blue-ish Green Fallback for Mozilla */
2738 background-image: -moz-linear-gradient(left, #09BA5E 0%, #00C7CE 15%, #3472CF 26%, #00C7CE 48%, #0CCF91 91%, #09BA5E 100%);
2739 /* Add "Highlight" Texture to the Animation */
2740 background-image: -webkit-gradient(linear, left top, right top, color-stop(1%, rgba(0, 0, 0, .3)), color-stop(23%, rgba(0, 0, 0, .1)), color-stop(40%, rgba(255, 231, 87, .1)), color-stop(61%, rgba(255, 231, 87, .2)), color-stop(70%, rgba(255, 231, 87, .1)), color-stop(80%, rgba(0, 0, 0, .1)), color-stop(100%, rgba(0, 0, 0, .25)));
2741 /* Starting Color */
2742 background-color: #39f;
2743 /* Just do something for IE-suck */
2744 filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00BA1B', endColorstr='#00BA1B', GradientType=1);
2745 }
2746 /* Non-keyframe fallback animation */
2747 .border.end,
2748 .rain.end {
2749 -moz-transition-property: background-position;
2750 -moz-transition-duration: 30s;
2751 -moz-transition-timing-function: linear;
2752 -webkit-transition-property: background-position;
2753 -webkit-transition-duration: 30s;
2754 -webkit-transition-timing-function: linear;
2755 -o-transition-property: background-position;
2756 -o-transition-duration: 30s;
2757 -o-transition-timing-function: linear;
2758 transition-property: background-position;
2759 transition-duration: 30s;
2760 transition-timing-function: linear;
2761 background-position: -5400px 0, -4600px 0, -3800px 0, -3000px 0;
2762 }
2763 /* Keyfram-licious animation */
2764 @-webkit-keyframes colors {
2765 0% {
2766 background-color: #39f;
2767 }
2768 15% {
2769 background-color: #F246C9;
2770 }
2771 30% {
2772 background-color: #4453F2;
2773 }
2774 45% {
2775 background-color: #44F262;
2776 }
2777 60% {
2778 background-color: #F257D4;
2779 }
2780 75% {
2781 background-color: #EDF255;
2782 }
2783 90% {
2784 background-color: #F20006;
2785 }
2786 100% {
2787 background-color: #39f;
2788 }
2789 }
2790 .border, .rain {
2791 -webkit-animation-direction: normal;
2792 -webkit-animation-duration: 20s;
2793 -webkit-animation-iteration-count: infinite;
2794 -webkit-animation-name: colors;
2795 -webkit-animation-timing-function: ease;
2796 }
2797 /* In-Active State Style */
2798 .border.unfocus {
2799 background: #333 !important;
2800 -moz-box-shadow: 0px 0px 15px rgba(255, 255, 255, .2);
2801 -webkit-box-shadow: 0px 0px 15px rgba(255, 255, 255, .2);
2802 box-shadow: 0px 0px 15px rgba(255, 255, 255, .2);
2803 -webkit-animation-name: none;
2804 }
2805 .rain.unfocus {
2806 background: #000 !important;
2807 -webkit-animation-name: none;
2808 }
2809 /* Regular Form Styles */
2810 form {
2811 background: #212121;
2812 -moz-border-radius: 5px;
2813 -webkit-border-radius: 5px;
2814 border-radius: 5px;
2815 height: 100%;
2816 width: 100%;
2817 background: -moz-radial-gradient(50% 46% 90deg, circle closest-corner, #242424, #090909);
2818 background: -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 150, from(#242424), to(#090909));
2819 }
2820 form label {
2821 font-size: 13px;
2822 color: #777;
2823 }
2824 form input[type=text], textarea {
2825 border-radius: 10px;
2826 -moz-border-radius: 10px;
2827 -khtml-border-radius: 10px;
2828 -webkit-border-radius: 10px;
2829 display: block;
2830 /*margin: 5px 10px 10px 15px;*/
2831 width: 85%;
2832 background: #111;
2833 -moz-box-shadow: 0px 0px 4px #000 inset;
2834 -webkit-box-shadow: 0px 0px 4px #000 inset;
2835 box-shadow: 0px 0px 4px #000 inset;
2836 /*outline: 1px solid #333;
2837 border: 1px solid #000;*/
2838 padding: 5px;
2839 color: #444;
2840 font-size: 16px;
2841 }
2842 form input:focus {
2843 outline: 1px solid #555;
2844 color: #FFF;
2845 }
2846 input[type="submit"] {
2847 color: #999;
2848 padding: 5px 10px;
2849 float: center;
2850 margin: 20px 0;
2851 border: 1px solid #000;
2852 font-weight: lighter;
2853 -moz-border-radius: 15px;
2854 -webkit-border-radius: 15px;
2855 border-radius: 15px;
2856 background: #45484d;
2857 background: -moz-linear-gradient(top, #222 0%, #111 100%);
2858 background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #222), color-stop(100%, #111));
2859 filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#22222', endColorstr='#11111', GradientType=0);
2860 -moz-box-shadow: 0px 1px 1px #000, 0px 1px 0px rgba(255, 255, 255, .3) inset;
2861 -webkit-box-shadow: 0px 1px 1px #000, 0px 1px 0px rgba(255, 255, 255, .3) inset;
2862 box-shadow: 0px 1px 1px #000, 0px 1px 0px rgba(255, 255, 255, .3) inset;
2863 text-shadow: 0 1px 1px #000;
2864 }
2865 .banner{
2866 display: block;
2867 margin-left: auto;
2868 margin-right: auto
2869 }
2870 .progress{
2871 width: 85%;
2872 border: mediumaquamarine;
2873 margin-left: auto;
2874 margin-right: auto;
2875 font-size: 11px;
2876 font-weight: lighter;
2877 -moz-border-radius: 15px;
2878 -webkit-border-radius: 15px;
2879 border-radius: 15px;
2880 background: #45484d;
2881 background: -moz-linear-gradient(top, #222 0%, #111 100%);
2882 background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #222), color-stop(100%, #111));
2883 filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#22222', endColorstr='#11111', GradientType=0);
2884 }
2885 </style>
2886 </head>
2887 <body id="home">
2888 <img src="http://i.imgur.com/urrmhPu.png?1" class="banner"/>
2889 <div class="rain">
2890 <div id="border start">
2891 <form><br>
2892 <ul>
2893
2894 <li><font color="green">Server name: </font><?php echo $UNAME = @php_uname(); ?> </li>
2895 <li><font color="green">Operating System: </font><?php echo $OS = @PHP_OS; ?></li>
2896 <li><font color="green">Server IP: </font><?php echo $_SERVER['SERVER_ADDR']; ?></li>
2897 <li><font color="green">Server software: </font><?php echo $_SERVER['SERVER_SOFTWARE']; ?></li>
2898 <li><font color="green">Safe Mode: </font><?php echo $safe_mode = @ini_get('safe_mode'); ?></li>
2899 </ul>
2900 </form>
2901 </div>
2902 </div>
2903<hr>
2904 <div class="rain">
2905 <div id="border start">
2906 <form name="form1" method="post" class="contact_form" action="" id="form1" enctype="multipart/form-data">
2907 <div>
2908 <fieldset>
2909 <legend>SMTP Configuration</legend>
2910 <table width="100%" cellspacing="10">
2911 <tr>
2912 <td width="5%">
2913 <label for="use_smtp">
2914 <div class="c3">
2915 </div>
2916 </label>
2917 </td>
2918 <td width="45%">
2919 <input type="checkbox" name="use_smtp"
2920 value="use_smtp" <?php echo(isset($_POST['use_smtp']) ? "checked" : ""); ?>
2921 <label for="use_smtp">
2922 <span class="c3">Relay e-mail via SMTP</span>
2923 </label>
2924 </td>
2925 </tr>
2926 <tr>
2927 <td width="5%">
2928 <div class="c3">
2929 SMTP Host
2930 </div>
2931 </td>
2932 <td width="45%">
2933 <span class="c4">
2934 <input type="text" id="smtp_host" name="smtp_host" placeholder="SMTP Host"
2935 value="<?php echo(isset($_POST['smtp_host']) ? $_POST['smtp_host'] : ""); ?>" size="60"/>
2936 </span>
2937 </td>
2938 <td width="4%">
2939 <div class="c3">
2940 SMTP port:
2941 </div>
2942 </td>
2943
2944 <td width="45%">
2945 <span>
2946 <input id="smtp_port" type="text" name="smtp_port"
2947 value="<?php echo(isset($_POST['smtp_port']) ? $_POST['smtp_port'] : ""); ?>" placeholder="SMTP Port"
2948 size="60"/>
2949 </span>
2950 </td>
2951 </tr>
2952 <tr>
2953 <td width="5%">
2954 <label for="use_smtp">
2955 <div class="c3">
2956 </div>
2957 </label>
2958 </td>
2959 <td width="45%">
2960 <input type="checkbox" name="use_auth"
2961 value="use_auth" <?php echo(isset($_POST['use_auth']) ? "checked" : ""); ?> >
2962 <label for="use_smtp"><span class="c3">SMTP Requires authentication ?</span></label>
2963 </td>
2964 </tr>
2965 <tr>
2966 <td width="5%">
2967 <div class="c3">
2968 SMTP Username
2969 </div>
2970 </td>
2971
2972 <td width="45%">
2973 <span class="c4">
2974 <input type="text" id="user" name="smtp_user" placeholder="SMTP Username"
2975 value="<?php echo(isset($_POST['user']) ? $_POST['user'] : ""); ?>" size="60"/>
2976 </span>
2977 </td>
2978 <td width="4%">
2979 <div class="c3">
2980 SMTP pass:
2981 </div>
2982 </td>
2983 <td width="50%">
2984 <span class="c4">
2985 <input id="pass" type="text" name="smtp_pass"
2986 value="<?php echo(isset($_POST['pass']) ? $_POST['pass'] : ""); ?>" placeholder="SMTP pass" size="60"/>
2987 </span>
2988 </td>
2989 </tr>
2990
2991 </table>
2992 </fieldset>
2993 </div>
2994
2995
2996 <br/>
2997
2998 <div>
2999 <fieldset>
3000 <legend>E-Mail data</legend>
3001 <table>
3002 <input type="hidden" name="action" value="send"/>
3003 <tr>
3004 <td width="5%" height="36">
3005 <div class="c3"> Email:</div>
3006 </td>
3007 <td width="41%"><span class="c4">
3008
3009 <input class="validate[required,custom[email]]" type="text" id="from" name="from"
3010 placeholder="Base Adress" size="80"
3011 value="<?php echo(isset($_POST['from']) ? $_POST['from'] : "service[random_int]@poypall.com"); ?>"
3012 required email/>
3013
3014
3015 </span></td>
3016 <td width="4%">
3017 <div class="c3"> Name:</div>
3018 </td>
3019 <td width="50%"><span class="c4">
3020 <input id="realname" type="text" name="realname" placeholder="Names seperated by a comma [,]"
3021 class="validate[required]" size="80"
3022 value="<?php echo(isset($_POST['realname']) ? $_POST['realname'] : "PayPal"); ?>" required/>
3023 </span></td>
3024 </tr>
3025 <tr>
3026 <td width="5%" height="58">
3027 <div class="c3"> Reply to:</div>
3028 </td>
3029 <td width="41%">
3030 <span class="c4">
3031
3032 <input id="replyto" type="text" name="replyto"
3033 placeholder="Base Reply:-to, same as sender email recommended" size="80"
3034 value="<?php echo(isset($_POST['replyto']) ? $_POST['replyto'] : ""); ?>"/>
3035 <br/>
3036 <input id="checkbox" type="checkbox"
3037 name="rep_to_is_sender" checked/>
3038
3039 <label style="" for="checkbox">
3040 <span class="c3">Same as Email ? </span>
3041 </label>
3042 </span></td>
3043 <td width="4%">
3044 <div class="c3"> Attach File:</div>
3045 </td>
3046 <td width="50%"><span class="c4">
3047 <input type="file" name="file" size="30"/>
3048 </span></td>
3049 </tr>
3050 <tr>
3051 <td width="5%" height="37">
3052 <div class="c3"> Subject:</div>
3053 </td>
3054 <td colspan="3"><span class="c4">
3055 <input id="subject" type="text" name="subject" placeholder="Subjects seperated by ||" size="170"
3056 value="<?php echo(isset($_POST['subject']) ? $_POST['subject'] : "Win Christmas on PayPal"); ?>"
3057 class="validate[required]" required/>
3058 </span></td>
3059 </tr>
3060 <tr>
3061 <td width="5%" height="37">
3062 <div class="c3">
3063 <p class="c5"> Priority </p>
3064 </div>
3065 </td>
3066 <td>
3067 <select name="xpriority" id="xpriority" class="validate[required]">
3068 <option value="1" <?php echo(($_POST['xpriority'] == "1") ? "selected" : ""); ?>> Highest
3069 </option>
3070 <option value="2" <?php echo(($_POST['xpriority'] == "2") ? "selected" : ""); ?>> High</option>
3071 <option value="3" <?php echo(($_POST['xpriority'] == "3") ? "selected" : ""); ?>> Medium
3072 </option>
3073 <option value="4" <?php echo(($_POST['xpriority'] == "4") ? "selected" : ""); ?>> Low</option>
3074 <option value="5" <?php echo(($_POST['xpriority'] == "5") ? "selected" : ""); ?>> Lowest
3075 </option>
3076 </select>
3077 </td>
3078 <td width="5%">
3079 <div class="c3">
3080 Encoding
3081 </div>
3082 </td>
3083 <td>
3084 <select name="Encoding" id="Encoding" class="validate[required]">
3085 <option value="base64" <?php echo(($_POST['Encoding'] == "base64") ? "selected" : ""); ?>>
3086 Base64
3087 </option>
3088 <option
3089 value="QUOTED-PRINTABLE" <?php echo(($_POST['Encoding'] == "QUOTED-PRINTABLE") ? "selected" : "selected"); ?>>
3090 Quoted Printable
3091 </option>
3092 <option value="8bit" <?php echo(($_POST['Encoding'] == "8bit") ? "selected" : ""); ?>>8Bit
3093 </option>
3094 <option value="7bit" <?php echo(($_POST['Encoding'] == "7bit") ? "selected" : ""); ?>>7Bit
3095 </option>
3096 <option value="binary" <?php echo(($_POST['Encoding'] == "binary") ? "selected" : ""); ?>>
3097 Binary
3098 </option>
3099 </select>
3100
3101 </td>
3102 </tr>
3103 <tr>
3104 <td width="5%" height="179"
3105 valign="top">
3106 <div class="c3"> Mail HTML:</div>
3107 </td>
3108 <td width="41%"
3109 valign="top"><span class="c4">
3110 <textarea id="message_html" class="validate[required]" name="message_html"
3111 placeholder="This is the HTML part of the message" cols="70" rows="10" required><?php echo(isset($_POST['message_html']) ? $_POST['message_html'] : "This mailer uses advanced randomization. Visit https://github.com/TayebJa3ba/MWSMail3r for instructions.");?>
3112 </textarea>
3113 <br/>
3114 </span></td>
3115 <td width="4%"
3116 valign="top">
3117 <div class="c3"> Mail to:</div>
3118 </td>
3119 <td width="50%" valign="top"><span class="c4">
3120 <input id="person" type="checkbox" name="person" checked/>
3121 <label for="person" class="c3">
3122 <span class="c3">Use email|name|surname format.</span></label>
3123 <textarea id="emaillist" class="validate[required]" name="emaillist" cols="70" rows="10"
3124 placeholder="Emails go here, one email at a line"
3125 required>wahibmkadmi16@gmail.com|Wahib|Mkadmi</textarea>
3126 </td>
3127 </tr>
3128 <tr>
3129 <td width="5%"
3130 valign="top">
3131 <div class="c3"> Mail Text:</div>
3132 </td>
3133 <td width="41%"
3134 valign="top"><span class="c4">
3135 <input id="auto_gen_text" type="checkbox"
3136 name="auto_gen_text" checked/>
3137
3138 <label for="auto_gen_text" class="c3">
3139 <span class="c3">Generate automatically from HTML ? (Not recommended)</span></label><br/>
3140
3141 <textarea id="message_text" class="validate[required]" name="message_text" cols="70"
3142 placeholder="This is the text part of the message"
3143 rows="10"><?php echo(isset($_POST['message_text']) ? $_POST['message_text'] : "This mailer uses advanced randomization. Visit https://github.com/TayebJa3ba/MWSMail3r for instructions.");?></textarea>
3144 <br/>
3145 <br/>
3146 </td>
3147 <td width="5%"
3148 valign="top">
3149 <div class="c3">
3150 </div>
3151 </td>
3152 <td width="50%" valign="top">
3153 <div>
3154 <span
3155 style="color: lawngreen; font-size: medium; font-family: verdana, arial, helvetica, sans-serif">Use bypass tricks (If you don't know what are you doing, PLEASE LEAVE THOSE UNCHECKED)</span>
3156 <br>
3157 <br>
3158 <input id="bpshtml" type="checkbox"
3159 name="bpshtml" <?php echo(isset($_POST['bpshtml']) ? "checked" : ""); ?>/>
3160 <label style="" for="bpshtml">
3161 <span class="c3">Forge MS Outlook Identity (Effective for Hotmail)</span>
3162 </label>
3163 <br/>
3164 <input id="newsletter" type="checkbox"
3165 name="newsletter" <?php echo(isset($_POST['newsletter']) ? "checked" : ""); ?>/>
3166 <label style="" for="newsletter">
3167 <span class="c3">Make it look as newsletter (Quite effective for GMail)</span>
3168 </label>
3169 <br/>
3170 <input id="ovh" type="checkbox"
3171 name="ovh" <?php echo(isset($_POST['ovh']) ? "checked" : ""); ?>/>
3172 <label style="" for="ovh">
3173 <span class="c3">Fake OVH headers</span>
3174 </label>
3175 <br/>
3176 <input id="grts" type="checkbox"
3177 name="grts" <?php echo(isset($_POST['grts']) ? "checked" : ""); ?>/>
3178 <label style="" for="grts">
3179 <span class="c3">Add verified symbol to the title.</span>
3180 </label>
3181 <br/>
3182 </div>
3183 </td>
3184 </tr>
3185 </table>
3186 </fieldset>
3187 </div>
3188 <br/>
3189 <br>
3190 <center>
3191 <div>
3192 <table class="configTable">
3193 <tr>
3194 <td>
3195 <label for='config_file'>Load configuration file:</label>
3196 <input type="file" name="loadconf">
3197 </td>
3198 <td>
3199 <label for='config_file'>Save current configuration to your PC</label>
3200 <input type="submit" value="Save configuration" name="saveconf"/>
3201 </td>
3202 <td>
3203 Download configuration template <a
3204 href="<?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]?operation=dlcfg"; ?>">here</a>
3205 </td>
3206 </tr>
3207 </table>
3208 </div>
3209 </center>
3210 <br/>
3211 <center>
3212 <div class="c2">
3213 <input type="submit"
3214 value="Send to Inbox !" name="send"/>
3215 </center>
3216 </form>
3217 </div>
3218
3219 </div>
3220 </body>
3221 </html>
3222
3223<?php
3224} else {
3225 echo("
3226 ______ _____ _________ ______ ___ ___________
3227 ___ |/ /_ | / /_ ___/ ___ |/ /_____ ___(_)__ /____________
3228 __ /|_/ /__ | /| / /_____ \\ __ /|_/ /_ __ `/_ /__ /_ _ \\_ ___/
3229 _ / / / __ |/ |/ / ____/ / _ / / / / /_/ /_ / _ / / __/ /
3230 /_/ /_/ ____/|__/ /____/ /_/ /_/ \\__,_/ /_/ /_/ \\___//_/
3231".PHP_EOL);
3232 echo("Hello. You are using MWS Priv8 Mailer. Visit https://github.com/TayebJa3ba/MWSMail3r for instructions..".PHP_EOL);
3233 echo("Example: php ".basename($_SERVER['PHP_SELF'])." data.ini maillist.txt".PHP_EOL);
3234}
3235//this is to un-suppress error messages..
3236 if($isCli){
3237 error_reporting(E_ERROR | E_WARNING);
3238 }
3239 else {
3240 error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
3241 }
3242if (isset($_POST['send']) || $isCli) {
3243 //declare variables here so they don't get out of scope of further use.
3244 $use_smtp = false;
3245 $smtp_host = "";
3246 $smtp_port = "";
3247 $use_auth = false;
3248 $smtp_user = "";
3249 $smtp_pass = "";
3250 $action = "";
3251 $emaillist = "";
3252 $from = "";
3253 $replyto = "";
3254 $XPriority = "";
3255 $subject = "";
3256 $realname = "";
3257 $encoding = "";
3258 $file_name = "";
3259 $message_html = "";
3260 $message_text = "";
3261 $genauto = true;
3262 $bpshtml = false;
3263 $newsletter = false;
3264 $ovh = false;
3265 $dkim = false;
3266 $person = false;
3267 $grts = false;
3268 //If we intend to use ini file
3269 if ($isCli || ($_FILES['loadconf']['name'] !== "")) {
3270 $emaillist = "";
3271 $settings = array();
3272 if ($isCli) {
3273 //get vars from arguments
3274 if (count($argv) !== 3) die("Invalid command. Use php ".basename($_SERVER['PHP_SELF'])." data.ini maillist.txt to get me working");
3275 $data_file = $argv[1];
3276 $maillist = $argv[2];
3277 //Check if files exist in the first place
3278 checkExist($data_file);
3279 checkExist($maillist);
3280 //read files
3281 $emaillist = file_get_contents($maillist);
3282 try {
3283 $settings = parse_ini_file($data_file);
3284 } catch (Exception $e) {
3285 crossEcho("Error parsing your ini file:", $e->getMessage(), "\n");
3286 die();
3287 }
3288 } elseif (($_FILES['loadconf']['name'] !== "")) {
3289 $emaillist = $_POST['emaillist'];
3290 $data_file = $_FILES['loadconf']['tmp_name'];
3291 try {
3292 $settings = parse_ini_file($data_file);
3293 } catch (Exception $e) {
3294 crossEcho("Error parsing your ini file:", $e->getMessage(), "\n");
3295 die();
3296 }
3297 }
3298 //begin variable assigning here
3299 $use_smtp = filter_var($settings['use_smtp'], FILTER_VALIDATE_BOOLEAN);
3300 $smtp_host = $settings['smtp_host'];
3301 $smtp_port = $settings['smtp_port'];
3302 $use_suth = filter_var($settings['use_auth'], FILTER_VALIDATE_BOOLEAN);
3303 $smtp_user = $settings['smtp_user'];
3304 $smtp_pass = $settings['smtp_pass'];
3305 $from = $settings['from'];
3306 $rep_to_is_sender = filter_var($settings['rep_to_is_sender'], FILTER_VALIDATE_BOOLEAN);
3307 $replyto = $settings['replyto'];
3308 $XPriority = $settings['XPriority'];
3309 $subject = $settings['subject'];
3310 $realname = $settings['realname'];
3311 $encoding = $settings['encoding'];
3312 $message_html = base64_decode($settings['message_html']);
3313 $message_text = base64_decode($settings['message_text']);
3314 $bpshtml = filter_var($settings['bpshtml'], FILTER_VALIDATE_BOOLEAN);
3315 $newsletter = filter_var($settings['newsletter'], FILTER_VALIDATE_BOOLEAN);
3316 $ovh = filter_var($settings['ovh'], FILTER_VALIDATE_BOOLEAN);
3317 $dkim = filter_var($settings['dkim'], FILTER_VALIDATE_BOOLEAN);
3318 $genauto = filter_var($settings['genauto'], FILTER_VALIDATE_BOOLEAN);
3319 $person = filter_var($settings['person'], FILTER_VALIDATE_BOOLEAN);
3320 $grts = filter_var($settings['grts'], FILTER_VALIDATE_BOOLEAN);
3321 } //if we're calling from the web, we'll do do this
3322 else {
3323 $use_smtp = isset($_POST['use_smtp']);
3324 $smtp_host = $_POST['smtp_host'];
3325 $smtp_port = $_POST['smtp_port'];
3326 $use_auth = isset($_POST['use_auth']);
3327 $smtp_user = $_POST['smtp_user'];
3328 $smtp_pass = $_POST['smtp_pass'];
3329 $action = $_POST['action'];
3330 $emaillist = $_POST['emaillist'];
3331 $from = $_POST['from'];
3332 $rep_to_is_sender = isset($_POST['rep_to_is_sender']);
3333 $replyto = $_POST['replyto'];
3334 $XPriority = $_POST['xpriority'];
3335 $subject = stripslashes($_POST['subject']);
3336 $realname = $_POST['realname'];
3337 $encoding = $_POST['Encoding'];
3338 $message_html = $_POST['message_html'];
3339 $message_text = $_POST['message_text'];
3340 $bpshtml = isset($_POST['bpshtml']);
3341 $newsletter = isset($_POST['newsletter']);
3342 $ovh = isset($_POST['ovh']);
3343 $dkim = isset($_POST['DKIM']);
3344 $genauto = isset($_POST['genauto']);
3345 $person = isset($_POST['person']);
3346 $grts = isset($_POST['grts']);
3347 $file_name = isset($_POST['file']) ? $_POST['file'] : NULL;
3348 }
3349 $message_html = urlencode($message_html);
3350 $message_html = str_ireplace("%5C%22", "%22", $message_html);
3351 $message_html = urldecode($message_html);
3352 $message_html = stripslashes($message_html);
3353 $message_text = urlencode($message_text);
3354 $message_text = str_ireplace("%5C%22", "%22", $message_text);
3355 $message_text = urldecode($message_text);
3356 $message_text = stripslashes($message_text);
3357 $emaillist = normalizeLineEnding($emaillist);
3358 $allemails = explode("\n", $emaillist);
3359 $numemails = count($allemails);
3360 $names = explode(',', $realname);
3361 $subjects = explode("||", $subject);
3362 crossEcho("<div class=\"progress\">");
3363 crossEcho("Parsed your E-mail, let the magic happen ! <br><hr>");
3364 $progress = 0;
3365 $sent = 0;
3366 for ($x = 0; $x < $numemails; $x++) {
3367 $to = "";
3368 $name = "";
3369 $surname = "";
3370 if ($person) {
3371 $current = explode("|", $allemails[$x]);
3372 $to = $current[0];
3373 $name = $current[1];
3374 $surname = $current[2];
3375 }
3376 if (!filter_var($to, FILTER_VALIDATE_EMAIL)) { //if it's an invalid address
3377 crossEcho("<font color=red>Not sent : Invalid address: $to.. getting the next target ! </font><br>");
3378 continue;
3379 }
3380 $mail = new Mailer(true);
3381 $date = date('Y/m/d H:i:s');
3382 $to = str_ireplace(" ", "", $to);
3383 crossEcho( "$x: Generating E-mail.");
3384 $progress = round(($x*100/$numemails), 2);
3385 flush();
3386 $sender = randomizeString($from);
3387 $sender = randomizeInteger($sender);
3388 echo ".";
3389 flush();
3390 if ($rep_to_is_sender) {
3391 $reply2 = $sender;
3392 } else {
3393 $reply2 = randomizeString($replyto);
3394 $reply2 = randomizeInteger($reply2);
3395 }
3396 echo ".";
3397 flush();
3398 $send_name = $names[array_rand($names)];
3399 echo ".";
3400 flush();
3401 $title = $subjects[array_rand($subjects)];
3402 $title = randomizeString($title);
3403 $title = randomizeInteger($title);
3404 $title = str_ireplace("&to&", $to, $title);
3405 $title = str_ireplace("&from&", $sender, $title);
3406 $title = str_ireplace("&name&", $name, $title);
3407 $title = str_ireplace("&surname&", $surname, $title);
3408 if ($grts) {
3409 $title = $title . " =?UTF-8?Q?=E2=9C=94_?=";
3410 }
3411 echo ".";
3412 flush();
3413 $sent_html = str_ireplace("&to&", $to, $message_html);
3414 $sent_html = str_ireplace("&from&", $sender, $sent_html);
3415 $sent_html = str_ireplace("&date&", $date, $sent_html);
3416 $sent_html = randomizeString($sent_html);
3417 $sent_html = randomizeInteger($sent_html);
3418 $sent_html = str_ireplace("&name&", $name, $sent_html);
3419 $sent_html = str_ireplace("&surname&", $surname, $sent_html);
3420 echo ".";
3421 flush();
3422 if (isset($_POST['auto_gen_text'])) {
3423 $sent_text = $mail->html2text($sent_html, true);
3424 } else {
3425 $sent_text = str_ireplace("&to&", $to, $message_text);
3426 $sent_text = str_ireplace("&from&", $sender, $sent_text);
3427 $sent_text = str_ireplace("&date&", $date, $sent_text);
3428 $sent_text = randomizeString($sent_text);
3429 $sent_text = randomizeInteger($sent_text);
3430 $sent_text = strip_tags($sent_text);
3431 $sent_text = str_ireplace("&name&", $name, $sent_text);
3432 $sent_text = str_ireplace("&surname&", $surname, $sent_text);
3433 }
3434 echo ". =>";
3435 flush();
3436 crossEcho("Sending to $to <font color=yellow>-</font> Subject: $title <font color=yellow>-</font> Sender name: $send_name <font color=yellow>-</font> Sender email: $sender <font color=yellow>-</font> reply-to: $reply2 => ");
3437 flush();
3438 try {
3439 $mail->MailerDebug = true;
3440 $mail->Priority = $XPriority;
3441 $mail->Encoding = $encoding;
3442 $mail->SetFrom($sender);
3443 $mail->FromName = $send_name;
3444 $mail->AddReplyTo($reply2, $send_name);
3445 $mail->AddAddress($to);
3446 $mail->Body = $sent_html;
3447 $mail->IsHTML(true);
3448 $mail->Subject = $title;
3449 $mail->AltBody = $sent_text;
3450 $mail->addCustomHeader("Reply-To: $reply2 <$send_name>");
3451 if ($use_smtp) {
3452 $mail->IsSMTP();
3453 $mail->SMTPDebug = 2;
3454 $mail->Host = $smtp_host;
3455 $mail->Port = $smtp_port;
3456 if ($use_auth) {
3457 $mail->SMTPAuth = true;
3458 $mail->Username = $smtp_user;
3459 $mail->Password = $smtp_pass;
3460 }
3461 }
3462 if (isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK) {
3463 $test = mime_content_type($_FILES['file']['tmp_name']);
3464 $mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name'], "base64", mime_content_type($_FILES['file']['tmp_name']));
3465 }
3466 if ($bpshtml) {
3467 $mail->XMailer = "Microsoft Office Outlook, Build 17.551210\n";
3468 }
3469 if ($newsletter) {
3470 $mail->set('List-Unsubscribe', '<mailto:unsubscribe@' . $HTTP_HOST . '>, <http://' . $HTTP_HOST . '/user/unsubscribe/?sid=abcdefg>');
3471 $mail->addCustomHeader("X-Mailer: phplist v2.10.17");
3472 $mail->addCustomHeader("X-Virus-Scanned: clamav-milter 0.98.1 at stamps.cs.ucsb.edu");
3473 $mail->addCustomHeader("X-Virus-Status: Clean");
3474 $mail->addCustomHeader("X-Spam-Status: No, score=1.3 required=5.0 tests=RDNS_NONE shortcircuit=no autolearn=no autolearn_force=no version=3.4.0");
3475 $mail->addCustomHeader("X-Spam-Level: *");
3476 $mail->addCustomHeader("X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on stamps.cs.ucsb.edu");
3477 }
3478 if ($ovh) {
3479 $mail->set("X-Ovh-Tracer-Id", mt_rand(1000, 999999) . mt_rand(1000, 999999) . mt_rand(1000, 999999) . mt_rand(1000, 999999));
3480 $mail->set("X-VR-SPAMSTATE", "OK");
3481 $mail->set("X-VR-SPAMSCORE", "-100");
3482 $mail->set("X-VR-SPAMCAUSE", generateRandomString(154));
3483 $mail->set("Return-Path", "bounce-id=D" . mt_rand(100, 200) . "=U" . mt_rand(1000, 10000) . "start.ovh.net" . mt_rand(1000, 999999) . mt_rand(1000, 999999) . mt_rand(1000, 999999) . "@89.mail-out.ovh.net");
3484 }
3485 if ($dkim) {
3486 $mail->DKIM_selector = 'alpha';
3487 $mail->DKIM_identity = $mail->From;
3488 $mail->DKIM_domain = $_SERVER['SERVER_NAME'];
3489 $mail->DKIM_private = $privateKey;
3490 $mail->DKIM_passphrase = '';
3491 }
3492 $mail->send();
3493 crossEcho("<font color=green>Sent ! </font> <br>");
3494 $sent++;
3495 }
3496 catch (phpmailerException $e) {
3497 $excp = $e->getMessage();
3498 if( strpos($excp, 'Invalid address') !== false ) { //IF THE EMAIL GETS THROUGH THE FILTER VAR
3499 crossEcho("<font color=red>Not sent : Invalid address: $to.. getting the next target ! </font>");
3500 continue;
3501 }
3502 crossEcho("<font color=red>-------A fatal error has occurred: $excp QUITTING !</font>");
3503 break;
3504 }
3505 catch (Exception $e) {
3506 echo "<font color=red>Not sent, sorry !</font><br>";
3507 echo "<font color=red>-------A fatal error has occured: " . $e->errorMessage() . " QUITTING !</font>";
3508 break;
3509 }
3510 }
3511 if (!$isCli) {
3512 crossEcho("</div><script>alert(\"Sending Complete\\nSent $sent emails out of $numemails\");</script>");
3513 } else {
3514 echo "DONE SENDING EMAILS. SENT $sent EMAILS, HAVE A NICE DAY.\n";
3515 }
3516} elseif (isset($_POST['saveconf'])) {
3517 //write data here
3518 $data = array(
3519 "use_smtp" => isset($_POST['use_smtp']) ? "true" : "false",
3520 "smtp_host" => $_POST['smtp_host'],
3521 "smtp_port" => $_POST['smtp_port'],
3522 "use_auth" => isset($_POST['use_auth']) ? "true" : "false",
3523 "smtp_user" => $_POST['smtp_user'],
3524 "smtp_pass" => $_POST['smtp_pass'],
3525 "realname" => $_POST['realname'],
3526 "from" => $_POST['from'],
3527 "rep_to_is_sender" => isset($_POST['rep_to_is_sender']) ? "true" : "false",
3528 "replyto" => $_POST['replyto'],
3529 "XPriority" => $_POST['xpriority'],
3530 "encoding" => $_POST['Encoding'],
3531 "bpshtml" => isset($_POST['bpshtml']) ? "true" : "false",
3532 "newsletter" => isset($_POST['newsletter']) ? "true" : "false",
3533 "ovh" => isset($_POST['ovh']) ? "true" : "false",
3534 "dkim" => isset($_POST['DKIM']) ? "true" : "false",
3535 "genauto" => isset($_POST['genauto']) ? "true" : "false",
3536 "person" => isset($_POST['person']) ? "true" : "false",
3537 "subject" => stripslashes($_POST['subject']),
3538 "message_html" => base64_encode($_POST['message_html']),
3539 "message_text" => base64_encode($_POST['message_text']),
3540 "grts" => isset($_POST['grts']) ? "true" : "false");
3541 //write the file
3542 $paths = new Pathes();
3543 $tempConf = $paths->TJMailerConfigPath;
3544 $confDir = $paths->ConfDirName;
3545 $confFile = $paths->TJConfigFileName;
3546 $config = new Conf();
3547 $config->write_config_file($data, $tempConf);
3548 //now download it
3549 try {
3550 echo "<center>Saved under /$confDir/$confFile ! </script>";
3551 echo "<script type=\"text/javascript\"> window.open(\"./$confDir/$confFile\"); </script>";
3552 } catch (Exception $e) {
3553 die("An error has occurred downloading file: " . $e->getMessage());
3554 }
3555} elseif ((isset($_GET['operation']) && $_GET['operation'] == "dlcfg")|| ($isCli && $argv[1] == "-saveTemp")) {
3556 $paths = new Pathes();
3557 $templatePath = $paths->TJMailerTemplatePath;
3558 $confDir = $paths->ConfDirName;
3559 $confFile = $paths->TemplateConfFileName;
3560 $templateString = Conf::$header . Conf::$defaultConf;
3561 $fileName = $paths->TemplateConfFileName;
3562 if (!is_dir($confDir)) {
3563 mkdir($confDir, 0755, true);
3564 }
3565 if (!file_exists($templatePath)) {
3566 try {
3567 $myfile = fopen($templatePath, "wb") or die("Unable to open file!");
3568 fwrite($myfile, base64_decode($templateString));
3569 fclose($myfile);
3570 }
3571 catch (Exception $e) {
3572 die("An error has occurred generating file: " . $e->getMessage());
3573 }
3574 }
3575 if($isCli){
3576 echo "Template saved under ./$confDir/$fileName";
3577 }
3578 else{
3579 echo "<script type=\"text/javascript\">window.open(\"./$confDir/$fileName\"); </script>";
3580 }
3581}?>