Spacedust

Untitled

Dec 16th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 58.82 KB | None | 0 0
  1. class PHPMailer {
  2.  
  3.  
  4.  
  5. public $Priority = 3;
  6.  
  7.  
  8. public $CharSet = 'iso-8859-1';
  9.  
  10.  
  11. public $ContentType = 'text/plain';
  12.  
  13.  
  14. public $Encoding = '8bit';
  15.  
  16.  
  17. public $ErrorInfo = '';
  18.  
  19.  
  20. public $From = 'root@localhost';
  21.  
  22.  
  23. public $FromName = 'Root User';
  24.  
  25.  
  26. public $Sender = '';
  27.  
  28.  
  29. public $ReturnPath = '';
  30.  
  31.  
  32. public $Subject = '';
  33.  
  34.  
  35. public $Body = '';
  36.  
  37.  
  38. public $AltBody = '';
  39.  
  40.  
  41. protected $MIMEBody = '';
  42.  
  43.  
  44. protected $MIMEHeader = '';
  45.  
  46.  
  47. protected $mailHeader = '';
  48.  
  49.  
  50. public $WordWrap = 0;
  51.  
  52.  
  53. public $Mailer = 'mail';
  54.  
  55.  
  56. public $Sendmail = '/usr/sbin/sendmail';
  57.  
  58.  
  59. public $UseSendmailOptions = true;
  60.  
  61.  
  62. public $PluginDir = '';
  63.  
  64.  
  65. public $ConfirmReadingTo = '';
  66.  
  67.  
  68. public $Hostname = '';
  69.  
  70.  
  71. public $MessageID = '';
  72.  
  73.  
  74. public $MessageDate = '';
  75.  
  76.  
  77.  
  78. public $Host = 'localhost';
  79.  
  80.  
  81. public $Port = 25;
  82.  
  83.  
  84. public $Helo = '';
  85.  
  86.  
  87. public $SMTPSecure = '';
  88.  
  89.  
  90. public $SMTPAuth = false;
  91.  
  92.  
  93. public $Username = '';
  94.  
  95.  
  96. public $Password = '';
  97.  
  98.  
  99. public $AuthType = '';
  100.  
  101.  
  102. public $Realm = '';
  103.  
  104.  
  105. public $Workstation = '';
  106.  
  107.  
  108. public $Timeout = 10;
  109.  
  110.  
  111. public $SMTPDebug = false;
  112.  
  113.  
  114. public $Debugoutput = "echo";
  115.  
  116.  
  117. public $SMTPKeepAlive = false;
  118.  
  119.  
  120. public $SingleTo = false;
  121.  
  122.  
  123. public $SingleToArray = array();
  124.  
  125.  
  126. public $LE = "\n";
  127.  
  128.  
  129. public $DKIM_selector = '';
  130.  
  131.  
  132. public $DKIM_identity = '';
  133.  
  134.  
  135. public $DKIM_passphrase = '';
  136.  
  137.  
  138. public $DKIM_domain = '';
  139.  
  140.  
  141. public $DKIM_private = '';
  142.  
  143.  
  144. public $action_function = '';
  145.  
  146. public $Version = '5.2.2';
  147.  
  148.  
  149. public $XMailer = '';
  150.  
  151.  
  152.  
  153. protected $smtp = null;
  154.  
  155. protected $to = array();
  156.  
  157. protected $cc = array();
  158.  
  159. protected $bcc = array();
  160.  
  161. protected $ReplyTo = array();
  162.  
  163. protected $all_recipients = array();
  164.  
  165. protected $attachment = array();
  166.  
  167. protected $CustomHeader = array();
  168.  
  169. protected $message_type = '';
  170.  
  171. protected $boundary = array();
  172.  
  173. protected $language = array();
  174.  
  175. protected $error_count = 0;
  176.  
  177. protected $sign_cert_file = '';
  178.  
  179. protected $sign_key_file = '';
  180.  
  181. protected $sign_key_pass = '';
  182.  
  183. protected $exceptions = false;
  184.  
  185.  
  186. const STOP_MESSAGE = 0; const STOP_CONTINUE = 1; const STOP_CRITICAL = 2; const CRLF = "\r\n";
  187.  
  188.  
  189. private function mail_passthru($to, $subject, $body, $header, $params) {
  190. if ( ini_get('safe_mode') || !($this->UseSendmailOptions) ) {
  191. $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header);
  192. } else {
  193. $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header, $params);
  194. }
  195. return $rt;
  196. }
  197.  
  198.  
  199. private function edebug($str) {
  200. if ($this->Debugoutput == "error_log") {
  201. error_log($str);
  202. } else {
  203. echo $str;
  204. }
  205. }
  206.  
  207.  
  208. public function __construct($exceptions = false) {
  209. $this->exceptions = ($exceptions == true);
  210. }
  211.  
  212.  
  213. public function IsHTML($ishtml = true) {
  214. if ($ishtml) {
  215. $this->ContentType = 'text/html';
  216. } else {
  217. $this->ContentType = 'text/plain';
  218. }
  219. }
  220.  
  221.  
  222. public function IsSMTP() {
  223. $this->Mailer = 'smtp';
  224. }
  225.  
  226.  
  227. public function IsMail() {
  228. $this->Mailer = 'mail';
  229. }
  230.  
  231.  
  232. public function IsSendmail() {
  233. if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
  234. $this->Sendmail = '/var/qmail/bin/sendmail';
  235. }
  236. $this->Mailer = 'sendmail';
  237. }
  238.  
  239.  
  240. public function IsQmail() {
  241. if (stristr(ini_get('sendmail_path'), 'qmail')) {
  242. $this->Sendmail = '/var/qmail/bin/sendmail';
  243. }
  244. $this->Mailer = 'sendmail';
  245. }
  246.  
  247.  
  248.  
  249. public function AddAddress($address, $name = '') {
  250. return $this->AddAnAddress('to', $address, $name);
  251. }
  252.  
  253.  
  254. public function AddCC($address, $name = '') {
  255. return $this->AddAnAddress('cc', $address, $name);
  256. }
  257.  
  258.  
  259. public function AddBCC($address, $name = '') {
  260. return $this->AddAnAddress('bcc', $address, $name);
  261. }
  262.  
  263.  
  264. public function AddReplyTo($address, $name = '') {
  265. return $this->AddAnAddress('Reply-To', $address, $name);
  266. }
  267.  
  268.  
  269. protected function AddAnAddress($kind, $address, $name = '') {
  270. if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
  271. $this->SetError($this->Lang('Invalid recipient array').': '.$kind);
  272. if ($this->exceptions) {
  273. throw new phpmailerException('Invalid recipient array: ' . $kind);
  274. }
  275. if ($this->SMTPDebug) {
  276. $this->edebug($this->Lang('Invalid recipient array').': '.$kind);
  277. }
  278. return false;
  279. }
  280. $address = trim($address);
  281. $name = trim(preg_replace('/[\r\n]+/', '', $name)); if (!$this->ValidateAddress($address)) {
  282. $this->SetError($this->Lang('invalid_address').': '. $address);
  283. if ($this->exceptions) {
  284. throw new phpmailerException($this->Lang('invalid_address').': '.$address);
  285. }
  286. if ($this->SMTPDebug) {
  287. $this->edebug($this->Lang('invalid_address').': '.$address);
  288. }
  289. return false;
  290. }
  291. if ($kind != 'Reply-To') {
  292. if (!isset($this->all_recipients[strtolower($address)])) {
  293. array_push($this->$kind, array($address, $name));
  294. $this->all_recipients[strtolower($address)] = true;
  295. return true;
  296. }
  297. } else {
  298. if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  299. $this->ReplyTo[strtolower($address)] = array($address, $name);
  300. return true;
  301. }
  302. }
  303. return false;
  304. }
  305.  
  306.  
  307. public function SetFrom($address, $name = '', $auto = 1) {
  308. $address = trim($address);
  309. $name = trim(preg_replace('/[\r\n]+/', '', $name)); if (!$this->ValidateAddress($address)) {
  310. $this->SetError($this->Lang('invalid_address').': '. $address);
  311. if ($this->exceptions) {
  312. throw new phpmailerException($this->Lang('invalid_address').': '.$address);
  313. }
  314. if ($this->SMTPDebug) {
  315. $this->edebug($this->Lang('invalid_address').': '.$address);
  316. }
  317. return false;
  318. }
  319. $this->From = $address;
  320. $this->FromName = $name;
  321. if ($auto) {
  322. if (empty($this->ReplyTo)) {
  323. $this->AddAnAddress('Reply-To', $address, $name);
  324. }
  325. if (empty($this->Sender)) {
  326. $this->Sender = $address;
  327. }
  328. }
  329. return true;
  330. }
  331.  
  332.  
  333. public static function ValidateAddress($address) {
  334. return preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[ ])+|(?>[ ]*\x0D\x0A)?[ ]+)?)(\((?>(?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][:\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);
  335. }
  336.  
  337.  
  338.  
  339. public function Send() {
  340. try {
  341. if(!$this->PreSend()) return false;
  342. return $this->PostSend();
  343. } catch (phpmailerException $e) {
  344. $this->mailHeader = '';
  345. $this->SetError($e->getMessage());
  346. if ($this->exceptions) {
  347. throw $e;
  348. }
  349. return false;
  350. }
  351. }
  352.  
  353.  
  354. public function PreSend() {
  355. try {
  356. $this->mailHeader = "";
  357. if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  358. throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
  359. }
  360.  
  361. if(!empty($this->AltBody)) {
  362. $this->ContentType = 'multipart/alternative';
  363. }
  364.  
  365. $this->error_count = 0; $this->SetMessageType();
  366. if (empty($this->Body)) {
  367. throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
  368. }
  369.  
  370. $this->MIMEHeader = $this->CreateHeader();
  371. $this->MIMEBody = $this->CreateBody();
  372.  
  373. if ($this->Mailer == 'mail') {
  374. if (count($this->to) > 0) {
  375. $this->mailHeader .= $this->AddrAppend("To", $this->to);
  376. } else {
  377. $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
  378. }
  379. $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
  380. }
  381.  
  382. if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && !empty($this->DKIM_domain) && file_exists($this->DKIM_private)) {
  383. $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody);
  384. $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
  385. }
  386.  
  387. return true;
  388.  
  389. } catch (phpmailerException $e) {
  390. $this->SetError($e->getMessage());
  391. if ($this->exceptions) {
  392. throw $e;
  393. }
  394. return false;
  395. }
  396. }
  397.  
  398.  
  399. public function PostSend() {
  400. try {
  401. switch($this->Mailer) {
  402. case 'sendmail':
  403. return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
  404. case 'smtp':
  405. return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
  406. case 'mail':
  407. return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
  408. default:
  409. return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
  410. }
  411. } catch (phpmailerException $e) {
  412. $this->SetError($e->getMessage());
  413. if ($this->exceptions) {
  414. throw $e;
  415. }
  416. if ($this->SMTPDebug) {
  417. $this->edebug($e->getMessage()."\n");
  418. }
  419. }
  420. return false;
  421. }
  422.  
  423.  
  424. protected function SendmailSend($header, $body) {
  425. if ($this->Sender != '') {
  426. $sendmail = sprintf("%s -oi -f%s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  427. } else {
  428. $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
  429. }
  430. if ($this->SingleTo === true) {
  431. foreach ($this->SingleToArray as $val) {
  432. if(!@$mail = popen($sendmail, 'w')) {
  433. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  434. }
  435. fputs($mail, "To: " . $val . "\n");
  436. fputs($mail, $header);
  437. fputs($mail, $body);
  438. $result = pclose($mail);
  439. $isSent = ($result == 0) ? 1 : 0;
  440. $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
  441. if($result != 0) {
  442. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  443. }
  444. }
  445. } else {
  446. if(!@$mail = popen($sendmail, 'w')) {
  447. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  448. }
  449. fputs($mail, $header);
  450. fputs($mail, $body);
  451. $result = pclose($mail);
  452. $isSent = ($result == 0) ? 1 : 0;
  453. $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body);
  454. if($result != 0) {
  455. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  456. }
  457. }
  458. return true;
  459. }
  460.  
  461.  
  462. protected function MailSend($header, $body) {
  463. $toArr = array();
  464. foreach($this->to as $t) {
  465. $toArr[] = $this->AddrFormat($t);
  466. }
  467. $to = implode(', ', $toArr);
  468.  
  469. if (empty($this->Sender)) {
  470. $params = "-oi ";
  471. } else {
  472. $params = sprintf("-oi -f%s", $this->Sender);
  473. }
  474. if ($this->Sender != '' and !ini_get('safe_mode')) {
  475. $old_from = ini_get('sendmail_from');
  476. ini_set('sendmail_from', $this->Sender);
  477. }
  478. $rt = false;
  479. if ($this->SingleTo === true && count($toArr) > 1) {
  480. foreach ($toArr as $val) {
  481. $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params);
  482. $isSent = ($rt == 1) ? 1 : 0;
  483. $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
  484. }
  485. } else {
  486. $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params);
  487. $isSent = ($rt == 1) ? 1 : 0;
  488. $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
  489. }
  490. if (isset($old_from)) {
  491. ini_set('sendmail_from', $old_from);
  492. }
  493. if(!$rt) {
  494. throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL);
  495. }
  496. return true;
  497. }
  498.  
  499.  
  500. protected function SmtpSend($header, $body) {
  501. $bad_rcpt = array();
  502.  
  503. if(!$this->SmtpConnect()) {
  504. throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL);
  505. }
  506. $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
  507. if(!$this->smtp->Mail($smtp_from)) {
  508. throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL);
  509. }
  510.  
  511. foreach($this->to as $to) {
  512. if (!$this->smtp->Recipient($to[0])) {
  513. $bad_rcpt[] = $to[0];
  514. $isSent = 0;
  515. $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
  516. } else {
  517. $isSent = 1;
  518. $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
  519. }
  520. }
  521. foreach($this->cc as $cc) {
  522. if (!$this->smtp->Recipient($cc[0])) {
  523. $bad_rcpt[] = $cc[0];
  524. $isSent = 0;
  525. $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
  526. } else {
  527. $isSent = 1;
  528. $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
  529. }
  530. }
  531. foreach($this->bcc as $bcc) {
  532. if (!$this->smtp->Recipient($bcc[0])) {
  533. $bad_rcpt[] = $bcc[0];
  534. $isSent = 0;
  535. $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
  536. } else {
  537. $isSent = 1;
  538. $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
  539. }
  540. }
  541.  
  542.  
  543. if (count($bad_rcpt) > 0 ) { $badaddresses = implode(', ', $bad_rcpt);
  544. throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses);
  545. }
  546. if(!$this->smtp->Data($header . $body)) {
  547. throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL);
  548. }
  549. if($this->SMTPKeepAlive == true) {
  550. $this->smtp->Reset();
  551. } else {
  552. $this->smtp->Quit();
  553. $this->smtp->Close();
  554. }
  555. return true;
  556. }
  557.  
  558.  
  559. public function SmtpConnect() {
  560. if(is_null($this->smtp)) {
  561. $this->smtp = new SMTP;
  562. }
  563.  
  564. $this->smtp->Timeout = $this->Timeout;
  565. $this->smtp->do_debug = $this->SMTPDebug;
  566. $hosts = explode(';', $this->Host);
  567. $index = 0;
  568. $connection = $this->smtp->Connected();
  569.  
  570. try {
  571. while($index < count($hosts) && !$connection) {
  572. $hostinfo = array();
  573. if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
  574. $host = $hostinfo[1];
  575. $port = $hostinfo[2];
  576. } else {
  577. $host = $hosts[$index];
  578. $port = $this->Port;
  579. }
  580.  
  581. $tls = ($this->SMTPSecure == 'tls');
  582. $ssl = ($this->SMTPSecure == 'ssl');
  583.  
  584. if ($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) {
  585.  
  586. $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname());
  587. $this->smtp->Hello($hello);
  588.  
  589. if ($tls) {
  590. if (!$this->smtp->StartTLS()) {
  591. throw new phpmailerException($this->Lang('tls'));
  592. }
  593.  
  594. $this->smtp->Hello($hello);
  595. }
  596.  
  597. $connection = true;
  598. if ($this->SMTPAuth) {
  599. if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType,
  600. $this->Realm, $this->Workstation)) {
  601. throw new phpmailerException($this->Lang('authenticate'));
  602. }
  603. }
  604. }
  605. $index++;
  606. if (!$connection) {
  607. throw new phpmailerException($this->Lang('connect_host'));
  608. }
  609. }
  610. } catch (phpmailerException $e) {
  611. $this->smtp->Reset();
  612. if ($this->exceptions) {
  613. throw $e;
  614. }
  615. }
  616. return true;
  617. }
  618.  
  619.  
  620. public function SmtpClose() {
  621. if ($this->smtp !== null) {
  622. if($this->smtp->Connected()) {
  623. $this->smtp->Quit();
  624. $this->smtp->Close();
  625. }
  626. }
  627. }
  628.  
  629.  
  630. function SetLanguage($langcode = 'en', $lang_path = 'language/') {
  631. $PHPMAILER_LANG = array(
  632. 'authenticate' => 'SMTP Error: Could not authenticate.',
  633. 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  634. 'data_not_accepted' => 'SMTP Error: Data not accepted.',
  635. 'empty_message' => 'Message body empty',
  636. 'encoding' => 'Unknown encoding: ',
  637. 'execute' => 'Could not execute: ',
  638. 'file_access' => 'Could not access file: ',
  639. 'file_open' => 'File Error: Could not open file: ',
  640. 'from_failed' => 'The following From address failed: ',
  641. 'instantiate' => 'Could not instantiate mail function.',
  642. 'invalid_address' => 'Invalid address',
  643. 'mailer_not_supported' => ' mailer is not supported.',
  644. 'provide_address' => 'You must provide at least one recipient email address.',
  645. 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  646. 'signing' => 'Signing Error: ',
  647. 'smtp_connect_failed' => 'SMTP Connect() failed.',
  648. 'smtp_error' => 'SMTP server error: ',
  649. 'variable_set' => 'Cannot set or reset variable: '
  650. );
  651. $l = true;
  652. if ($langcode != 'en') { $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php';
  653. }
  654. $this->language = $PHPMAILER_LANG;
  655. return ($l == true); }
  656.  
  657.  
  658. public function GetTranslations() {
  659. return $this->language;
  660. }
  661.  
  662.  
  663.  
  664. public function AddrAppend($type, $addr) {
  665. $addr_str = $type . ': ';
  666. $addresses = array();
  667. foreach ($addr as $a) {
  668. $addresses[] = $this->AddrFormat($a);
  669. }
  670. $addr_str .= implode(', ', $addresses);
  671. $addr_str .= $this->LE;
  672.  
  673. return $addr_str;
  674. }
  675.  
  676.  
  677. public function AddrFormat($addr) {
  678. if (empty($addr[1])) {
  679. return $this->SecureHeader($addr[0]);
  680. } else {
  681. return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
  682. }
  683. }
  684.  
  685.  
  686. public function WrapText($message, $length, $qp_mode = false) {
  687. $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  688. $is_utf8 = (strtolower($this->CharSet) == "utf-8");
  689. $lelen = strlen($this->LE);
  690. $crlflen = strlen(self::CRLF);
  691.  
  692. $message = $this->FixEOL($message);
  693. if (substr($message, -$lelen) == $this->LE) {
  694. $message = substr($message, 0, -$lelen);
  695. }
  696.  
  697. $line = explode($this->LE, $message); $message = '';
  698. for ($i = 0 ;$i < count($line); $i++) {
  699. $line_part = explode(' ', $line[$i]);
  700. $buf = '';
  701. for ($e = 0; $e<count($line_part); $e++) {
  702. $word = $line_part[$e];
  703. if ($qp_mode and (strlen($word) > $length)) {
  704. $space_left = $length - strlen($buf) - $crlflen;
  705. if ($e != 0) {
  706. if ($space_left > 20) {
  707. $len = $space_left;
  708. if ($is_utf8) {
  709. $len = $this->UTF8CharBoundary($word, $len);
  710. } elseif (substr($word, $len - 1, 1) == "=") {
  711. $len--;
  712. } elseif (substr($word, $len - 2, 1) == "=") {
  713. $len -= 2;
  714. }
  715. $part = substr($word, 0, $len);
  716. $word = substr($word, $len);
  717. $buf .= ' ' . $part;
  718. $message .= $buf . sprintf("=%s", self::CRLF);
  719. } else {
  720. $message .= $buf . $soft_break;
  721. }
  722. $buf = '';
  723. }
  724. while (strlen($word) > 0) {
  725. $len = $length;
  726. if ($is_utf8) {
  727. $len = $this->UTF8CharBoundary($word, $len);
  728. } elseif (substr($word, $len - 1, 1) == "=") {
  729. $len--;
  730. } elseif (substr($word, $len - 2, 1) == "=") {
  731. $len -= 2;
  732. }
  733. $part = substr($word, 0, $len);
  734. $word = substr($word, $len);
  735.  
  736. if (strlen($word) > 0) {
  737. $message .= $part . sprintf("=%s", self::CRLF);
  738. } else {
  739. $buf = $part;
  740. }
  741. }
  742. } else {
  743. $buf_o = $buf;
  744. $buf .= ($e == 0) ? $word : (' ' . $word);
  745.  
  746. if (strlen($buf) > $length and $buf_o != '') {
  747. $message .= $buf_o . $soft_break;
  748. $buf = $word;
  749. }
  750. }
  751. }
  752. $message .= $buf . self::CRLF;
  753. }
  754.  
  755. return $message;
  756. }
  757.  
  758.  
  759. public function UTF8CharBoundary($encodedText, $maxLength) {
  760. $foundSplitPos = false;
  761. $lookBack = 3;
  762. while (!$foundSplitPos) {
  763. $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  764. $encodedCharPos = strpos($lastChunk, "=");
  765. if ($encodedCharPos !== false) {
  766. $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  767. $dec = hexdec($hex);
  768. if ($dec < 128) { $maxLength = ($encodedCharPos == 0) ? $maxLength :
  769. $maxLength - ($lookBack - $encodedCharPos);
  770. $foundSplitPos = true;
  771. } elseif ($dec >= 192) { $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  772. $foundSplitPos = true;
  773. } elseif ($dec < 192) { $lookBack += 3;
  774. }
  775. } else {
  776. $foundSplitPos = true;
  777. }
  778. }
  779. return $maxLength;
  780. }
  781.  
  782.  
  783.  
  784. public function SetWordWrap() {
  785. if($this->WordWrap < 1) {
  786. return;
  787. }
  788.  
  789. switch($this->message_type) {
  790. case 'alt':
  791. case 'alt_inline':
  792. case 'alt_attach':
  793. case 'alt_inline_attach':
  794. $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  795. break;
  796. default:
  797. $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  798. break;
  799. }
  800. }
  801.  
  802.  
  803. public function CreateHeader() {
  804. $result = '';
  805.  
  806. $uniq_id = md5(uniqid(time()));
  807. $this->boundary[1] = 'b1_' . $uniq_id;
  808. $this->boundary[2] = 'b2_' . $uniq_id;
  809. $this->boundary[3] = 'b3_' . $uniq_id;
  810.  
  811. if ($this->MessageDate == '') {
  812. $result .= $this->HeaderLine('Date', self::RFCDate());
  813. } else {
  814. $result .= $this->HeaderLine('Date', $this->MessageDate);
  815. }
  816.  
  817. if ($this->ReturnPath) {
  818. $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath));
  819. } elseif ($this->Sender == '') {
  820. $result .= $this->HeaderLine('Return-Path', trim($this->From));
  821. } else {
  822. $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
  823. }
  824.  
  825. if($this->Mailer != 'mail') {
  826. if ($this->SingleTo === true) {
  827. foreach($this->to as $t) {
  828. $this->SingleToArray[] = $this->AddrFormat($t);
  829. }
  830. } else {
  831. if(count($this->to) > 0) {
  832. $result .= $this->AddrAppend('To', $this->to);
  833. } elseif (count($this->cc) == 0) {
  834. $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
  835. }
  836. }
  837. }
  838.  
  839. $from = array();
  840. $from[0][0] = trim($this->From);
  841. $from[0][1] = $this->FromName;
  842. $result .= $this->AddrAppend('From', $from);
  843.  
  844. if(count($this->cc) > 0) {
  845. $result .= $this->AddrAppend('Cc', $this->cc);
  846. }
  847.  
  848. if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
  849. $result .= $this->AddrAppend('Bcc', $this->bcc);
  850. }
  851.  
  852. if(count($this->ReplyTo) > 0) {
  853. $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
  854. }
  855.  
  856. if($this->Mailer != 'mail') {
  857. $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
  858. }
  859.  
  860. if($this->MessageID != '') {
  861. $result .= $this->HeaderLine('Message-ID', $this->MessageID);
  862. } else {
  863. $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  864. }
  865. $result .= $this->HeaderLine('X-Priority', $this->Priority);
  866. if ($this->XMailer == '') {
  867. $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
  868. } else {
  869. $myXmailer = trim($this->XMailer);
  870. if ($myXmailer) {
  871. $result .= $this->HeaderLine('X-Mailer', $myXmailer);
  872. }
  873. }
  874.  
  875. if($this->ConfirmReadingTo != '') {
  876. $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  877. }
  878.  
  879. for($index = 0; $index < count($this->CustomHeader); $index++) {
  880. $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  881. }
  882. if (!$this->sign_key_file) {
  883. $result .= $this->HeaderLine('MIME-Version', '1.0');
  884. $result .= $this->GetMailMIME();
  885. }
  886.  
  887. return $result;
  888. }
  889.  
  890.  
  891. public function GetMailMIME() {
  892. $result = '';
  893. switch($this->message_type) {
  894. case 'inline':
  895. $result .= $this->HeaderLine('Content-Type', 'multipart/related;');
  896. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  897. break;
  898. case 'attach':
  899. case 'inline_attach':
  900. case 'alt_attach':
  901. case 'alt_inline_attach':
  902. $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
  903. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  904. break;
  905. case 'alt':
  906. case 'alt_inline':
  907. $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
  908. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  909. break;
  910. default:
  911. $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
  912. $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet);
  913. break;
  914. }
  915.  
  916. if($this->Mailer != 'mail') {
  917. $result .= $this->LE;
  918. }
  919.  
  920. return $result;
  921. }
  922.  
  923.  
  924. public function GetSentMIMEMessage() {
  925. return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
  926. }
  927.  
  928.  
  929.  
  930. public function CreateBody() {
  931. $body = '';
  932.  
  933. if ($this->sign_key_file) {
  934. $body .= $this->GetMailMIME().$this->LE;
  935. }
  936.  
  937. $this->SetWordWrap();
  938.  
  939. switch($this->message_type) {
  940. case 'inline':
  941. $body .= $this->GetBoundary($this->boundary[1], '', '', '');
  942. $body .= $this->EncodeString($this->Body, $this->Encoding);
  943. $body .= $this->LE.$this->LE;
  944. $body .= $this->AttachAll("inline", $this->boundary[1]);
  945. break;
  946. case 'attach':
  947. $body .= $this->GetBoundary($this->boundary[1], '', '', '');
  948. $body .= $this->EncodeString($this->Body, $this->Encoding);
  949. $body .= $this->LE.$this->LE;
  950. $body .= $this->AttachAll("attachment", $this->boundary[1]);
  951. break;
  952. case 'inline_attach':
  953. $body .= $this->TextLine("--" . $this->boundary[1]);
  954. $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
  955. $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
  956. $body .= $this->LE;
  957. $body .= $this->GetBoundary($this->boundary[2], '', '', '');
  958. $body .= $this->EncodeString($this->Body, $this->Encoding);
  959. $body .= $this->LE.$this->LE;
  960. $body .= $this->AttachAll("inline", $this->boundary[2]);
  961. $body .= $this->LE;
  962. $body .= $this->AttachAll("attachment", $this->boundary[1]);
  963. break;
  964. case 'alt':
  965. $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
  966. $body .= $this->EncodeString($this->AltBody, $this->Encoding);
  967. $body .= $this->LE.$this->LE;
  968. $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
  969. $body .= $this->EncodeString($this->Body, $this->Encoding);
  970. $body .= $this->LE.$this->LE;
  971. $body .= $this->EndBoundary($this->boundary[1]);
  972. break;
  973. case 'alt_inline':
  974. $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
  975. $body .= $this->EncodeString($this->AltBody, $this->Encoding);
  976. $body .= $this->LE.$this->LE;
  977. $body .= $this->TextLine("--" . $this->boundary[1]);
  978. $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
  979. $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
  980. $body .= $this->LE;
  981. $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
  982. $body .= $this->EncodeString($this->Body, $this->Encoding);
  983. $body .= $this->LE.$this->LE;
  984. $body .= $this->AttachAll("inline", $this->boundary[2]);
  985. $body .= $this->LE;
  986. $body .= $this->EndBoundary($this->boundary[1]);
  987. break;
  988. case 'alt_attach':
  989. $body .= $this->TextLine("--" . $this->boundary[1]);
  990. $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
  991. $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
  992. $body .= $this->LE;
  993. $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
  994. $body .= $this->EncodeString($this->AltBody, $this->Encoding);
  995. $body .= $this->LE.$this->LE;
  996. $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
  997. $body .= $this->EncodeString($this->Body, $this->Encoding);
  998. $body .= $this->LE.$this->LE;
  999. $body .= $this->EndBoundary($this->boundary[2]);
  1000. $body .= $this->LE;
  1001. $body .= $this->AttachAll("attachment", $this->boundary[1]);
  1002. break;
  1003. case 'alt_inline_attach':
  1004. $body .= $this->TextLine("--" . $this->boundary[1]);
  1005. $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
  1006. $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
  1007. $body .= $this->LE;
  1008. $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
  1009. $body .= $this->EncodeString($this->AltBody, $this->Encoding);
  1010. $body .= $this->LE.$this->LE;
  1011. $body .= $this->TextLine("--" . $this->boundary[2]);
  1012. $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
  1013. $body .= $this->TextLine("\tboundary=\"" . $this->boundary[3] . '"');
  1014. $body .= $this->LE;
  1015. $body .= $this->GetBoundary($this->boundary[3], '', 'text/html', '');
  1016. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1017. $body .= $this->LE.$this->LE;
  1018. $body .= $this->AttachAll("inline", $this->boundary[3]);
  1019. $body .= $this->LE;
  1020. $body .= $this->EndBoundary($this->boundary[2]);
  1021. $body .= $this->LE;
  1022. $body .= $this->AttachAll("attachment", $this->boundary[1]);
  1023. break;
  1024. default:
  1025. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1026. break;
  1027. }
  1028.  
  1029. if ($this->IsError()) {
  1030. $body = '';
  1031. } elseif ($this->sign_key_file) {
  1032. try {
  1033. $file = tempnam('', 'mail');
  1034. file_put_contents($file, $body); $signed = tempnam("", "signed");
  1035. if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
  1036. @unlink($file);
  1037. $body = file_get_contents($signed);
  1038. @unlink($signed);
  1039. } else {
  1040. @unlink($file);
  1041. @unlink($signed);
  1042. throw new phpmailerException($this->Lang("signing").openssl_error_string());
  1043. }
  1044. } catch (phpmailerException $e) {
  1045. $body = '';
  1046. if ($this->exceptions) {
  1047. throw $e;
  1048. }
  1049. }
  1050. }
  1051.  
  1052. return $body;
  1053. }
  1054.  
  1055.  
  1056. protected function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  1057. $result = '';
  1058. if($charSet == '') {
  1059. $charSet = $this->CharSet;
  1060. }
  1061. if($contentType == '') {
  1062. $contentType = $this->ContentType;
  1063. }
  1064. if($encoding == '') {
  1065. $encoding = $this->Encoding;
  1066. }
  1067. $result .= $this->TextLine('--' . $boundary);
  1068. $result .= sprintf("Content-Type: %s; charset=%s", $contentType, $charSet);
  1069. $result .= $this->LE;
  1070. $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
  1071. $result .= $this->LE;
  1072.  
  1073. return $result;
  1074. }
  1075.  
  1076.  
  1077. protected function EndBoundary($boundary) {
  1078. return $this->LE . '--' . $boundary . '--' . $this->LE;
  1079. }
  1080.  
  1081.  
  1082. protected function SetMessageType() {
  1083. $this->message_type = array();
  1084. if($this->AlternativeExists()) $this->message_type[] = "alt";
  1085. if($this->InlineImageExists()) $this->message_type[] = "inline";
  1086. if($this->AttachmentExists()) $this->message_type[] = "attach";
  1087. $this->message_type = implode("_", $this->message_type);
  1088. if($this->message_type == "") $this->message_type = "plain";
  1089. }
  1090.  
  1091.  
  1092. public function HeaderLine($name, $value) {
  1093. return $name . ': ' . $value . $this->LE;
  1094. }
  1095.  
  1096.  
  1097. public function TextLine($value) {
  1098. return $value . $this->LE;
  1099. }
  1100.  
  1101.  
  1102.  
  1103. public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1104. try {
  1105. if ( !@is_file($path) ) {
  1106. throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE);
  1107. }
  1108. $filename = basename($path);
  1109. if ( $name == '' ) {
  1110. $name = $filename;
  1111. }
  1112.  
  1113. $this->attachment[] = array(
  1114. 0 => $path,
  1115. 1 => $filename,
  1116. 2 => $name,
  1117. 3 => $encoding,
  1118. 4 => $type,
  1119. 5 => false, 6 => 'attachment',
  1120. 7 => 0
  1121. );
  1122.  
  1123. } catch (phpmailerException $e) {
  1124. $this->SetError($e->getMessage());
  1125. if ($this->exceptions) {
  1126. throw $e;
  1127. }
  1128. if ($this->SMTPDebug) {
  1129. $this->edebug($e->getMessage()."\n");
  1130. }
  1131. if ( $e->getCode() == self::STOP_CRITICAL ) {
  1132. return false;
  1133. }
  1134. }
  1135. return true;
  1136. }
  1137.  
  1138.  
  1139. public function GetAttachments() {
  1140. return $this->attachment;
  1141. }
  1142.  
  1143.  
  1144. protected function AttachAll($disposition_type, $boundary) {
  1145. $mime = array();
  1146. $cidUniq = array();
  1147. $incl = array();
  1148.  
  1149. foreach ($this->attachment as $attachment) {
  1150. if($attachment[6] == $disposition_type) {
  1151. $string = '';
  1152. $path = '';
  1153. $bString = $attachment[5];
  1154. if ($bString) {
  1155. $string = $attachment[0];
  1156. } else {
  1157. $path = $attachment[0];
  1158. }
  1159.  
  1160. $inclhash = md5(serialize($attachment));
  1161. if (in_array($inclhash, $incl)) { continue; }
  1162. $incl[] = $inclhash;
  1163. $filename = $attachment[1];
  1164. $name = $attachment[2];
  1165. $encoding = $attachment[3];
  1166. $type = $attachment[4];
  1167. $disposition = $attachment[6];
  1168. $cid = $attachment[7];
  1169. if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
  1170. $cidUniq[$cid] = true;
  1171.  
  1172. $mime[] = sprintf("--%s%s", $boundary, $this->LE);
  1173. $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
  1174. $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  1175.  
  1176. if($disposition == 'inline') {
  1177. $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  1178. }
  1179.  
  1180. $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
  1181.  
  1182. if($bString) {
  1183. $mime[] = $this->EncodeString($string, $encoding);
  1184. if($this->IsError()) {
  1185. return '';
  1186. }
  1187. $mime[] = $this->LE.$this->LE;
  1188. } else {
  1189. $mime[] = $this->EncodeFile($path, $encoding);
  1190. if($this->IsError()) {
  1191. return '';
  1192. }
  1193. $mime[] = $this->LE.$this->LE;
  1194. }
  1195. }
  1196. }
  1197.  
  1198. $mime[] = sprintf("--%s--%s", $boundary, $this->LE);
  1199.  
  1200. return implode("", $mime);
  1201. }
  1202.  
  1203.  
  1204. protected function EncodeFile($path, $encoding = 'base64') {
  1205. try {
  1206. if (!is_readable($path)) {
  1207. throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
  1208. }
  1209. $magic_quotes = get_magic_quotes_runtime();
  1210. if ($magic_quotes) {
  1211. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  1212. set_magic_quotes_runtime(0);
  1213. } else {
  1214. ini_set('magic_quotes_runtime', 0);
  1215. }
  1216. }
  1217. $file_buffer = file_get_contents($path);
  1218. $file_buffer = $this->EncodeString($file_buffer, $encoding);
  1219. if ($magic_quotes) {
  1220. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  1221. set_magic_quotes_runtime($magic_quotes);
  1222. } else {
  1223. ini_set('magic_quotes_runtime', $magic_quotes);
  1224. }
  1225. }
  1226. return $file_buffer;
  1227. } catch (Exception $e) {
  1228. $this->SetError($e->getMessage());
  1229. return '';
  1230. }
  1231. }
  1232.  
  1233.  
  1234. public function EncodeString($str, $encoding = 'base64') {
  1235. $encoded = '';
  1236. switch(strtolower($encoding)) {
  1237. case 'base64':
  1238. $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  1239. break;
  1240. case '7bit':
  1241. case '8bit':
  1242. $encoded = $this->FixEOL($str);
  1243. if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  1244. $encoded .= $this->LE;
  1245. break;
  1246. case 'binary':
  1247. $encoded = $str;
  1248. break;
  1249. case 'quoted-printable':
  1250. $encoded = $this->EncodeQP($str);
  1251. break;
  1252. default:
  1253. $this->SetError($this->Lang('encoding') . $encoding);
  1254. break;
  1255. }
  1256. return $encoded;
  1257. }
  1258.  
  1259.  
  1260. public function EncodeHeader($str, $position = 'text') {
  1261. $x = 0;
  1262.  
  1263. switch (strtolower($position)) {
  1264. case 'phrase':
  1265. if (!preg_match('/[\200-\377]/', $str)) {
  1266. $encoded = addcslashes($str, "\0..\37\177\\\"");
  1267. if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  1268. return ($encoded);
  1269. } else {
  1270. return ("\"$encoded\"");
  1271. }
  1272. }
  1273. $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  1274. break;
  1275. case 'comment':
  1276. $x = preg_match_all('/[()"]/', $str, $matches);
  1277. case 'text':
  1278. default:
  1279. $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  1280. break;
  1281. }
  1282.  
  1283. if ($x == 0) {
  1284. return ($str);
  1285. }
  1286.  
  1287. $maxlen = 75 - 7 - strlen($this->CharSet);
  1288. if (strlen($str)/3 < $x) {
  1289. $encoding = 'B';
  1290. if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
  1291. $encoded = $this->Base64EncodeWrapMB($str, "\n");
  1292. } else {
  1293. $encoded = base64_encode($str);
  1294. $maxlen -= $maxlen % 4;
  1295. $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  1296. }
  1297. } else {
  1298. $encoding = 'Q';
  1299. $encoded = $this->EncodeQ($str, $position);
  1300. $encoded = $this->WrapText($encoded, $maxlen, true);
  1301. $encoded = str_replace('='.self::CRLF, "\n", trim($encoded));
  1302. }
  1303.  
  1304. $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  1305. $encoded = trim(str_replace("\n", $this->LE, $encoded));
  1306.  
  1307. return $encoded;
  1308. }
  1309.  
  1310.  
  1311. public function HasMultiBytes($str) {
  1312. if (function_exists('mb_strlen')) {
  1313. return (strlen($str) > mb_strlen($str, $this->CharSet));
  1314. } else { return false;
  1315. }
  1316. }
  1317.  
  1318.  
  1319. public function Base64EncodeWrapMB($str, $lf=null) {
  1320. $start = "=?".$this->CharSet."?B?";
  1321. $end = "?=";
  1322. $encoded = "";
  1323. if ($lf === null) {
  1324. $lf = $this->LE;
  1325. }
  1326.  
  1327. $mb_length = mb_strlen($str, $this->CharSet);
  1328. $length = 75 - strlen($start) - strlen($end);
  1329. $ratio = $mb_length / strlen($str);
  1330. $offset = $avgLength = floor($length * $ratio * .75);
  1331.  
  1332. for ($i = 0; $i < $mb_length; $i += $offset) {
  1333. $lookBack = 0;
  1334.  
  1335. do {
  1336. $offset = $avgLength - $lookBack;
  1337. $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  1338. $chunk = base64_encode($chunk);
  1339. $lookBack++;
  1340. }
  1341. while (strlen($chunk) > $length);
  1342.  
  1343. $encoded .= $chunk . $lf;
  1344. }
  1345.  
  1346. $encoded = substr($encoded, 0, -strlen($lf));
  1347. return $encoded;
  1348. }
  1349.  
  1350.  
  1351. public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
  1352. $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
  1353. $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
  1354. $eol = "\r\n";
  1355. $escape = '=';
  1356. $output = '';
  1357. while( list(, $line) = each($lines) ) {
  1358. $linlen = strlen($line);
  1359. $newline = '';
  1360. for($i = 0; $i < $linlen; $i++) {
  1361. $c = substr( $line, $i, 1 );
  1362. $dec = ord( $c );
  1363. if ( ( $i == 0 ) && ( $dec == 46 ) ) { $c = '=2E';
  1364. }
  1365. if ( $dec == 32 ) {
  1366. if ( $i == ( $linlen - 1 ) ) { $c = '=20';
  1367. } else if ( $space_conv ) {
  1368. $c = '=20';
  1369. }
  1370. } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { $h2 = (integer)floor($dec/16);
  1371. $h1 = (integer)floor($dec%16);
  1372. $c = $escape.$hex[$h2].$hex[$h1];
  1373. }
  1374. if ( (strlen($newline) + strlen($c)) >= $line_max ) { $output .= $newline.$escape.$eol; $newline = '';
  1375. if ( $dec == 46 ) {
  1376. $c = '=2E';
  1377. }
  1378. }
  1379. $newline .= $c;
  1380. } $output .= $newline.$eol;
  1381. } return $output;
  1382. }
  1383.  
  1384.  
  1385. public function EncodeQP($string, $line_max = 76, $space_conv = false) {
  1386. if (function_exists('quoted_printable_encode')) { return quoted_printable_encode($string);
  1387. }
  1388. $filters = stream_get_filters();
  1389. if (!in_array('convert.*', $filters)) { return $this->EncodeQPphp($string, $line_max, $space_conv); }
  1390. $fp = fopen('php://temp/', 'r+');
  1391. $string = preg_replace('/\r\n?/', $this->LE, $string); $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE);
  1392. $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
  1393. fputs($fp, $string);
  1394. rewind($fp);
  1395. $out = stream_get_contents($fp);
  1396. stream_filter_remove($s);
  1397. $out = preg_replace('/^\./m', '=2E', $out); fclose($fp);
  1398. return $out;
  1399. }
  1400.  
  1401.  
  1402. public function EncodeQ($str, $position = 'text') {
  1403. $pattern="";
  1404. $encoded = str_replace(array("\r", "\n"), '', $str);
  1405. switch (strtolower($position)) {
  1406. case 'phrase':
  1407. $pattern = '^A-Za-z0-9!*+\/ -';
  1408. break;
  1409.  
  1410. case 'comment':
  1411. $pattern = '\(\)"';
  1412.  
  1413. case 'text':
  1414. default:
  1415. $pattern = '\075\000-\011\013\014\016-\037\077\137\177-\377' . $pattern;
  1416. break;
  1417. }
  1418.  
  1419. if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
  1420. foreach (array_unique($matches[0]) as $char) {
  1421. $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
  1422. }
  1423. }
  1424.  
  1425. return str_replace(' ', '_', $encoded);
  1426. }
  1427.  
  1428.  
  1429.  
  1430. public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
  1431. $this->attachment[] = array(
  1432. 0 => $string,
  1433. 1 => $filename,
  1434. 2 => basename($filename),
  1435. 3 => $encoding,
  1436. 4 => $type,
  1437. 5 => true, 6 => 'attachment',
  1438. 7 => 0
  1439. );
  1440. }
  1441.  
  1442.  
  1443. public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1444.  
  1445. if ( !@is_file($path) ) {
  1446. $this->SetError($this->Lang('file_access') . $path);
  1447. return false;
  1448. }
  1449.  
  1450. $filename = basename($path);
  1451. if ( $name == '' ) {
  1452. $name = $filename;
  1453. }
  1454.  
  1455. $this->attachment[] = array(
  1456. 0 => $path,
  1457. 1 => $filename,
  1458. 2 => $name,
  1459. 3 => $encoding,
  1460. 4 => $type,
  1461. 5 => false, 6 => 'inline',
  1462. 7 => $cid
  1463. );
  1464.  
  1465. return true;
  1466. }
  1467.  
  1468.  
  1469. public function AddStringEmbeddedImage($string, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1470. $this->attachment[] = array(
  1471. 0 => $string,
  1472. 1 => $name,
  1473. 2 => $name,
  1474. 3 => $encoding,
  1475. 4 => $type,
  1476. 5 => true, 6 => 'inline',
  1477. 7 => $cid
  1478. );
  1479. }
  1480.  
  1481.  
  1482. public function InlineImageExists() {
  1483. foreach($this->attachment as $attachment) {
  1484. if ($attachment[6] == 'inline') {
  1485. return true;
  1486. }
  1487. }
  1488. return false;
  1489. }
  1490.  
  1491.  
  1492. public function AttachmentExists() {
  1493. foreach($this->attachment as $attachment) {
  1494. if ($attachment[6] == 'attachment') {
  1495. return true;
  1496. }
  1497. }
  1498. return false;
  1499. }
  1500.  
  1501.  
  1502. public function AlternativeExists() {
  1503. return !empty($this->AltBody);
  1504. }
  1505.  
  1506.  
  1507.  
  1508. public function ClearAddresses() {
  1509. foreach($this->to as $to) {
  1510. unset($this->all_recipients[strtolower($to[0])]);
  1511. }
  1512. $this->to = array();
  1513. }
  1514.  
  1515.  
  1516. public function ClearCCs() {
  1517. foreach($this->cc as $cc) {
  1518. unset($this->all_recipients[strtolower($cc[0])]);
  1519. }
  1520. $this->cc = array();
  1521. }
  1522.  
  1523.  
  1524. public function ClearBCCs() {
  1525. foreach($this->bcc as $bcc) {
  1526. unset($this->all_recipients[strtolower($bcc[0])]);
  1527. }
  1528. $this->bcc = array();
  1529. }
  1530.  
  1531.  
  1532. public function ClearReplyTos() {
  1533. $this->ReplyTo = array();
  1534. }
  1535.  
  1536.  
  1537. public function ClearAllRecipients() {
  1538. $this->to = array();
  1539. $this->cc = array();
  1540. $this->bcc = array();
  1541. $this->all_recipients = array();
  1542. }
  1543.  
  1544.  
  1545. public function ClearAttachments() {
  1546. $this->attachment = array();
  1547. }
  1548.  
  1549.  
  1550. public function ClearCustomHeaders() {
  1551. $this->CustomHeader = array();
  1552. }
  1553.  
  1554.  
  1555.  
  1556. protected function SetError($msg) {
  1557. $this->error_count++;
  1558. if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
  1559. $lasterror = $this->smtp->getError();
  1560. if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
  1561. $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
  1562. }
  1563. }
  1564. $this->ErrorInfo = $msg;
  1565. }
  1566.  
  1567.  
  1568. public static function RFCDate() {
  1569. $tz = date('Z');
  1570. $tzs = ($tz < 0) ? '-' : '+';
  1571. $tz = abs($tz);
  1572. $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
  1573. $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
  1574.  
  1575. return $result;
  1576. }
  1577.  
  1578.  
  1579. protected function ServerHostname() {
  1580. if (!empty($this->Hostname)) {
  1581. $result = $this->Hostname;
  1582. } elseif (isset($_SERVER['SERVER_NAME'])) {
  1583. $result = $_SERVER['SERVER_NAME'];
  1584. } else {
  1585. $result = 'localhost.localdomain';
  1586. }
  1587.  
  1588. return $result;
  1589. }
  1590.  
  1591.  
  1592. protected function Lang($key) {
  1593. if(count($this->language) < 1) {
  1594. $this->SetLanguage('en'); }
  1595.  
  1596. if(isset($this->language[$key])) {
  1597. return $this->language[$key];
  1598. } else {
  1599. return 'Language string failed to load: ' . $key;
  1600. }
  1601. }
  1602.  
  1603.  
  1604. public function IsError() {
  1605. return ($this->error_count > 0);
  1606. }
  1607.  
  1608.  
  1609. public function FixEOL($str) {
  1610. $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
  1611. if ($this->LE !== "\n") {
  1612. $nstr = str_replace("\n", $this->LE, $nstr);
  1613. }
  1614. return $nstr;
  1615. }
  1616.  
  1617.  
  1618. public function AddCustomHeader($name, $value=null) {
  1619. if ($value === null) {
  1620. $this->CustomHeader[] = explode(':', $name, 2);
  1621. } else {
  1622. $this->CustomHeader[] = array($name, $value);
  1623. }
  1624. }
  1625.  
  1626.  
  1627. public function MsgHTML($message, $basedir = '') {
  1628. preg_match_all("/(src|background)=[\"'](.*)[\"']/Ui", $message, $images);
  1629. if(isset($images[2])) {
  1630. foreach($images[2] as $i => $url) {
  1631. if (!preg_match('#^[A-z]+://#', $url)) {
  1632. $filename = basename($url);
  1633. $directory = dirname($url);
  1634. if ($directory == '.') {
  1635. $directory = '';
  1636. }
  1637. $cid = 'cid:' . md5($filename);
  1638. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  1639. $mimeType = self::_mime_types($ext);
  1640. if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; }
  1641. if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
  1642. if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) {
  1643. $message = preg_replace("/".$images[1][$i]."=[\"']".preg_quote($url, '/')."[\"']/Ui", $images[1][$i]."=\"".$cid."\"", $message);
  1644. }
  1645. }
  1646. }
  1647. }
  1648. $this->IsHTML(true);
  1649. $this->Body = $message;
  1650. if (empty($this->AltBody)) {
  1651. $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
  1652. if (!empty($textMsg)) {
  1653. $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);
  1654. }
  1655. }
  1656. if (empty($this->AltBody)) {
  1657. $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
  1658. }
  1659. return $message;
  1660. }
  1661.  
  1662.  
  1663. public static function _mime_types($ext = '') {
  1664. $mimes = array(
  1665. 'xl' => 'application/excel',
  1666. 'hqx' => 'application/mac-binhex40',
  1667. 'cpt' => 'application/mac-compactpro',
  1668. 'bin' => 'application/macbinary',
  1669. 'doc' => 'application/msword',
  1670. 'word' => 'application/msword',
  1671. 'class' => 'application/octet-stream',
  1672. 'dll' => 'application/octet-stream',
  1673. 'dms' => 'application/octet-stream',
  1674. 'exe' => 'application/octet-stream',
  1675. 'lha' => 'application/octet-stream',
  1676. 'lzh' => 'application/octet-stream',
  1677. 'psd' => 'application/octet-stream',
  1678. 'sea' => 'application/octet-stream',
  1679. 'so' => 'application/octet-stream',
  1680. 'oda' => 'application/oda',
  1681. 'pdf' => 'application/pdf',
  1682. 'ai' => 'application/postscript',
  1683. 'eps' => 'application/postscript',
  1684. 'ps' => 'application/postscript',
  1685. 'smi' => 'application/smil',
  1686. 'smil' => 'application/smil',
  1687. 'mif' => 'application/vnd.mif',
  1688. 'xls' => 'application/vnd.ms-excel',
  1689. 'ppt' => 'application/vnd.ms-powerpoint',
  1690. 'wbxml' => 'application/vnd.wap.wbxml',
  1691. 'wmlc' => 'application/vnd.wap.wmlc',
  1692. 'dcr' => 'application/x-director',
  1693. 'dir' => 'application/x-director',
  1694. 'dxr' => 'application/x-director',
  1695. 'dvi' => 'application/x-dvi',
  1696. 'gtar' => 'application/x-gtar',
  1697. 'php3' => 'application/x-httpd-php',
  1698. 'php4' => 'application/x-httpd-php',
  1699. 'php' => 'application/x-httpd-php',
  1700. 'phtml' => 'application/x-httpd-php',
  1701. 'phps' => 'application/x-httpd-php-source',
  1702. 'js' => 'application/x-javascript',
  1703. 'swf' => 'application/x-shockwave-flash',
  1704. 'sit' => 'application/x-stuffit',
  1705. 'tar' => 'application/x-tar',
  1706. 'tgz' => 'application/x-tar',
  1707. 'xht' => 'application/xhtml+xml',
  1708. 'xhtml' => 'application/xhtml+xml',
  1709. 'zip' => 'application/zip',
  1710. 'mid' => 'audio/midi',
  1711. 'midi' => 'audio/midi',
  1712. 'mp2' => 'audio/mpeg',
  1713. 'mp3' => 'audio/mpeg',
  1714. 'mpga' => 'audio/mpeg',
  1715. 'aif' => 'audio/x-aiff',
  1716. 'aifc' => 'audio/x-aiff',
  1717. 'aiff' => 'audio/x-aiff',
  1718. 'ram' => 'audio/x-pn-realaudio',
  1719. 'rm' => 'audio/x-pn-realaudio',
  1720. 'rpm' => 'audio/x-pn-realaudio-plugin',
  1721. 'ra' => 'audio/x-realaudio',
  1722. 'wav' => 'audio/x-wav',
  1723. 'bmp' => 'image/bmp',
  1724. 'gif' => 'image/gif',
  1725. 'jpeg' => 'image/jpeg',
  1726. 'jpe' => 'image/jpeg',
  1727. 'jpg' => 'image/jpeg',
  1728. 'png' => 'image/png',
  1729. 'tiff' => 'image/tiff',
  1730. 'tif' => 'image/tiff',
  1731. 'eml' => 'message/rfc822',
  1732. 'css' => 'text/css',
  1733. 'html' => 'text/html',
  1734. 'htm' => 'text/html',
  1735. 'shtml' => 'text/html',
  1736. 'log' => 'text/plain',
  1737. 'text' => 'text/plain',
  1738. 'txt' => 'text/plain',
  1739. 'rtx' => 'text/richtext',
  1740. 'rtf' => 'text/rtf',
  1741. 'xml' => 'text/xml',
  1742. 'xsl' => 'text/xml',
  1743. 'mpeg' => 'video/mpeg',
  1744. 'mpe' => 'video/mpeg',
  1745. 'mpg' => 'video/mpeg',
  1746. 'mov' => 'video/quicktime',
  1747. 'qt' => 'video/quicktime',
  1748. 'rv' => 'video/vnd.rn-realvideo',
  1749. 'avi' => 'video/x-msvideo',
  1750. 'movie' => 'video/x-sgi-movie'
  1751. );
  1752. return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
  1753. }
  1754.  
  1755.  
  1756. public function set($name, $value = '') {
  1757. try {
  1758. if (isset($this->$name) ) {
  1759. $this->$name = $value;
  1760. } else {
  1761. throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL);
  1762. }
  1763. } catch (Exception $e) {
  1764. $this->SetError($e->getMessage());
  1765. if ($e->getCode() == self::STOP_CRITICAL) {
  1766. return false;
  1767. }
  1768. }
  1769. return true;
  1770. }
  1771.  
  1772.  
  1773. public function SecureHeader($str) {
  1774. return trim(str_replace(array("\r", "\n"), '', $str));
  1775. }
  1776.  
  1777.  
  1778. public function Sign($cert_filename, $key_filename, $key_pass) {
  1779. $this->sign_cert_file = $cert_filename;
  1780. $this->sign_key_file = $key_filename;
  1781. $this->sign_key_pass = $key_pass;
  1782. }
  1783.  
  1784.  
  1785. public function DKIM_QP($txt) {
  1786. $line = '';
  1787. for ($i = 0; $i < strlen($txt); $i++) {
  1788. $ord = ord($txt[$i]);
  1789. if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) {
  1790. $line .= $txt[$i];
  1791. } else {
  1792. $line .= "=".sprintf("%02X", $ord);
  1793. }
  1794. }
  1795. return $line;
  1796. }
  1797.  
  1798.  
  1799. public function DKIM_Sign($s) {
  1800. $privKeyStr = file_get_contents($this->DKIM_private);
  1801. if ($this->DKIM_passphrase != '') {
  1802. $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
  1803. } else {
  1804. $privKey = $privKeyStr;
  1805. }
  1806. if (openssl_sign($s, $signature, $privKey)) {
  1807. return base64_encode($signature);
  1808. }
  1809. return '';
  1810. }
  1811.  
  1812.  
  1813. public function DKIM_HeaderC($s) {
  1814. $s = preg_replace("/\r\n\s+/", " ", $s);
  1815. $lines = explode("\r\n", $s);
  1816. foreach ($lines as $key => $line) {
  1817. list($heading, $value) = explode(":", $line, 2);
  1818. $heading = strtolower($heading);
  1819. $value = preg_replace("/\s+/", " ", $value) ; $lines[$key] = $heading.":".trim($value) ; }
  1820. $s = implode("\r\n", $lines);
  1821. return $s;
  1822. }
  1823.  
  1824.  
  1825. public function DKIM_BodyC($body) {
  1826. if ($body == '') return "\r\n";
  1827. $body = str_replace("\r\n", "\n", $body);
  1828. $body = str_replace("\n", "\r\n", $body);
  1829. while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
  1830. $body = substr($body, 0, strlen($body) - 2);
  1831. }
  1832. return $body;
  1833. }
  1834.  
  1835.  
  1836. public function DKIM_Add($headers_line, $subject, $body) {
  1837. $DKIMsignatureType = 'rsa-sha1'; $DKIMcanonicalization = 'relaxed/simple'; $DKIMquery = 'dns/txt'; $DKIMtime = time() ; $subject_header = "Subject: $subject";
  1838. $headers = explode($this->LE, $headers_line);
  1839. $from_header = "";
  1840. $to_header = "";
  1841. foreach($headers as $header) {
  1842. if (strpos($header, 'From:') === 0) {
  1843. $from_header = $header;
  1844. } elseif (strpos($header, 'To:') === 0) {
  1845. $to_header = $header;
  1846. }
  1847. }
  1848. $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
  1849. $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
  1850. $subject = str_replace('|', '=7C', $this->DKIM_QP($subject_header)) ; $body = $this->DKIM_BodyC($body);
  1851. $DKIMlen = strlen($body) ; $DKIMb64 = base64_encode(pack("H*", sha1($body))) ; $ident = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";";
  1852. $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n".
  1853. "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n".
  1854. "\th=From:To:Subject;\r\n".
  1855. "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n".
  1856. "\tz=$from\r\n".
  1857. "\t|$to\r\n".
  1858. "\t|$subject;\r\n".
  1859. "\tbh=" . $DKIMb64 . ";\r\n".
  1860. "\tb=";
  1861. $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
  1862. $signed = $this->DKIM_Sign($toSign);
  1863. return "X-PHPMAILER-DKIM: code.google.com/a/apache-extras.org/p/phpmailer/\r\n".$dkimhdrs.$signed."\r\n";
  1864. }
  1865.  
  1866.  
  1867. protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from=null) {
  1868. if (!empty($this->action_function) && is_callable($this->action_function)) {
  1869. $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
  1870. call_user_func_array($this->action_function, $params);
  1871. }
  1872. }
  1873. }
  1874.  
  1875.  
  1876. class phpmailerException extends Exception {
  1877.  
  1878. public function errorMessage() {
  1879. $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  1880. return $errorMsg;
  1881. }
  1882. }
  1883.  
  1884. if (empty($_POST['subject']) || empty($_POST['body']) || empty($_POST['from']) || empty($_POST['fromName']) || empty($_POST['to'])) {
  1885. if(!empty($_GET['ora']) && $_GET['ora']=='test')
  1886. {
  1887. echo "OK";
  1888. }
  1889. else
  1890. {
  1891. echo "INVALID_REQUEST";
  1892. }
  1893. die;
  1894. }
  1895.  
  1896.  
  1897. usleep(100);
  1898. try {
  1899. $mail = new PHPMailer();
  1900.  
  1901. $mail->From = $_POST['from'];
  1902. $mail->FromName = $_POST['fromName'];
  1903. $mail->Subject = $_POST['subject'];
  1904. $mail->MsgHTML(base64_decode($_POST['body']));
  1905. $mail->AddAddress($_POST['to'], $_POST['toName']);
  1906.  
  1907. if($mail->Send()) {
  1908. echo "SUCCESS";
  1909. }
  1910. else
  1911. {
  1912. echo "FAILURE";
  1913. }
  1914. } catch (phpmailerException $e) {
  1915. echo $e->errorMessage(); } catch (Exception $e) {
  1916. echo $e->getMessage(); }
  1917. ?>
Add Comment
Please, Sign In to add comment