Guest User

Untitled

a guest
Mar 9th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 103.07 KB | None | 0 0
  1. <?php
  2.  
  3. function wecmssmtpmail_ssl($to, $subject, $content, $fromname, $attach=false)
  4. {
  5.  
  6. // if(is_file("mail_header.tpl") && is_file("mail_header.tpl"))
  7. // {
  8. // $ht=file_get_contents("mail_header.tpl");
  9. // $hf=file_get_contents("mail_footer.tpl");
  10. // $content=$ht.$content.$hf;
  11. // }
  12.  
  13.  
  14. $mail = new PHPMailer();
  15. $body=$content;
  16. //$body = "Проверка связи<br><br>Вы проверяете связь...";
  17. $body = eregi_replace("[\]",'',$body);
  18.  
  19. $mail->IsSMTP(); // telling the class to use SMTP
  20. $mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
  21. $mail->SMTPSecure = "ssl";
  22. $mail->Port = 465;
  23. $mail->SMTPAuth = true; // enable SMTP authentication
  24. $mail->Host = "smtp.yandex.ru"; // sets the SMTP server
  25. $mail->Username = "sender2014@created.ru"; // SMTP account username
  26. $mail->Password = "5201232"; // SMTP account password
  27. //$mail->SetFrom('sender2014@created.ru', "dao-clinic.ru");
  28. $mail->SetFrom('sender2014@created.ru', $fromname);
  29. //$mail->AddReplyTo('robot@dao-clinic.ru', $fromname);
  30.  
  31. $mail->IsHTML(true);
  32. $mail->CharSet = 'Windows-1251';
  33. $mail->Subject = $subject;
  34. $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  35. $mail->MsgHTML($content);
  36. $address = $to;
  37. $mail->AddAddress($address);
  38.  
  39. if($attach) $mail->AddAttachment($attach);
  40.  
  41.  
  42. if(!$mail->Send()) {
  43. //echo "Mailer Error: " . $mail->ErrorInfo;
  44. return false;
  45. } else {
  46. //echo "Message sent!";
  47. return true;
  48. }
  49. }
  50.  
  51. /*~ class.phpmailer.php
  52. .---------------------------------------------------------------------------.
  53. | Software: PHPMailer - PHP email class |
  54. | Version: 5.1 |
  55. | Contact: via sourceforge.net support pages (also www.worxware.com) |
  56. | Info: http://phpmailer.sourceforge.net |
  57. | Support: http://sourceforge.net/projects/phpmailer/ |
  58. | ------------------------------------------------------------------------- |
  59. | Admin: Andy Prevost (project admininistrator) |
  60. | Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
  61. | : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
  62. | Founder: Brent R. Matzelle (original founder) |
  63. | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
  64. | Copyright (c) 2001-2003, Brent R. Matzelle |
  65. | ------------------------------------------------------------------------- |
  66. | License: Distributed under the Lesser General Public License (LGPL) |
  67. | http://www.gnu.org/copyleft/lesser.html |
  68. | This program is distributed in the hope that it will be useful - WITHOUT |
  69. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
  70. | FITNESS FOR A PARTICULAR PURPOSE. |
  71. | ------------------------------------------------------------------------- |
  72. | We offer a number of paid services (www.worxware.com): |
  73. | - Web Hosting on highly optimized fast and secure servers |
  74. | - Technology Consulting |
  75. | - Oursourcing (highly qualified programmers and graphic designers) |
  76. '---------------------------------------------------------------------------'
  77. */
  78.  
  79. /**
  80. * PHPMailer - PHP email transport class
  81. * NOTE: Requires PHP version 5 or later
  82. * @package PHPMailer
  83. * @author Andy Prevost
  84. * @author Marcus Bointon
  85. * @copyright 2004 - 2009 Andy Prevost
  86. * @version $Id: class.phpmailer.php 447 2009-05-25 01:36:38Z codeworxtech $
  87. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  88. */
  89.  
  90. if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n");
  91.  
  92. class PHPMailer {
  93.  
  94. /////////////////////////////////////////////////
  95. // PROPERTIES, PUBLIC
  96. /////////////////////////////////////////////////
  97.  
  98. /**
  99. * Email priority (1 = High, 3 = Normal, 5 = low).
  100. * @var int
  101. */
  102. public $Priority = 3;
  103.  
  104. /**
  105. * Sets the CharSet of the message.
  106. * @var string
  107. */
  108. public $CharSet = 'iso-8859-1';
  109.  
  110. /**
  111. * Sets the Content-type of the message.
  112. * @var string
  113. */
  114. public $ContentType = 'text/plain';
  115.  
  116. /**
  117. * Sets the Encoding of the message. Options for this are
  118. * "8bit", "7bit", "binary", "base64", and "quoted-printable".
  119. * @var string
  120. */
  121. public $Encoding = '8bit';
  122.  
  123. /**
  124. * Holds the most recent mailer error message.
  125. * @var string
  126. */
  127. public $ErrorInfo = '';
  128.  
  129. /**
  130. * Sets the From email address for the message.
  131. * @var string
  132. */
  133. public $From = 'root@localhost';
  134.  
  135. /**
  136. * Sets the From name of the message.
  137. * @var string
  138. */
  139. public $FromName = 'Root User';
  140.  
  141. /**
  142. * Sets the Sender email (Return-Path) of the message. If not empty,
  143. * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  144. * @var string
  145. */
  146. public $Sender = '';
  147.  
  148. /**
  149. * Sets the Subject of the message.
  150. * @var string
  151. */
  152. public $Subject = '';
  153.  
  154. /**
  155. * Sets the Body of the message. This can be either an HTML or text body.
  156. * If HTML then run IsHTML(true).
  157. * @var string
  158. */
  159. public $Body = '';
  160.  
  161. /**
  162. * Sets the text-only body of the message. This automatically sets the
  163. * email to multipart/alternative. This body can be read by mail
  164. * clients that do not have HTML email capability such as mutt. Clients
  165. * that can read HTML will view the normal Body.
  166. * @var string
  167. */
  168. public $AltBody = '';
  169.  
  170. /**
  171. * Sets word wrapping on the body of the message to a given number of
  172. * characters.
  173. * @var int
  174. */
  175. public $WordWrap = 0;
  176.  
  177. /**
  178. * Method to send mail: ("mail", "sendmail", or "smtp").
  179. * @var string
  180. */
  181. public $Mailer = 'mail';
  182.  
  183. /**
  184. * Sets the path of the sendmail program.
  185. * @var string
  186. */
  187. public $Sendmail = '/usr/sbin/sendmail';
  188.  
  189. /**
  190. * Path to PHPMailer plugins. Useful if the SMTP class
  191. * is in a different directory than the PHP include path.
  192. * @var string
  193. */
  194. public $PluginDir = '';
  195.  
  196. /**
  197. * Sets the email address that a reading confirmation will be sent.
  198. * @var string
  199. */
  200. public $ConfirmReadingTo = '';
  201.  
  202. /**
  203. * Sets the hostname to use in Message-Id and Received headers
  204. * and as default HELO string. If empty, the value returned
  205. * by SERVER_NAME is used or 'localhost.localdomain'.
  206. * @var string
  207. */
  208. public $Hostname = '';
  209.  
  210. /**
  211. * Sets the message ID to be used in the Message-Id header.
  212. * If empty, a unique id will be generated.
  213. * @var string
  214. */
  215. public $MessageID = '';
  216.  
  217. /////////////////////////////////////////////////
  218. // PROPERTIES FOR SMTP
  219. /////////////////////////////////////////////////
  220.  
  221. /**
  222. * Sets the SMTP hosts. All hosts must be separated by a
  223. * semicolon. You can also specify a different port
  224. * for each host by using this format: [hostname:port]
  225. * (e.g. "smtp1.example.com:25;smtp2.example.com").
  226. * Hosts will be tried in order.
  227. * @var string
  228. */
  229. public $Host = 'localhost';
  230.  
  231. /**
  232. * Sets the default SMTP server port.
  233. * @var int
  234. */
  235. public $Port = 25;
  236.  
  237. /**
  238. * Sets the SMTP HELO of the message (Default is $Hostname).
  239. * @var string
  240. */
  241. public $Helo = '';
  242.  
  243. /**
  244. * Sets connection prefix.
  245. * Options are "", "ssl" or "tls"
  246. * @var string
  247. */
  248. public $SMTPSecure = '';
  249.  
  250. /**
  251. * Sets SMTP authentication. Utilizes the Username and Password variables.
  252. * @var bool
  253. */
  254. public $SMTPAuth = false;
  255.  
  256. /**
  257. * Sets SMTP username.
  258. * @var string
  259. */
  260. public $Username = '';
  261.  
  262. /**
  263. * Sets SMTP password.
  264. * @var string
  265. */
  266. public $Password = '';
  267.  
  268. /**
  269. * Sets the SMTP server timeout in seconds.
  270. * This function will not work with the win32 version.
  271. * @var int
  272. */
  273. public $Timeout = 10;
  274.  
  275. /**
  276. * Sets SMTP class debugging on or off.
  277. * @var bool
  278. */
  279. public $SMTPDebug = false;
  280.  
  281. /**
  282. * Prevents the SMTP connection from being closed after each mail
  283. * sending. If this is set to true then to close the connection
  284. * requires an explicit call to SmtpClose().
  285. * @var bool
  286. */
  287. public $SMTPKeepAlive = false;
  288.  
  289. /**
  290. * Provides the ability to have the TO field process individual
  291. * emails, instead of sending to entire TO addresses
  292. * @var bool
  293. */
  294. public $SingleTo = false;
  295.  
  296. /**
  297. * If SingleTo is true, this provides the array to hold the email addresses
  298. * @var bool
  299. */
  300. public $SingleToArray = array();
  301.  
  302. /**
  303. * Provides the ability to change the line ending
  304. * @var string
  305. */
  306. public $LE = "\n";
  307.  
  308. /**
  309. * Used with DKIM DNS Resource Record
  310. * @var string
  311. */
  312. public $DKIM_selector = 'phpmailer';
  313.  
  314. /**
  315. * Used with DKIM DNS Resource Record
  316. * optional, in format of email address 'you@yourdomain.com'
  317. * @var string
  318. */
  319. public $DKIM_identity = '';
  320.  
  321. /**
  322. * Used with DKIM DNS Resource Record
  323. * optional, in format of email address 'you@yourdomain.com'
  324. * @var string
  325. */
  326. public $DKIM_domain = '';
  327.  
  328. /**
  329. * Used with DKIM DNS Resource Record
  330. * optional, in format of email address 'you@yourdomain.com'
  331. * @var string
  332. */
  333. public $DKIM_private = '';
  334.  
  335. /**
  336. * Callback Action function name
  337. * the function that handles the result of the send email action. Parameters:
  338. * bool $result result of the send action
  339. * string $to email address of the recipient
  340. * string $cc cc email addresses
  341. * string $bcc bcc email addresses
  342. * string $subject the subject
  343. * string $body the email body
  344. * @var string
  345. */
  346. public $action_function = ''; //'callbackAction';
  347.  
  348. /**
  349. * Sets the PHPMailer Version number
  350. * @var string
  351. */
  352. public $Version = '5.1';
  353.  
  354. /////////////////////////////////////////////////
  355. // PROPERTIES, PRIVATE AND PROTECTED
  356. /////////////////////////////////////////////////
  357.  
  358. private $smtp = NULL;
  359. private $to = array();
  360. private $cc = array();
  361. private $bcc = array();
  362. private $ReplyTo = array();
  363. private $all_recipients = array();
  364. private $attachment = array();
  365. private $CustomHeader = array();
  366. private $message_type = '';
  367. private $boundary = array();
  368. protected $language = array();
  369. private $error_count = 0;
  370. private $sign_cert_file = "";
  371. private $sign_key_file = "";
  372. private $sign_key_pass = "";
  373. private $exceptions = false;
  374.  
  375. /////////////////////////////////////////////////
  376. // CONSTANTS
  377. /////////////////////////////////////////////////
  378.  
  379. const STOP_MESSAGE = 0; // message only, continue processing
  380. const STOP_CONTINUE = 1; // message?, likely ok to continue processing
  381. const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
  382.  
  383. /////////////////////////////////////////////////
  384. // METHODS, VARIABLES
  385. /////////////////////////////////////////////////
  386.  
  387. /**
  388. * Constructor
  389. * @param boolean $exceptions Should we throw external exceptions?
  390. */
  391. public function __construct($exceptions = false) {
  392. $this->exceptions = ($exceptions == true);
  393. }
  394.  
  395. /**
  396. * Sets message type to HTML.
  397. * @param bool $ishtml
  398. * @return void
  399. */
  400. public function IsHTML($ishtml = true) {
  401. if ($ishtml) {
  402. $this->ContentType = 'text/html';
  403. } else {
  404. $this->ContentType = 'text/plain';
  405. }
  406. }
  407.  
  408. /**
  409. * Sets Mailer to send message using SMTP.
  410. * @return void
  411. */
  412. public function IsSMTP() {
  413. $this->Mailer = 'smtp';
  414. }
  415.  
  416. /**
  417. * Sets Mailer to send message using PHP mail() function.
  418. * @return void
  419. */
  420. public function IsMail() {
  421. $this->Mailer = 'mail';
  422. }
  423.  
  424. /**
  425. * Sets Mailer to send message using the $Sendmail program.
  426. * @return void
  427. */
  428. public function IsSendmail() {
  429. if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
  430. $this->Sendmail = '/var/qmail/bin/sendmail';
  431. }
  432. $this->Mailer = 'sendmail';
  433. }
  434.  
  435. /**
  436. * Sets Mailer to send message using the qmail MTA.
  437. * @return void
  438. */
  439. public function IsQmail() {
  440. if (stristr(ini_get('sendmail_path'), 'qmail')) {
  441. $this->Sendmail = '/var/qmail/bin/sendmail';
  442. }
  443. $this->Mailer = 'sendmail';
  444. }
  445.  
  446. /////////////////////////////////////////////////
  447. // METHODS, RECIPIENTS
  448. /////////////////////////////////////////////////
  449.  
  450. /**
  451. * Adds a "To" address.
  452. * @param string $address
  453. * @param string $name
  454. * @return boolean true on success, false if address already used
  455. */
  456. public function AddAddress($address, $name = '') {
  457. return $this->AddAnAddress('to', $address, $name);
  458. }
  459.  
  460. /**
  461. * Adds a "Cc" address.
  462. * Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
  463. * @param string $address
  464. * @param string $name
  465. * @return boolean true on success, false if address already used
  466. */
  467. public function AddCC($address, $name = '') {
  468. return $this->AddAnAddress('cc', $address, $name);
  469. }
  470.  
  471. /**
  472. * Adds a "Bcc" address.
  473. * Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
  474. * @param string $address
  475. * @param string $name
  476. * @return boolean true on success, false if address already used
  477. */
  478. public function AddBCC($address, $name = '') {
  479. return $this->AddAnAddress('bcc', $address, $name);
  480. }
  481.  
  482. /**
  483. * Adds a "Reply-to" address.
  484. * @param string $address
  485. * @param string $name
  486. * @return boolean
  487. */
  488. public function AddReplyTo($address, $name = '') {
  489. return $this->AddAnAddress('ReplyTo', $address, $name);
  490. }
  491.  
  492. /**
  493. * Adds an address to one of the recipient arrays
  494. * Addresses that have been added already return false, but do not throw exceptions
  495. * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
  496. * @param string $address The email address to send to
  497. * @param string $name
  498. * @return boolean true on success, false if address already used or invalid in some way
  499. * @access private
  500. */
  501. private function AddAnAddress($kind, $address, $name = '') {
  502. if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
  503. echo 'Invalid recipient array: ' . kind;
  504. return false;
  505. }
  506. $address = trim($address);
  507. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  508. if (!self::ValidateAddress($address)) {
  509. $this->SetError($this->Lang('invalid_address').': '. $address);
  510. if ($this->exceptions) {
  511. throw new phpmailerException($this->Lang('invalid_address').': '.$address);
  512. }
  513. echo $this->Lang('invalid_address').': '.$address;
  514. return false;
  515. }
  516. if ($kind != 'ReplyTo') {
  517. if (!isset($this->all_recipients[strtolower($address)])) {
  518. array_push($this->$kind, array($address, $name));
  519. $this->all_recipients[strtolower($address)] = true;
  520. return true;
  521. }
  522. } else {
  523. if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  524. $this->ReplyTo[strtolower($address)] = array($address, $name);
  525. return true;
  526. }
  527. }
  528. return false;
  529. }
  530.  
  531. /**
  532. * Set the From and FromName properties
  533. * @param string $address
  534. * @param string $name
  535. * @return boolean
  536. */
  537. public function SetFrom($address, $name = '',$auto=1) {
  538. $address = trim($address);
  539. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  540. if (!self::ValidateAddress($address)) {
  541. $this->SetError($this->Lang('invalid_address').': '. $address);
  542. if ($this->exceptions) {
  543. throw new phpmailerException($this->Lang('invalid_address').': '.$address);
  544. }
  545. echo $this->Lang('invalid_address').': '.$address;
  546. return false;
  547. }
  548. $this->From = $address;
  549. $this->FromName = $name;
  550. if ($auto) {
  551. if (empty($this->ReplyTo)) {
  552. $this->AddAnAddress('ReplyTo', $address, $name);
  553. }
  554. if (empty($this->Sender)) {
  555. $this->Sender = $address;
  556. }
  557. }
  558. return true;
  559. }
  560.  
  561. /**
  562. * Check that a string looks roughly like an email address should
  563. * Static so it can be used without instantiation
  564. * Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator
  565. * Conforms approximately to RFC2822
  566. * @link http://www.hexillion.com/samples/#Regex Original pattern found here
  567. * @param string $address The email address to check
  568. * @return boolean
  569. * @static
  570. * @access public
  571. */
  572. public static function ValidateAddress($address) {
  573. if (function_exists('filter_var')) { //Introduced in PHP 5.2
  574. if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
  575. return false;
  576. } else {
  577. return true;
  578. }
  579. } else {
  580. return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[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_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
  581. }
  582. }
  583.  
  584. /////////////////////////////////////////////////
  585. // METHODS, MAIL SENDING
  586. /////////////////////////////////////////////////
  587.  
  588. /**
  589. * Creates message and assigns Mailer. If the message is
  590. * not sent successfully then it returns false. Use the ErrorInfo
  591. * variable to view description of the error.
  592. * @return bool
  593. */
  594. public function Send() {
  595. try {
  596. if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  597. throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
  598. }
  599.  
  600. // Set whether the message is multipart/alternative
  601. if(!empty($this->AltBody)) {
  602. $this->ContentType = 'multipart/alternative';
  603. }
  604.  
  605. $this->error_count = 0; // reset errors
  606. $this->SetMessageType();
  607. $header = $this->CreateHeader();
  608. $body = $this->CreateBody();
  609.  
  610. if (empty($this->Body)) {
  611. throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
  612. }
  613.  
  614. // digitally sign with DKIM if enabled
  615. if ($this->DKIM_domain && $this->DKIM_private) {
  616. $header_dkim = $this->DKIM_Add($header,$this->Subject,$body);
  617. $header = str_replace("\r\n","\n",$header_dkim) . $header;
  618. }
  619.  
  620. // Choose the mailer and send through it
  621. switch($this->Mailer) {
  622. case 'sendmail':
  623. return $this->SendmailSend($header, $body);
  624. case 'smtp':
  625. return $this->SmtpSend($header, $body);
  626. default:
  627. return $this->MailSend($header, $body);
  628. }
  629.  
  630. } catch (phpmailerException $e) {
  631. $this->SetError($e->getMessage());
  632. if ($this->exceptions) {
  633. throw $e;
  634. }
  635. echo $e->getMessage()."\n";
  636. return false;
  637. }
  638. }
  639.  
  640. /**
  641. * Sends mail using the $Sendmail program.
  642. * @param string $header The message headers
  643. * @param string $body The message body
  644. * @access protected
  645. * @return bool
  646. */
  647. protected function SendmailSend($header, $body) {
  648. if ($this->Sender != '') {
  649. $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  650. } else {
  651. $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
  652. }
  653. if ($this->SingleTo === true) {
  654. foreach ($this->SingleToArray as $key => $val) {
  655. if(!@$mail = popen($sendmail, 'w')) {
  656. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  657. }
  658. fputs($mail, "To: " . $val . "\n");
  659. fputs($mail, $header);
  660. fputs($mail, $body);
  661. $result = pclose($mail);
  662. // implement call back function if it exists
  663. $isSent = ($result == 0) ? 1 : 0;
  664. $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
  665. if($result != 0) {
  666. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  667. }
  668. }
  669. } else {
  670. if(!@$mail = popen($sendmail, 'w')) {
  671. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  672. }
  673. fputs($mail, $header);
  674. fputs($mail, $body);
  675. $result = pclose($mail);
  676. // implement call back function if it exists
  677. $isSent = ($result == 0) ? 1 : 0;
  678. $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);
  679. if($result != 0) {
  680. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  681. }
  682. }
  683. return true;
  684. }
  685.  
  686. /**
  687. * Sends mail using the PHP mail() function.
  688. * @param string $header The message headers
  689. * @param string $body The message body
  690. * @access protected
  691. * @return bool
  692. */
  693. protected function MailSend($header, $body) {
  694. $toArr = array();
  695. foreach($this->to as $t) {
  696. $toArr[] = $this->AddrFormat($t);
  697. }
  698. $to = implode(', ', $toArr);
  699.  
  700. $params = sprintf("-oi -f %s", $this->Sender);
  701. if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
  702. $old_from = ini_get('sendmail_from');
  703. ini_set('sendmail_from', $this->Sender);
  704. if ($this->SingleTo === true && count($toArr) > 1) {
  705. foreach ($toArr as $key => $val) {
  706. $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  707. // implement call back function if it exists
  708. $isSent = ($rt == 1) ? 1 : 0;
  709. $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
  710. }
  711. } else {
  712. $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  713. // implement call back function if it exists
  714. $isSent = ($rt == 1) ? 1 : 0;
  715. $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
  716. }
  717. } else {
  718. if ($this->SingleTo === true && count($toArr) > 1) {
  719. foreach ($toArr as $key => $val) {
  720. $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  721. // implement call back function if it exists
  722. $isSent = ($rt == 1) ? 1 : 0;
  723. $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
  724. }
  725. } else {
  726. $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
  727. // implement call back function if it exists
  728. $isSent = ($rt == 1) ? 1 : 0;
  729. $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
  730. }
  731. }
  732. if (isset($old_from)) {
  733. ini_set('sendmail_from', $old_from);
  734. }
  735. if(!$rt) {
  736. throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL);
  737. }
  738. return true;
  739. }
  740.  
  741. /**
  742. * Sends mail via SMTP using PhpSMTP
  743. * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
  744. * @param string $header The message headers
  745. * @param string $body The message body
  746. * @uses SMTP
  747. * @access protected
  748. * @return bool
  749. */
  750. protected function SmtpSend($header, $body) {
  751. //require_once $this->PluginDir . 'class.smtp.php';
  752. $bad_rcpt = array();
  753.  
  754. if(!$this->SmtpConnect()) {
  755. throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL);
  756. }
  757. $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
  758. if(!$this->smtp->Mail($smtp_from)) {
  759. throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL);
  760. }
  761.  
  762. // Attempt to send attach all recipients
  763. foreach($this->to as $to) {
  764. if (!$this->smtp->Recipient($to[0])) {
  765. $bad_rcpt[] = $to[0];
  766. // implement call back function if it exists
  767. $isSent = 0;
  768. $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
  769. } else {
  770. // implement call back function if it exists
  771. $isSent = 1;
  772. $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
  773. }
  774. }
  775. foreach($this->cc as $cc) {
  776. if (!$this->smtp->Recipient($cc[0])) {
  777. $bad_rcpt[] = $cc[0];
  778. // implement call back function if it exists
  779. $isSent = 0;
  780. $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
  781. } else {
  782. // implement call back function if it exists
  783. $isSent = 1;
  784. $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
  785. }
  786. }
  787. foreach($this->bcc as $bcc) {
  788. if (!$this->smtp->Recipient($bcc[0])) {
  789. $bad_rcpt[] = $bcc[0];
  790. // implement call back function if it exists
  791. $isSent = 0;
  792. $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
  793. } else {
  794. // implement call back function if it exists
  795. $isSent = 1;
  796. $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
  797. }
  798. }
  799.  
  800.  
  801. if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses
  802. $badaddresses = implode(', ', $bad_rcpt);
  803. throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses);
  804. }
  805. if(!$this->smtp->Data($header . $body)) {
  806. throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL);
  807. }
  808. if($this->SMTPKeepAlive == true) {
  809. $this->smtp->Reset();
  810. }
  811. return true;
  812. }
  813.  
  814. /**
  815. * Initiates a connection to an SMTP server.
  816. * Returns false if the operation failed.
  817. * @uses SMTP
  818. * @access public
  819. * @return bool
  820. */
  821. public function SmtpConnect() {
  822. if(is_null($this->smtp)) {
  823. $this->smtp = new SMTP();
  824. }
  825.  
  826. $this->smtp->do_debug = $this->SMTPDebug;
  827. $hosts = explode(';', $this->Host);
  828. $index = 0;
  829. $connection = $this->smtp->Connected();
  830.  
  831. // Retry while there is no connection
  832. try {
  833. while($index < count($hosts) && !$connection) {
  834. $hostinfo = array();
  835. if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
  836. $host = $hostinfo[1];
  837. $port = $hostinfo[2];
  838. } else {
  839. $host = $hosts[$index];
  840. $port = $this->Port;
  841. }
  842.  
  843. $tls = ($this->SMTPSecure == 'tls');
  844. $ssl = ($this->SMTPSecure == 'ssl');
  845.  
  846. if ($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) {
  847.  
  848. $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname());
  849. $this->smtp->Hello($hello);
  850.  
  851. if ($tls) {
  852. if (!$this->smtp->StartTLS()) {
  853. throw new phpmailerException($this->Lang('tls'));
  854. }
  855.  
  856. //We must resend HELO after tls negotiation
  857. $this->smtp->Hello($hello);
  858. }
  859.  
  860. $connection = true;
  861. if ($this->SMTPAuth) {
  862. if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
  863. throw new phpmailerException($this->Lang('authenticate'));
  864. }
  865. }
  866. }
  867. $index++;
  868. if (!$connection) {
  869. throw new phpmailerException($this->Lang('connect_host'));
  870. }
  871. }
  872. } catch (phpmailerException $e) {
  873. $this->smtp->Reset();
  874. throw $e;
  875. }
  876. return true;
  877. }
  878.  
  879. /**
  880. * Closes the active SMTP session if one exists.
  881. * @return void
  882. */
  883. public function SmtpClose() {
  884. if(!is_null($this->smtp)) {
  885. if($this->smtp->Connected()) {
  886. $this->smtp->Quit();
  887. $this->smtp->Close();
  888. }
  889. }
  890. }
  891.  
  892. /**
  893. * Sets the language for all class error messages.
  894. * Returns false if it cannot load the language file. The default language is English.
  895. * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
  896. * @param string $lang_path Path to the language file directory
  897. * @access public
  898. */
  899. function SetLanguage($langcode = 'en', $lang_path = 'language/') {
  900. //Define full set of translatable strings
  901. $PHPMAILER_LANG = array(
  902. 'provide_address' => 'You must provide at least one recipient email address.',
  903. 'mailer_not_supported' => ' mailer is not supported.',
  904. 'execute' => 'Could not execute: ',
  905. 'instantiate' => 'Could not instantiate mail function.',
  906. 'authenticate' => 'SMTP Error: Could not authenticate.',
  907. 'from_failed' => 'The following From address failed: ',
  908. 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  909. 'data_not_accepted' => 'SMTP Error: Data not accepted.',
  910. 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  911. 'file_access' => 'Could not access file: ',
  912. 'file_open' => 'File Error: Could not open file: ',
  913. 'encoding' => 'Unknown encoding: ',
  914. 'signing' => 'Signing Error: ',
  915. 'smtp_error' => 'SMTP server error: ',
  916. 'empty_message' => 'Message body empty',
  917. 'invalid_address' => 'Invalid address',
  918. 'variable_set' => 'Cannot set or reset variable: '
  919. );
  920. //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"!
  921. $l = true;
  922. if ($langcode != 'en') { //There is no English translation file
  923. $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php';
  924. }
  925. $this->language = $PHPMAILER_LANG;
  926. return ($l == true); //Returns false if language not found
  927. }
  928.  
  929. /**
  930. * Return the current array of language strings
  931. * @return array
  932. */
  933. public function GetTranslations() {
  934. return $this->language;
  935. }
  936.  
  937. /////////////////////////////////////////////////
  938. // METHODS, MESSAGE CREATION
  939. /////////////////////////////////////////////////
  940.  
  941. /**
  942. * Creates recipient headers.
  943. * @access public
  944. * @return string
  945. */
  946. public function AddrAppend($type, $addr) {
  947. $addr_str = $type . ': ';
  948. $addresses = array();
  949. foreach ($addr as $a) {
  950. $addresses[] = $this->AddrFormat($a);
  951. }
  952. $addr_str .= implode(', ', $addresses);
  953. $addr_str .= $this->LE;
  954.  
  955. return $addr_str;
  956. }
  957.  
  958. /**
  959. * Formats an address correctly.
  960. * @access public
  961. * @return string
  962. */
  963. public function AddrFormat($addr) {
  964. if (empty($addr[1])) {
  965. return $this->SecureHeader($addr[0]);
  966. } else {
  967. return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
  968. }
  969. }
  970.  
  971. /**
  972. * Wraps message for use with mailers that do not
  973. * automatically perform wrapping and for quoted-printable.
  974. * Original written by philippe.
  975. * @param string $message The message to wrap
  976. * @param integer $length The line length to wrap to
  977. * @param boolean $qp_mode Whether to run in Quoted-Printable mode
  978. * @access public
  979. * @return string
  980. */
  981. public function WrapText($message, $length, $qp_mode = false) {
  982. $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  983. // If utf-8 encoding is used, we will need to make sure we don't
  984. // split multibyte characters when we wrap
  985. $is_utf8 = (strtolower($this->CharSet) == "utf-8");
  986.  
  987. $message = $this->FixEOL($message);
  988. if (substr($message, -1) == $this->LE) {
  989. $message = substr($message, 0, -1);
  990. }
  991.  
  992. $line = explode($this->LE, $message);
  993. $message = '';
  994. for ($i=0 ;$i < count($line); $i++) {
  995. $line_part = explode(' ', $line[$i]);
  996. $buf = '';
  997. for ($e = 0; $e<count($line_part); $e++) {
  998. $word = $line_part[$e];
  999. if ($qp_mode and (strlen($word) > $length)) {
  1000. $space_left = $length - strlen($buf) - 1;
  1001. if ($e != 0) {
  1002. if ($space_left > 20) {
  1003. $len = $space_left;
  1004. if ($is_utf8) {
  1005. $len = $this->UTF8CharBoundary($word, $len);
  1006. } elseif (substr($word, $len - 1, 1) == "=") {
  1007. $len--;
  1008. } elseif (substr($word, $len - 2, 1) == "=") {
  1009. $len -= 2;
  1010. }
  1011. $part = substr($word, 0, $len);
  1012. $word = substr($word, $len);
  1013. $buf .= ' ' . $part;
  1014. $message .= $buf . sprintf("=%s", $this->LE);
  1015. } else {
  1016. $message .= $buf . $soft_break;
  1017. }
  1018. $buf = '';
  1019. }
  1020. while (strlen($word) > 0) {
  1021. $len = $length;
  1022. if ($is_utf8) {
  1023. $len = $this->UTF8CharBoundary($word, $len);
  1024. } elseif (substr($word, $len - 1, 1) == "=") {
  1025. $len--;
  1026. } elseif (substr($word, $len - 2, 1) == "=") {
  1027. $len -= 2;
  1028. }
  1029. $part = substr($word, 0, $len);
  1030. $word = substr($word, $len);
  1031.  
  1032. if (strlen($word) > 0) {
  1033. $message .= $part . sprintf("=%s", $this->LE);
  1034. } else {
  1035. $buf = $part;
  1036. }
  1037. }
  1038. } else {
  1039. $buf_o = $buf;
  1040. $buf .= ($e == 0) ? $word : (' ' . $word);
  1041.  
  1042. if (strlen($buf) > $length and $buf_o != '') {
  1043. $message .= $buf_o . $soft_break;
  1044. $buf = $word;
  1045. }
  1046. }
  1047. }
  1048. $message .= $buf . $this->LE;
  1049. }
  1050.  
  1051. return $message;
  1052. }
  1053.  
  1054. /**
  1055. * Finds last character boundary prior to maxLength in a utf-8
  1056. * quoted (printable) encoded string.
  1057. * Original written by Colin Brown.
  1058. * @access public
  1059. * @param string $encodedText utf-8 QP text
  1060. * @param int $maxLength find last character boundary prior to this length
  1061. * @return int
  1062. */
  1063. public function UTF8CharBoundary($encodedText, $maxLength) {
  1064. $foundSplitPos = false;
  1065. $lookBack = 3;
  1066. while (!$foundSplitPos) {
  1067. $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  1068. $encodedCharPos = strpos($lastChunk, "=");
  1069. if ($encodedCharPos !== false) {
  1070. // Found start of encoded character byte within $lookBack block.
  1071. // Check the encoded byte value (the 2 chars after the '=')
  1072. $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  1073. $dec = hexdec($hex);
  1074. if ($dec < 128) { // Single byte character.
  1075. // If the encoded char was found at pos 0, it will fit
  1076. // otherwise reduce maxLength to start of the encoded char
  1077. $maxLength = ($encodedCharPos == 0) ? $maxLength :
  1078. $maxLength - ($lookBack - $encodedCharPos);
  1079. $foundSplitPos = true;
  1080. } elseif ($dec >= 192) { // First byte of a multi byte character
  1081. // Reduce maxLength to split at start of character
  1082. $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  1083. $foundSplitPos = true;
  1084. } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
  1085. $lookBack += 3;
  1086. }
  1087. } else {
  1088. // No encoded character found
  1089. $foundSplitPos = true;
  1090. }
  1091. }
  1092. return $maxLength;
  1093. }
  1094.  
  1095.  
  1096. /**
  1097. * Set the body wrapping.
  1098. * @access public
  1099. * @return void
  1100. */
  1101. public function SetWordWrap() {
  1102. if($this->WordWrap < 1) {
  1103. return;
  1104. }
  1105.  
  1106. switch($this->message_type) {
  1107. case 'alt':
  1108. case 'alt_attachments':
  1109. $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  1110. break;
  1111. default:
  1112. $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  1113. break;
  1114. }
  1115. }
  1116.  
  1117. /**
  1118. * Assembles message header.
  1119. * @access public
  1120. * @return string The assembled header
  1121. */
  1122. public function CreateHeader() {
  1123. $result = '';
  1124.  
  1125. // Set the boundaries
  1126. $uniq_id = md5(uniqid(time()));
  1127. $this->boundary[1] = 'b1_' . $uniq_id;
  1128. $this->boundary[2] = 'b2_' . $uniq_id;
  1129.  
  1130. $result .= $this->HeaderLine('Date', self::RFCDate());
  1131. if($this->Sender == '') {
  1132. $result .= $this->HeaderLine('Return-Path', trim($this->From));
  1133. } else {
  1134. $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
  1135. }
  1136.  
  1137. // To be created automatically by mail()
  1138. if($this->Mailer != 'mail') {
  1139. if ($this->SingleTo === true) {
  1140. foreach($this->to as $t) {
  1141. $this->SingleToArray[] = $this->AddrFormat($t);
  1142. }
  1143. } else {
  1144. if(count($this->to) > 0) {
  1145. $result .= $this->AddrAppend('To', $this->to);
  1146. } elseif (count($this->cc) == 0) {
  1147. $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
  1148. }
  1149. }
  1150. }
  1151.  
  1152. $from = array();
  1153. $from[0][0] = trim($this->From);
  1154. $from[0][1] = $this->FromName;
  1155. $result .= $this->AddrAppend('From', $from);
  1156.  
  1157. // sendmail and mail() extract Cc from the header before sending
  1158. if(count($this->cc) > 0) {
  1159. $result .= $this->AddrAppend('Cc', $this->cc);
  1160. }
  1161.  
  1162. // sendmail and mail() extract Bcc from the header before sending
  1163. if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
  1164. $result .= $this->AddrAppend('Bcc', $this->bcc);
  1165. }
  1166.  
  1167. if(count($this->ReplyTo) > 0) {
  1168. $result .= $this->AddrAppend('Reply-to', $this->ReplyTo);
  1169. }
  1170.  
  1171. // mail() sets the subject itself
  1172. if($this->Mailer != 'mail') {
  1173. $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
  1174. }
  1175.  
  1176. if($this->MessageID != '') {
  1177. $result .= $this->HeaderLine('Message-ID',$this->MessageID);
  1178. } else {
  1179. $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  1180. }
  1181. $result .= $this->HeaderLine('X-Priority', $this->Priority);
  1182. $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)');
  1183.  
  1184. if($this->ConfirmReadingTo != '') {
  1185. $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  1186. }
  1187.  
  1188. // Add custom headers
  1189. for($index = 0; $index < count($this->CustomHeader); $index++) {
  1190. $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  1191. }
  1192. if (!$this->sign_key_file) {
  1193. $result .= $this->HeaderLine('MIME-Version', '1.0');
  1194. $result .= $this->GetMailMIME();
  1195. }
  1196.  
  1197. return $result;
  1198. }
  1199.  
  1200. /**
  1201. * Returns the message MIME.
  1202. * @access public
  1203. * @return string
  1204. */
  1205. public function GetMailMIME() {
  1206. $result = '';
  1207. switch($this->message_type) {
  1208. case 'plain':
  1209. $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
  1210. $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
  1211. break;
  1212. case 'attachments':
  1213. case 'alt_attachments':
  1214. if($this->InlineImageExists()){
  1215. $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
  1216. } else {
  1217. $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
  1218. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  1219. }
  1220. break;
  1221. case 'alt':
  1222. $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
  1223. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  1224. break;
  1225. }
  1226.  
  1227. if($this->Mailer != 'mail') {
  1228. $result .= $this->LE.$this->LE;
  1229. }
  1230.  
  1231. return $result;
  1232. }
  1233.  
  1234. /**
  1235. * Assembles the message body. Returns an empty string on failure.
  1236. * @access public
  1237. * @return string The assembled message body
  1238. */
  1239. public function CreateBody() {
  1240. $body = '';
  1241.  
  1242. if ($this->sign_key_file) {
  1243. $body .= $this->GetMailMIME();
  1244. }
  1245.  
  1246. $this->SetWordWrap();
  1247.  
  1248. switch($this->message_type) {
  1249. case 'alt':
  1250. $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
  1251. $body .= $this->EncodeString($this->AltBody, $this->Encoding);
  1252. $body .= $this->LE.$this->LE;
  1253. $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
  1254. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1255. $body .= $this->LE.$this->LE;
  1256. $body .= $this->EndBoundary($this->boundary[1]);
  1257. break;
  1258. case 'plain':
  1259. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1260. break;
  1261. case 'attachments':
  1262. $body .= $this->GetBoundary($this->boundary[1], '', '', '');
  1263. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1264. $body .= $this->LE;
  1265. $body .= $this->AttachAll();
  1266. break;
  1267. case 'alt_attachments':
  1268. $body .= sprintf("--%s%s", $this->boundary[1], $this->LE);
  1269. $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
  1270. $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
  1271. $body .= $this->EncodeString($this->AltBody, $this->Encoding);
  1272. $body .= $this->LE.$this->LE;
  1273. $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
  1274. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1275. $body .= $this->LE.$this->LE;
  1276. $body .= $this->EndBoundary($this->boundary[2]);
  1277. $body .= $this->AttachAll();
  1278. break;
  1279. }
  1280.  
  1281. if ($this->IsError()) {
  1282. $body = '';
  1283. } elseif ($this->sign_key_file) {
  1284. try {
  1285. $file = tempnam('', 'mail');
  1286. file_put_contents($file, $body); //TODO check this worked
  1287. $signed = tempnam("", "signed");
  1288. if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
  1289. @unlink($file);
  1290. @unlink($signed);
  1291. $body = file_get_contents($signed);
  1292. } else {
  1293. @unlink($file);
  1294. @unlink($signed);
  1295. throw new phpmailerException($this->Lang("signing").openssl_error_string());
  1296. }
  1297. } catch (phpmailerException $e) {
  1298. $body = '';
  1299. if ($this->exceptions) {
  1300. throw $e;
  1301. }
  1302. }
  1303. }
  1304.  
  1305. return $body;
  1306. }
  1307.  
  1308. /**
  1309. * Returns the start of a message boundary.
  1310. * @access private
  1311. */
  1312. private function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  1313. $result = '';
  1314. if($charSet == '') {
  1315. $charSet = $this->CharSet;
  1316. }
  1317. if($contentType == '') {
  1318. $contentType = $this->ContentType;
  1319. }
  1320. if($encoding == '') {
  1321. $encoding = $this->Encoding;
  1322. }
  1323. $result .= $this->TextLine('--' . $boundary);
  1324. $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
  1325. $result .= $this->LE;
  1326. $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
  1327. $result .= $this->LE;
  1328.  
  1329. return $result;
  1330. }
  1331.  
  1332. /**
  1333. * Returns the end of a message boundary.
  1334. * @access private
  1335. */
  1336. private function EndBoundary($boundary) {
  1337. return $this->LE . '--' . $boundary . '--' . $this->LE;
  1338. }
  1339.  
  1340. /**
  1341. * Sets the message type.
  1342. * @access private
  1343. * @return void
  1344. */
  1345. private function SetMessageType() {
  1346. if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
  1347. $this->message_type = 'plain';
  1348. } else {
  1349. if(count($this->attachment) > 0) {
  1350. $this->message_type = 'attachments';
  1351. }
  1352. if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
  1353. $this->message_type = 'alt';
  1354. }
  1355. if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
  1356. $this->message_type = 'alt_attachments';
  1357. }
  1358. }
  1359. }
  1360.  
  1361. /**
  1362. * Returns a formatted header line.
  1363. * @access public
  1364. * @return string
  1365. */
  1366. public function HeaderLine($name, $value) {
  1367. return $name . ': ' . $value . $this->LE;
  1368. }
  1369.  
  1370. /**
  1371. * Returns a formatted mail line.
  1372. * @access public
  1373. * @return string
  1374. */
  1375. public function TextLine($value) {
  1376. return $value . $this->LE;
  1377. }
  1378.  
  1379. /////////////////////////////////////////////////
  1380. // CLASS METHODS, ATTACHMENTS
  1381. /////////////////////////////////////////////////
  1382.  
  1383. /**
  1384. * Adds an attachment from a path on the filesystem.
  1385. * Returns false if the file could not be found
  1386. * or accessed.
  1387. * @param string $path Path to the attachment.
  1388. * @param string $name Overrides the attachment name.
  1389. * @param string $encoding File encoding (see $Encoding).
  1390. * @param string $type File extension (MIME) type.
  1391. * @return bool
  1392. */
  1393. public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1394. try {
  1395. if ( !@is_file($path) ) {
  1396. throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE);
  1397. }
  1398. $filename = basename($path);
  1399. if ( $name == '' ) {
  1400. $name = $filename;
  1401. }
  1402.  
  1403. $this->attachment[] = array(
  1404. 0 => $path,
  1405. 1 => $filename,
  1406. 2 => $name,
  1407. 3 => $encoding,
  1408. 4 => $type,
  1409. 5 => false, // isStringAttachment
  1410. 6 => 'attachment',
  1411. 7 => 0
  1412. );
  1413.  
  1414. } catch (phpmailerException $e) {
  1415. $this->SetError($e->getMessage());
  1416. if ($this->exceptions) {
  1417. throw $e;
  1418. }
  1419. echo $e->getMessage()."\n";
  1420. if ( $e->getCode() == self::STOP_CRITICAL ) {
  1421. return false;
  1422. }
  1423. }
  1424. return true;
  1425. }
  1426.  
  1427. /**
  1428. * Return the current array of attachments
  1429. * @return array
  1430. */
  1431. public function GetAttachments() {
  1432. return $this->attachment;
  1433. }
  1434.  
  1435. /**
  1436. * Attaches all fs, string, and binary attachments to the message.
  1437. * Returns an empty string on failure.
  1438. * @access private
  1439. * @return string
  1440. */
  1441. private function AttachAll() {
  1442. // Return text of body
  1443. $mime = array();
  1444. $cidUniq = array();
  1445. $incl = array();
  1446.  
  1447. // Add all attachments
  1448. foreach ($this->attachment as $attachment) {
  1449. // Check for string attachment
  1450. $bString = $attachment[5];
  1451. if ($bString) {
  1452. $string = $attachment[0];
  1453. } else {
  1454. $path = $attachment[0];
  1455. }
  1456.  
  1457. if (in_array($attachment[0], $incl)) { continue; }
  1458. $filename = $attachment[1];
  1459. $name = $attachment[2];
  1460. $encoding = $attachment[3];
  1461. $type = $attachment[4];
  1462. $disposition = $attachment[6];
  1463. $cid = $attachment[7];
  1464. $incl[] = $attachment[0];
  1465. if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
  1466. $cidUniq[$cid] = true;
  1467.  
  1468. $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
  1469. $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
  1470. $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  1471.  
  1472. if($disposition == 'inline') {
  1473. $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  1474. }
  1475.  
  1476. $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
  1477.  
  1478. // Encode as string attachment
  1479. if($bString) {
  1480. $mime[] = $this->EncodeString($string, $encoding);
  1481. if($this->IsError()) {
  1482. return '';
  1483. }
  1484. $mime[] = $this->LE.$this->LE;
  1485. } else {
  1486. $mime[] = $this->EncodeFile($path, $encoding);
  1487. if($this->IsError()) {
  1488. return '';
  1489. }
  1490. $mime[] = $this->LE.$this->LE;
  1491. }
  1492. }
  1493.  
  1494. $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
  1495.  
  1496. return join('', $mime);
  1497. }
  1498.  
  1499. /**
  1500. * Encodes attachment in requested format.
  1501. * Returns an empty string on failure.
  1502. * @param string $path The full path to the file
  1503. * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  1504. * @see EncodeFile()
  1505. * @access private
  1506. * @return string
  1507. */
  1508. private function EncodeFile($path, $encoding = 'base64') {
  1509. try {
  1510. if (!is_readable($path)) {
  1511. throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
  1512. }
  1513. if (function_exists('get_magic_quotes')) {
  1514. function get_magic_quotes() {
  1515. return false;
  1516. }
  1517. }
  1518. if (PHP_VERSION < 6) {
  1519. $magic_quotes = get_magic_quotes_runtime();
  1520. set_magic_quotes_runtime(0);
  1521. }
  1522. $file_buffer = file_get_contents($path);
  1523. $file_buffer = $this->EncodeString($file_buffer, $encoding);
  1524. if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
  1525. return $file_buffer;
  1526. } catch (Exception $e) {
  1527. $this->SetError($e->getMessage());
  1528. return '';
  1529. }
  1530. }
  1531.  
  1532. /**
  1533. * Encodes string to requested format.
  1534. * Returns an empty string on failure.
  1535. * @param string $str The text to encode
  1536. * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  1537. * @access public
  1538. * @return string
  1539. */
  1540. public function EncodeString ($str, $encoding = 'base64') {
  1541. $encoded = '';
  1542. switch(strtolower($encoding)) {
  1543. case 'base64':
  1544. $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  1545. break;
  1546. case '7bit':
  1547. case '8bit':
  1548. $encoded = $this->FixEOL($str);
  1549. //Make sure it ends with a line break
  1550. if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  1551. $encoded .= $this->LE;
  1552. break;
  1553. case 'binary':
  1554. $encoded = $str;
  1555. break;
  1556. case 'quoted-printable':
  1557. $encoded = $this->EncodeQP($str);
  1558. break;
  1559. default:
  1560. $this->SetError($this->Lang('encoding') . $encoding);
  1561. break;
  1562. }
  1563. return $encoded;
  1564. }
  1565.  
  1566. /**
  1567. * Encode a header string to best (shortest) of Q, B, quoted or none.
  1568. * @access public
  1569. * @return string
  1570. */
  1571. public function EncodeHeader($str, $position = 'text') {
  1572. $x = 0;
  1573.  
  1574. switch (strtolower($position)) {
  1575. case 'phrase':
  1576. if (!preg_match('/[\200-\377]/', $str)) {
  1577. // Can't use addslashes as we don't know what value has magic_quotes_sybase
  1578. $encoded = addcslashes($str, "\0..\37\177\\\"");
  1579. if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  1580. return ($encoded);
  1581. } else {
  1582. return ("\"$encoded\"");
  1583. }
  1584. }
  1585. $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  1586. break;
  1587. case 'comment':
  1588. $x = preg_match_all('/[()"]/', $str, $matches);
  1589. // Fall-through
  1590. case 'text':
  1591. default:
  1592. $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  1593. break;
  1594. }
  1595.  
  1596. if ($x == 0) {
  1597. return ($str);
  1598. }
  1599.  
  1600. $maxlen = 75 - 7 - strlen($this->CharSet);
  1601. // Try to select the encoding which should produce the shortest output
  1602. if (strlen($str)/3 < $x) {
  1603. $encoding = 'B';
  1604. if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
  1605. // Use a custom function which correctly encodes and wraps long
  1606. // multibyte strings without breaking lines within a character
  1607. $encoded = $this->Base64EncodeWrapMB($str);
  1608. } else {
  1609. $encoded = base64_encode($str);
  1610. $maxlen -= $maxlen % 4;
  1611. $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  1612. }
  1613. } else {
  1614. $encoding = 'Q';
  1615. $encoded = $this->EncodeQ($str, $position);
  1616. $encoded = $this->WrapText($encoded, $maxlen, true);
  1617. $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
  1618. }
  1619.  
  1620. $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  1621. $encoded = trim(str_replace("\n", $this->LE, $encoded));
  1622.  
  1623. return $encoded;
  1624. }
  1625.  
  1626. /**
  1627. * Checks if a string contains multibyte characters.
  1628. * @access public
  1629. * @param string $str multi-byte text to wrap encode
  1630. * @return bool
  1631. */
  1632. public function HasMultiBytes($str) {
  1633. if (function_exists('mb_strlen')) {
  1634. return (strlen($str) > mb_strlen($str, $this->CharSet));
  1635. } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  1636. return false;
  1637. }
  1638. }
  1639.  
  1640. /**
  1641. * Correctly encodes and wraps long multibyte strings for mail headers
  1642. * without breaking lines within a character.
  1643. * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
  1644. * @access public
  1645. * @param string $str multi-byte text to wrap encode
  1646. * @return string
  1647. */
  1648. public function Base64EncodeWrapMB($str) {
  1649. $start = "=?".$this->CharSet."?B?";
  1650. $end = "?=";
  1651. $encoded = "";
  1652.  
  1653. $mb_length = mb_strlen($str, $this->CharSet);
  1654. // Each line must have length <= 75, including $start and $end
  1655. $length = 75 - strlen($start) - strlen($end);
  1656. // Average multi-byte ratio
  1657. $ratio = $mb_length / strlen($str);
  1658. // Base64 has a 4:3 ratio
  1659. $offset = $avgLength = floor($length * $ratio * .75);
  1660.  
  1661. for ($i = 0; $i < $mb_length; $i += $offset) {
  1662. $lookBack = 0;
  1663.  
  1664. do {
  1665. $offset = $avgLength - $lookBack;
  1666. $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  1667. $chunk = base64_encode($chunk);
  1668. $lookBack++;
  1669. }
  1670. while (strlen($chunk) > $length);
  1671.  
  1672. $encoded .= $chunk . $this->LE;
  1673. }
  1674.  
  1675. // Chomp the last linefeed
  1676. $encoded = substr($encoded, 0, -strlen($this->LE));
  1677. return $encoded;
  1678. }
  1679.  
  1680. /**
  1681. * Encode string to quoted-printable.
  1682. * Only uses standard PHP, slow, but will always work
  1683. * @access public
  1684. * @param string $string the text to encode
  1685. * @param integer $line_max Number of chars allowed on a line before wrapping
  1686. * @return string
  1687. */
  1688. public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
  1689. $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  1690. $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
  1691. $eol = "\r\n";
  1692. $escape = '=';
  1693. $output = '';
  1694. while( list(, $line) = each($lines) ) {
  1695. $linlen = strlen($line);
  1696. $newline = '';
  1697. for($i = 0; $i < $linlen; $i++) {
  1698. $c = substr( $line, $i, 1 );
  1699. $dec = ord( $c );
  1700. if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
  1701. $c = '=2E';
  1702. }
  1703. if ( $dec == 32 ) {
  1704. if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
  1705. $c = '=20';
  1706. } else if ( $space_conv ) {
  1707. $c = '=20';
  1708. }
  1709. } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
  1710. $h2 = floor($dec/16);
  1711. $h1 = floor($dec%16);
  1712. $c = $escape.$hex[$h2].$hex[$h1];
  1713. }
  1714. if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
  1715. $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
  1716. $newline = '';
  1717. // check if newline first character will be point or not
  1718. if ( $dec == 46 ) {
  1719. $c = '=2E';
  1720. }
  1721. }
  1722. $newline .= $c;
  1723. } // end of for
  1724. $output .= $newline.$eol;
  1725. } // end of while
  1726. return $output;
  1727. }
  1728.  
  1729. /**
  1730. * Encode string to RFC2045 (6.7) quoted-printable format
  1731. * Uses a PHP5 stream filter to do the encoding about 64x faster than the old version
  1732. * Also results in same content as you started with after decoding
  1733. * @see EncodeQPphp()
  1734. * @access public
  1735. * @param string $string the text to encode
  1736. * @param integer $line_max Number of chars allowed on a line before wrapping
  1737. * @param boolean $space_conv Dummy param for compatibility with existing EncodeQP function
  1738. * @return string
  1739. * @author Marcus Bointon
  1740. */
  1741. public function EncodeQP($string, $line_max = 76, $space_conv = false) {
  1742. if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3)
  1743. return quoted_printable_encode($string);
  1744. }
  1745. $filters = stream_get_filters();
  1746. if (!in_array('convert.*', $filters)) { //Got convert stream filter?
  1747. return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation
  1748. }
  1749. $fp = fopen('php://temp/', 'r+');
  1750. $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks
  1751. $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE);
  1752. $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
  1753. fputs($fp, $string);
  1754. rewind($fp);
  1755. $out = stream_get_contents($fp);
  1756. stream_filter_remove($s);
  1757. $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange
  1758. fclose($fp);
  1759. return $out;
  1760. }
  1761.  
  1762. /**
  1763. * Encode string to q encoding.
  1764. * @link http://tools.ietf.org/html/rfc2047
  1765. * @param string $str the text to encode
  1766. * @param string $position Where the text is going to be used, see the RFC for what that means
  1767. * @access public
  1768. * @return string
  1769. */
  1770. public function EncodeQ ($str, $position = 'text') {
  1771. // There should not be any EOL in the string
  1772. $encoded = preg_replace('/[\r\n]*/', '', $str);
  1773.  
  1774. switch (strtolower($position)) {
  1775. case 'phrase':
  1776. $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1777. break;
  1778. case 'comment':
  1779. $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1780. case 'text':
  1781. default:
  1782. // Replace every high ascii, control =, ? and _ characters
  1783. //TODO using /e (equivalent to eval()) is probably not a good idea
  1784. $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
  1785. "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1786. break;
  1787. }
  1788.  
  1789. // Replace every spaces to _ (more readable than =20)
  1790. $encoded = str_replace(' ', '_', $encoded);
  1791.  
  1792. return $encoded;
  1793. }
  1794.  
  1795. /**
  1796. * Adds a string or binary attachment (non-filesystem) to the list.
  1797. * This method can be used to attach ascii or binary data,
  1798. * such as a BLOB record from a database.
  1799. * @param string $string String attachment data.
  1800. * @param string $filename Name of the attachment.
  1801. * @param string $encoding File encoding (see $Encoding).
  1802. * @param string $type File extension (MIME) type.
  1803. * @return void
  1804. */
  1805. public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
  1806. // Append to $attachment array
  1807. $this->attachment[] = array(
  1808. 0 => $string,
  1809. 1 => $filename,
  1810. 2 => basename($filename),
  1811. 3 => $encoding,
  1812. 4 => $type,
  1813. 5 => true, // isStringAttachment
  1814. 6 => 'attachment',
  1815. 7 => 0
  1816. );
  1817. }
  1818.  
  1819. /**
  1820. * Adds an embedded attachment. This can include images, sounds, and
  1821. * just about any other document. Make sure to set the $type to an
  1822. * image type. For JPEG images use "image/jpeg" and for GIF images
  1823. * use "image/gif".
  1824. * @param string $path Path to the attachment.
  1825. * @param string $cid Content ID of the attachment. Use this to identify
  1826. * the Id for accessing the image in an HTML form.
  1827. * @param string $name Overrides the attachment name.
  1828. * @param string $encoding File encoding (see $Encoding).
  1829. * @param string $type File extension (MIME) type.
  1830. * @return bool
  1831. */
  1832. public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1833.  
  1834. if ( !@is_file($path) ) {
  1835. $this->SetError($this->Lang('file_access') . $path);
  1836. return false;
  1837. }
  1838.  
  1839. $filename = basename($path);
  1840. if ( $name == '' ) {
  1841. $name = $filename;
  1842. }
  1843.  
  1844. // Append to $attachment array
  1845. $this->attachment[] = array(
  1846. 0 => $path,
  1847. 1 => $filename,
  1848. 2 => $name,
  1849. 3 => $encoding,
  1850. 4 => $type,
  1851. 5 => false, // isStringAttachment
  1852. 6 => 'inline',
  1853. 7 => $cid
  1854. );
  1855.  
  1856. return true;
  1857. }
  1858.  
  1859. /**
  1860. * Returns true if an inline attachment is present.
  1861. * @access public
  1862. * @return bool
  1863. */
  1864. public function InlineImageExists() {
  1865. foreach($this->attachment as $attachment) {
  1866. if ($attachment[6] == 'inline') {
  1867. return true;
  1868. }
  1869. }
  1870. return false;
  1871. }
  1872.  
  1873. /////////////////////////////////////////////////
  1874. // CLASS METHODS, MESSAGE RESET
  1875. /////////////////////////////////////////////////
  1876.  
  1877. /**
  1878. * Clears all recipients assigned in the TO array. Returns void.
  1879. * @return void
  1880. */
  1881. public function ClearAddresses() {
  1882. foreach($this->to as $to) {
  1883. unset($this->all_recipients[strtolower($to[0])]);
  1884. }
  1885. $this->to = array();
  1886. }
  1887.  
  1888. /**
  1889. * Clears all recipients assigned in the CC array. Returns void.
  1890. * @return void
  1891. */
  1892. public function ClearCCs() {
  1893. foreach($this->cc as $cc) {
  1894. unset($this->all_recipients[strtolower($cc[0])]);
  1895. }
  1896. $this->cc = array();
  1897. }
  1898.  
  1899. /**
  1900. * Clears all recipients assigned in the BCC array. Returns void.
  1901. * @return void
  1902. */
  1903. public function ClearBCCs() {
  1904. foreach($this->bcc as $bcc) {
  1905. unset($this->all_recipients[strtolower($bcc[0])]);
  1906. }
  1907. $this->bcc = array();
  1908. }
  1909.  
  1910. /**
  1911. * Clears all recipients assigned in the ReplyTo array. Returns void.
  1912. * @return void
  1913. */
  1914. public function ClearReplyTos() {
  1915. $this->ReplyTo = array();
  1916. }
  1917.  
  1918. /**
  1919. * Clears all recipients assigned in the TO, CC and BCC
  1920. * array. Returns void.
  1921. * @return void
  1922. */
  1923. public function ClearAllRecipients() {
  1924. $this->to = array();
  1925. $this->cc = array();
  1926. $this->bcc = array();
  1927. $this->all_recipients = array();
  1928. }
  1929.  
  1930. /**
  1931. * Clears all previously set filesystem, string, and binary
  1932. * attachments. Returns void.
  1933. * @return void
  1934. */
  1935. public function ClearAttachments() {
  1936. $this->attachment = array();
  1937. }
  1938.  
  1939. /**
  1940. * Clears all custom headers. Returns void.
  1941. * @return void
  1942. */
  1943. public function ClearCustomHeaders() {
  1944. $this->CustomHeader = array();
  1945. }
  1946.  
  1947. /////////////////////////////////////////////////
  1948. // CLASS METHODS, MISCELLANEOUS
  1949. /////////////////////////////////////////////////
  1950.  
  1951. /**
  1952. * Adds the error message to the error container.
  1953. * @access protected
  1954. * @return void
  1955. */
  1956. protected function SetError($msg) {
  1957. $this->error_count++;
  1958. if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
  1959. $lasterror = $this->smtp->getError();
  1960. if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
  1961. $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
  1962. }
  1963. }
  1964. $this->ErrorInfo = $msg;
  1965. }
  1966.  
  1967. /**
  1968. * Returns the proper RFC 822 formatted date.
  1969. * @access public
  1970. * @return string
  1971. * @static
  1972. */
  1973. public static function RFCDate() {
  1974. $tz = date('Z');
  1975. $tzs = ($tz < 0) ? '-' : '+';
  1976. $tz = abs($tz);
  1977. $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
  1978. $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
  1979.  
  1980. return $result;
  1981. }
  1982.  
  1983. /**
  1984. * Returns the server hostname or 'localhost.localdomain' if unknown.
  1985. * @access private
  1986. * @return string
  1987. */
  1988. private function ServerHostname() {
  1989. if (!empty($this->Hostname)) {
  1990. $result = $this->Hostname;
  1991. } elseif (isset($_SERVER['SERVER_NAME'])) {
  1992. $result = $_SERVER['SERVER_NAME'];
  1993. } else {
  1994. $result = 'localhost.localdomain';
  1995. }
  1996.  
  1997. return $result;
  1998. }
  1999.  
  2000. /**
  2001. * Returns a message in the appropriate language.
  2002. * @access private
  2003. * @return string
  2004. */
  2005. private function Lang($key) {
  2006. if(count($this->language) < 1) {
  2007. $this->SetLanguage('en'); // set the default language
  2008. }
  2009.  
  2010. if(isset($this->language[$key])) {
  2011. return $this->language[$key];
  2012. } else {
  2013. return 'Language string failed to load: ' . $key;
  2014. }
  2015. }
  2016.  
  2017. /**
  2018. * Returns true if an error occurred.
  2019. * @access public
  2020. * @return bool
  2021. */
  2022. public function IsError() {
  2023. return ($this->error_count > 0);
  2024. }
  2025.  
  2026. /**
  2027. * Changes every end of line from CR or LF to CRLF.
  2028. * @access private
  2029. * @return string
  2030. */
  2031. private function FixEOL($str) {
  2032. $str = str_replace("\r\n", "\n", $str);
  2033. $str = str_replace("\r", "\n", $str);
  2034. $str = str_replace("\n", $this->LE, $str);
  2035. return $str;
  2036. }
  2037.  
  2038. /**
  2039. * Adds a custom header.
  2040. * @access public
  2041. * @return void
  2042. */
  2043. public function AddCustomHeader($custom_header) {
  2044. $this->CustomHeader[] = explode(':', $custom_header, 2);
  2045. }
  2046.  
  2047. /**
  2048. * Evaluates the message and returns modifications for inline images and backgrounds
  2049. * @access public
  2050. * @return $message
  2051. */
  2052. public function MsgHTML($message, $basedir = '') {
  2053. preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
  2054. if(isset($images[2])) {
  2055. foreach($images[2] as $i => $url) {
  2056. // do not change urls for absolute images (thanks to corvuscorax)
  2057. if (!preg_match('#^[A-z]+://#',$url)) {
  2058. $filename = basename($url);
  2059. $directory = dirname($url);
  2060. ($directory == '.')?$directory='':'';
  2061. $cid = 'cid:' . md5($filename);
  2062. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  2063. $mimeType = self::_mime_types($ext);
  2064. if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
  2065. if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
  2066. if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
  2067. $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
  2068. }
  2069. }
  2070. }
  2071. }
  2072. $this->IsHTML(true);
  2073. $this->Body = $message;
  2074. $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
  2075. if (!empty($textMsg) && empty($this->AltBody)) {
  2076. $this->AltBody = html_entity_decode($textMsg);
  2077. }
  2078. if (empty($this->AltBody)) {
  2079. $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
  2080. }
  2081. }
  2082.  
  2083. /**
  2084. * Gets the MIME type of the embedded or inline image
  2085. * @param string File extension
  2086. * @access public
  2087. * @return string MIME type of ext
  2088. * @static
  2089. */
  2090. public static function _mime_types($ext = '') {
  2091. $mimes = array(
  2092. 'hqx' => 'application/mac-binhex40',
  2093. 'cpt' => 'application/mac-compactpro',
  2094. 'doc' => 'application/msword',
  2095. 'bin' => 'application/macbinary',
  2096. 'dms' => 'application/octet-stream',
  2097. 'lha' => 'application/octet-stream',
  2098. 'lzh' => 'application/octet-stream',
  2099. 'exe' => 'application/octet-stream',
  2100. 'class' => 'application/octet-stream',
  2101. 'psd' => 'application/octet-stream',
  2102. 'so' => 'application/octet-stream',
  2103. 'sea' => 'application/octet-stream',
  2104. 'dll' => 'application/octet-stream',
  2105. 'oda' => 'application/oda',
  2106. 'pdf' => 'application/pdf',
  2107. 'ai' => 'application/postscript',
  2108. 'eps' => 'application/postscript',
  2109. 'ps' => 'application/postscript',
  2110. 'smi' => 'application/smil',
  2111. 'smil' => 'application/smil',
  2112. 'mif' => 'application/vnd.mif',
  2113. 'xls' => 'application/vnd.ms-excel',
  2114. 'ppt' => 'application/vnd.ms-powerpoint',
  2115. 'wbxml' => 'application/vnd.wap.wbxml',
  2116. 'wmlc' => 'application/vnd.wap.wmlc',
  2117. 'dcr' => 'application/x-director',
  2118. 'dir' => 'application/x-director',
  2119. 'dxr' => 'application/x-director',
  2120. 'dvi' => 'application/x-dvi',
  2121. 'gtar' => 'application/x-gtar',
  2122. 'php' => 'application/x-httpd-php',
  2123. 'php4' => 'application/x-httpd-php',
  2124. 'php3' => 'application/x-httpd-php',
  2125. 'phtml' => 'application/x-httpd-php',
  2126. 'phps' => 'application/x-httpd-php-source',
  2127. 'js' => 'application/x-javascript',
  2128. 'swf' => 'application/x-shockwave-flash',
  2129. 'sit' => 'application/x-stuffit',
  2130. 'tar' => 'application/x-tar',
  2131. 'tgz' => 'application/x-tar',
  2132. 'xhtml' => 'application/xhtml+xml',
  2133. 'xht' => 'application/xhtml+xml',
  2134. 'zip' => 'application/zip',
  2135. 'mid' => 'audio/midi',
  2136. 'midi' => 'audio/midi',
  2137. 'mpga' => 'audio/mpeg',
  2138. 'mp2' => 'audio/mpeg',
  2139. 'mp3' => 'audio/mpeg',
  2140. 'aif' => 'audio/x-aiff',
  2141. 'aiff' => 'audio/x-aiff',
  2142. 'aifc' => 'audio/x-aiff',
  2143. 'ram' => 'audio/x-pn-realaudio',
  2144. 'rm' => 'audio/x-pn-realaudio',
  2145. 'rpm' => 'audio/x-pn-realaudio-plugin',
  2146. 'ra' => 'audio/x-realaudio',
  2147. 'rv' => 'video/vnd.rn-realvideo',
  2148. 'wav' => 'audio/x-wav',
  2149. 'bmp' => 'image/bmp',
  2150. 'gif' => 'image/gif',
  2151. 'jpeg' => 'image/jpeg',
  2152. 'jpg' => 'image/jpeg',
  2153. 'jpe' => 'image/jpeg',
  2154. 'png' => 'image/png',
  2155. 'tiff' => 'image/tiff',
  2156. 'tif' => 'image/tiff',
  2157. 'css' => 'text/css',
  2158. 'html' => 'text/html',
  2159. 'htm' => 'text/html',
  2160. 'shtml' => 'text/html',
  2161. 'txt' => 'text/plain',
  2162. 'text' => 'text/plain',
  2163. 'log' => 'text/plain',
  2164. 'rtx' => 'text/richtext',
  2165. 'rtf' => 'text/rtf',
  2166. 'xml' => 'text/xml',
  2167. 'xsl' => 'text/xml',
  2168. 'mpeg' => 'video/mpeg',
  2169. 'mpg' => 'video/mpeg',
  2170. 'mpe' => 'video/mpeg',
  2171. 'qt' => 'video/quicktime',
  2172. 'mov' => 'video/quicktime',
  2173. 'avi' => 'video/x-msvideo',
  2174. 'movie' => 'video/x-sgi-movie',
  2175. 'doc' => 'application/msword',
  2176. 'word' => 'application/msword',
  2177. 'xl' => 'application/excel',
  2178. 'eml' => 'message/rfc822'
  2179. );
  2180. return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
  2181. }
  2182.  
  2183. /**
  2184. * Set (or reset) Class Objects (variables)
  2185. *
  2186. * Usage Example:
  2187. * $page->set('X-Priority', '3');
  2188. *
  2189. * @access public
  2190. * @param string $name Parameter Name
  2191. * @param mixed $value Parameter Value
  2192. * NOTE: will not work with arrays, there are no arrays to set/reset
  2193. * @todo Should this not be using __set() magic function?
  2194. */
  2195. public function set($name, $value = '') {
  2196. try {
  2197. if (isset($this->$name) ) {
  2198. $this->$name = $value;
  2199. } else {
  2200. throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL);
  2201. }
  2202. } catch (Exception $e) {
  2203. $this->SetError($e->getMessage());
  2204. if ($e->getCode() == self::STOP_CRITICAL) {
  2205. return false;
  2206. }
  2207. }
  2208. return true;
  2209. }
  2210.  
  2211. /**
  2212. * Strips newlines to prevent header injection.
  2213. * @access public
  2214. * @param string $str String
  2215. * @return string
  2216. */
  2217. public function SecureHeader($str) {
  2218. $str = str_replace("\r", '', $str);
  2219. $str = str_replace("\n", '', $str);
  2220. return trim($str);
  2221. }
  2222.  
  2223. /**
  2224. * Set the private key file and password to sign the message.
  2225. *
  2226. * @access public
  2227. * @param string $key_filename Parameter File Name
  2228. * @param string $key_pass Password for private key
  2229. */
  2230. public function Sign($cert_filename, $key_filename, $key_pass) {
  2231. $this->sign_cert_file = $cert_filename;
  2232. $this->sign_key_file = $key_filename;
  2233. $this->sign_key_pass = $key_pass;
  2234. }
  2235.  
  2236. /**
  2237. * Set the private key file and password to sign the message.
  2238. *
  2239. * @access public
  2240. * @param string $key_filename Parameter File Name
  2241. * @param string $key_pass Password for private key
  2242. */
  2243. public function DKIM_QP($txt) {
  2244. $tmp="";
  2245. $line="";
  2246. for ($i=0;$i<strlen($txt);$i++) {
  2247. $ord=ord($txt[$i]);
  2248. if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) {
  2249. $line.=$txt[$i];
  2250. } else {
  2251. $line.="=".sprintf("%02X",$ord);
  2252. }
  2253. }
  2254. return $line;
  2255. }
  2256.  
  2257. /**
  2258. * Generate DKIM signature
  2259. *
  2260. * @access public
  2261. * @param string $s Header
  2262. */
  2263. public function DKIM_Sign($s) {
  2264. $privKeyStr = file_get_contents($this->DKIM_private);
  2265. if ($this->DKIM_passphrase!='') {
  2266. $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase);
  2267. } else {
  2268. $privKey = $privKeyStr;
  2269. }
  2270. if (openssl_sign($s, $signature, $privKey)) {
  2271. return base64_encode($signature);
  2272. }
  2273. }
  2274.  
  2275. /**
  2276. * Generate DKIM Canonicalization Header
  2277. *
  2278. * @access public
  2279. * @param string $s Header
  2280. */
  2281. public function DKIM_HeaderC($s) {
  2282. $s=preg_replace("/\r\n\s+/"," ",$s);
  2283. $lines=explode("\r\n",$s);
  2284. foreach ($lines as $key=>$line) {
  2285. list($heading,$value)=explode(":",$line,2);
  2286. $heading=strtolower($heading);
  2287. $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces
  2288. $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value
  2289. }
  2290. $s=implode("\r\n",$lines);
  2291. return $s;
  2292. }
  2293.  
  2294. /**
  2295. * Generate DKIM Canonicalization Body
  2296. *
  2297. * @access public
  2298. * @param string $body Message Body
  2299. */
  2300. public function DKIM_BodyC($body) {
  2301. if ($body == '') return "\r\n";
  2302. // stabilize line endings
  2303. $body=str_replace("\r\n","\n",$body);
  2304. $body=str_replace("\n","\r\n",$body);
  2305. // END stabilize line endings
  2306. while (substr($body,strlen($body)-4,4) == "\r\n\r\n") {
  2307. $body=substr($body,0,strlen($body)-2);
  2308. }
  2309. return $body;
  2310. }
  2311.  
  2312. /**
  2313. * Create the DKIM header, body, as new header
  2314. *
  2315. * @access public
  2316. * @param string $headers_line Header lines
  2317. * @param string $subject Subject
  2318. * @param string $body Body
  2319. */
  2320. public function DKIM_Add($headers_line,$subject,$body) {
  2321. $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
  2322. $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
  2323. $DKIMquery = 'dns/txt'; // Query method
  2324. $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
  2325. $subject_header = "Subject: $subject";
  2326. $headers = explode("\r\n",$headers_line);
  2327. foreach($headers as $header) {
  2328. if (strpos($header,'From:') === 0) {
  2329. $from_header=$header;
  2330. } elseif (strpos($header,'To:') === 0) {
  2331. $to_header=$header;
  2332. }
  2333. }
  2334. $from = str_replace('|','=7C',$this->DKIM_QP($from_header));
  2335. $to = str_replace('|','=7C',$this->DKIM_QP($to_header));
  2336. $subject = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable
  2337. $body = $this->DKIM_BodyC($body);
  2338. $DKIMlen = strlen($body) ; // Length of body
  2339. $DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body
  2340. $ident = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";";
  2341. $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n".
  2342. "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n".
  2343. "\th=From:To:Subject;\r\n".
  2344. "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n".
  2345. "\tz=$from\r\n".
  2346. "\t|$to\r\n".
  2347. "\t|$subject;\r\n".
  2348. "\tbh=" . $DKIMb64 . ";\r\n".
  2349. "\tb=";
  2350. $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
  2351. $signed = $this->DKIM_Sign($toSign);
  2352. return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
  2353. }
  2354.  
  2355. protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) {
  2356. if (!empty($this->action_function) && function_exists($this->action_function)) {
  2357. $params = array($isSent,$to,$cc,$bcc,$subject,$body);
  2358. call_user_func_array($this->action_function,$params);
  2359. }
  2360. }
  2361. }
  2362.  
  2363. class phpmailerException extends Exception {
  2364. public function errorMessage() {
  2365. $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  2366. return $errorMsg;
  2367. }
  2368. }
  2369.  
  2370. /*~ class.smtp.php
  2371. .---------------------------------------------------------------------------.
  2372. | Software: PHPMailer - PHP email class |
  2373. | Version: 5.1 |
  2374. | Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
  2375. | Info: http://phpmailer.sourceforge.net |
  2376. | Support: http://sourceforge.net/projects/phpmailer/ |
  2377. | ------------------------------------------------------------------------- |
  2378. | Admin: Andy Prevost (project admininistrator) |
  2379. | Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
  2380. | : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
  2381. | Founder: Brent R. Matzelle (original founder) |
  2382. | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
  2383. | Copyright (c) 2001-2003, Brent R. Matzelle |
  2384. | ------------------------------------------------------------------------- |
  2385. | License: Distributed under the Lesser General Public License (LGPL) |
  2386. | http://www.gnu.org/copyleft/lesser.html |
  2387. | This program is distributed in the hope that it will be useful - WITHOUT |
  2388. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
  2389. | FITNESS FOR A PARTICULAR PURPOSE. |
  2390. | ------------------------------------------------------------------------- |
  2391. | We offer a number of paid services (www.codeworxtech.com): |
  2392. | - Web Hosting on highly optimized fast and secure servers |
  2393. | - Technology Consulting |
  2394. | - Oursourcing (highly qualified programmers and graphic designers) |
  2395. '---------------------------------------------------------------------------'
  2396. */
  2397.  
  2398. /**
  2399. * PHPMailer - PHP SMTP email transport class
  2400. * NOTE: Designed for use with PHP version 5 and up
  2401. * @package PHPMailer
  2402. * @author Andy Prevost
  2403. * @author Marcus Bointon
  2404. * @copyright 2004 - 2008 Andy Prevost
  2405. * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
  2406. * @version $Id: class.smtp.php 444 2009-05-05 11:22:26Z coolbru $
  2407. */
  2408.  
  2409. /**
  2410. * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
  2411. * commands except TURN which will always return a not implemented
  2412. * error. SMTP also provides some utility methods for sending mail
  2413. * to an SMTP server.
  2414. * original author: Chris Ryan
  2415. */
  2416.  
  2417. class SMTP {
  2418. /**
  2419. * SMTP server port
  2420. * @var int
  2421. */
  2422. public $SMTP_PORT = 25;
  2423.  
  2424. /**
  2425. * SMTP reply line ending
  2426. * @var string
  2427. */
  2428. public $CRLF = "\r\n";
  2429.  
  2430. /**
  2431. * Sets whether debugging is turned on
  2432. * @var bool
  2433. */
  2434. public $do_debug; // the level of debug to perform
  2435.  
  2436. /**
  2437. * Sets VERP use on/off (default is off)
  2438. * @var bool
  2439. */
  2440. public $do_verp = false;
  2441.  
  2442. /////////////////////////////////////////////////
  2443. // PROPERTIES, PRIVATE AND PROTECTED
  2444. /////////////////////////////////////////////////
  2445.  
  2446. private $smtp_conn; // the socket to the server
  2447. private $error; // error if any on the last call
  2448. private $helo_rply; // the reply the server sent to us for HELO
  2449.  
  2450. /**
  2451. * Initialize the class so that the data is in a known state.
  2452. * @access public
  2453. * @return void
  2454. */
  2455. public function __construct() {
  2456. $this->smtp_conn = 0;
  2457. $this->error = null;
  2458. $this->helo_rply = null;
  2459.  
  2460. $this->do_debug = 0;
  2461. }
  2462.  
  2463. /////////////////////////////////////////////////
  2464. // CONNECTION FUNCTIONS
  2465. /////////////////////////////////////////////////
  2466.  
  2467. /**
  2468. * Connect to the server specified on the port specified.
  2469. * If the port is not specified use the default SMTP_PORT.
  2470. * If tval is specified then a connection will try and be
  2471. * established with the server for that number of seconds.
  2472. * If tval is not specified the default is 30 seconds to
  2473. * try on the connection.
  2474. *
  2475. * SMTP CODE SUCCESS: 220
  2476. * SMTP CODE FAILURE: 421
  2477. * @access public
  2478. * @return bool
  2479. */
  2480. public function Connect($host, $port = 0, $tval = 30) {
  2481. // set the error val to null so there is no confusion
  2482. $this->error = null;
  2483.  
  2484. // make sure we are __not__ connected
  2485. if($this->connected()) {
  2486. // already connected, generate error
  2487. $this->error = array("error" => "Already connected to a server");
  2488. return false;
  2489. }
  2490.  
  2491. if(empty($port)) {
  2492. $port = $this->SMTP_PORT;
  2493. }
  2494.  
  2495. // connect to the smtp server
  2496. $this->smtp_conn = @fsockopen($host, // the host of the server
  2497. $port, // the port to use
  2498. $errno, // error number if any
  2499. $errstr, // error message if any
  2500. $tval); // give up after ? secs
  2501. // verify we connected properly
  2502. if(empty($this->smtp_conn)) {
  2503. $this->error = array("error" => "Failed to connect to server",
  2504. "errno" => $errno,
  2505. "errstr" => $errstr);
  2506. if($this->do_debug >= 1) {
  2507. echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';
  2508. }
  2509. return false;
  2510. }
  2511.  
  2512. // SMTP server can take longer to respond, give longer timeout for first read
  2513. // Windows does not have support for this timeout function
  2514. if(substr(PHP_OS, 0, 3) != "WIN")
  2515. socket_set_timeout($this->smtp_conn, $tval, 0);
  2516.  
  2517. // get any announcement
  2518. $announce = $this->get_lines();
  2519.  
  2520. if($this->do_debug >= 2) {
  2521. echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';
  2522. }
  2523.  
  2524. return true;
  2525. }
  2526.  
  2527. /**
  2528. * Initiate a TLS communication with the server.
  2529. *
  2530. * SMTP CODE 220 Ready to start TLS
  2531. * SMTP CODE 501 Syntax error (no parameters allowed)
  2532. * SMTP CODE 454 TLS not available due to temporary reason
  2533. * @access public
  2534. * @return bool success
  2535. */
  2536. public function StartTLS() {
  2537. $this->error = null; # to avoid confusion
  2538.  
  2539. if(!$this->connected()) {
  2540. $this->error = array("error" => "Called StartTLS() without being connected");
  2541. return false;
  2542. }
  2543.  
  2544. fputs($this->smtp_conn,"STARTTLS" . $this->CRLF);
  2545.  
  2546. $rply = $this->get_lines();
  2547. $code = substr($rply,0,3);
  2548.  
  2549. if($this->do_debug >= 2) {
  2550. echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
  2551. }
  2552.  
  2553. if($code != 220) {
  2554. $this->error =
  2555. array("error" => "STARTTLS not accepted from server",
  2556. "smtp_code" => $code,
  2557. "smtp_msg" => substr($rply,4));
  2558. if($this->do_debug >= 1) {
  2559. echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
  2560. }
  2561. return false;
  2562. }
  2563.  
  2564. // Begin encrypted connection
  2565. if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
  2566. return false;
  2567. }
  2568.  
  2569. return true;
  2570. }
  2571.  
  2572. /**
  2573. * Performs SMTP authentication. Must be run after running the
  2574. * Hello() method. Returns true if successfully authenticated.
  2575. * @access public
  2576. * @return bool
  2577. */
  2578. public function Authenticate($username, $password) {
  2579. // Start authentication
  2580. fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
  2581.  
  2582. $rply = $this->get_lines();
  2583. $code = substr($rply,0,3);
  2584.  
  2585. if($code != 334) {
  2586. $this->error =
  2587. array("error" => "AUTH not accepted from server",
  2588. "smtp_code" => $code,
  2589. "smtp_msg" => substr($rply,4));
  2590. if($this->do_debug >= 1) {
  2591. echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
  2592. }
  2593. return false;
  2594. }
  2595.  
  2596. // Send encoded username
  2597. fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
  2598.  
  2599. $rply = $this->get_lines();
  2600. $code = substr($rply,0,3);
  2601.  
  2602. if($code != 334) {
  2603. $this->error =
  2604. array("error" => "Username not accepted from server",
  2605. "smtp_code" => $code,
  2606. "smtp_msg" => substr($rply,4));
  2607. if($this->do_debug >= 1) {
  2608. echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
  2609. }
  2610. return false;
  2611. }
  2612.  
  2613. // Send encoded password
  2614. fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
  2615.  
  2616. $rply = $this->get_lines();
  2617. $code = substr($rply,0,3);
  2618.  
  2619. if($code != 235) {
  2620. $this->error =
  2621. array("error" => "Password not accepted from server",
  2622. "smtp_code" => $code,
  2623. "smtp_msg" => substr($rply,4));
  2624. if($this->do_debug >= 1) {
  2625. echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
  2626. }
  2627. return false;
  2628. }
  2629.  
  2630. return true;
  2631. }
  2632.  
  2633. /**
  2634. * Returns true if connected to a server otherwise false
  2635. * @access public
  2636. * @return bool
  2637. */
  2638. public function Connected() {
  2639. if(!empty($this->smtp_conn)) {
  2640. $sock_status = socket_get_status($this->smtp_conn);
  2641. if($sock_status["eof"]) {
  2642. // the socket is valid but we are not connected
  2643. if($this->do_debug >= 1) {
  2644. echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
  2645. }
  2646. $this->Close();
  2647. return false;
  2648. }
  2649. return true; // everything looks good
  2650. }
  2651. return false;
  2652. }
  2653.  
  2654. /**
  2655. * Closes the socket and cleans up the state of the class.
  2656. * It is not considered good to use this function without
  2657. * first trying to use QUIT.
  2658. * @access public
  2659. * @return void
  2660. */
  2661. public function Close() {
  2662. $this->error = null; // so there is no confusion
  2663. $this->helo_rply = null;
  2664. if(!empty($this->smtp_conn)) {
  2665. // close the connection and cleanup
  2666. fclose($this->smtp_conn);
  2667. $this->smtp_conn = 0;
  2668. }
  2669. }
  2670.  
  2671. /////////////////////////////////////////////////
  2672. // SMTP COMMANDS
  2673. /////////////////////////////////////////////////
  2674.  
  2675. /**
  2676. * Issues a data command and sends the msg_data to the server
  2677. * finializing the mail transaction. $msg_data is the message
  2678. * that is to be send with the headers. Each header needs to be
  2679. * on a single line followed by a <CRLF> with the message headers
  2680. * and the message body being seperated by and additional <CRLF>.
  2681. *
  2682. * Implements rfc 821: DATA <CRLF>
  2683. *
  2684. * SMTP CODE INTERMEDIATE: 354
  2685. * [data]
  2686. * <CRLF>.<CRLF>
  2687. * SMTP CODE SUCCESS: 250
  2688. * SMTP CODE FAILURE: 552,554,451,452
  2689. * SMTP CODE FAILURE: 451,554
  2690. * SMTP CODE ERROR : 500,501,503,421
  2691. * @access public
  2692. * @return bool
  2693. */
  2694. public function Data($msg_data) {
  2695. $this->error = null; // so no confusion is caused
  2696.  
  2697. if(!$this->connected()) {
  2698. $this->error = array(
  2699. "error" => "Called Data() without being connected");
  2700. return false;
  2701. }
  2702.  
  2703. fputs($this->smtp_conn,"DATA" . $this->CRLF);
  2704.  
  2705. $rply = $this->get_lines();
  2706. $code = substr($rply,0,3);
  2707.  
  2708. if($this->do_debug >= 2) {
  2709. echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
  2710. }
  2711.  
  2712. if($code != 354) {
  2713. $this->error =
  2714. array("error" => "DATA command not accepted from server",
  2715. "smtp_code" => $code,
  2716. "smtp_msg" => substr($rply,4));
  2717. if($this->do_debug >= 1) {
  2718. echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
  2719. }
  2720. return false;
  2721. }
  2722.  
  2723. /* the server is ready to accept data!
  2724. * according to rfc 821 we should not send more than 1000
  2725. * including the CRLF
  2726. * characters on a single line so we will break the data up
  2727. * into lines by \r and/or \n then if needed we will break
  2728. * each of those into smaller lines to fit within the limit.
  2729. * in addition we will be looking for lines that start with
  2730. * a period '.' and append and additional period '.' to that
  2731. * line. NOTE: this does not count towards limit.
  2732. */
  2733.  
  2734. // normalize the line breaks so we know the explode works
  2735. $msg_data = str_replace("\r\n","\n",$msg_data);
  2736. $msg_data = str_replace("\r","\n",$msg_data);
  2737. $lines = explode("\n",$msg_data);
  2738.  
  2739. /* we need to find a good way to determine is headers are
  2740. * in the msg_data or if it is a straight msg body
  2741. * currently I am assuming rfc 822 definitions of msg headers
  2742. * and if the first field of the first line (':' sperated)
  2743. * does not contain a space then it _should_ be a header
  2744. * and we can process all lines before a blank "" line as
  2745. * headers.
  2746. */
  2747.  
  2748. $field = substr($lines[0],0,strpos($lines[0],":"));
  2749. $in_headers = false;
  2750. if(!empty($field) && !strstr($field," ")) {
  2751. $in_headers = true;
  2752. }
  2753.  
  2754. $max_line_length = 998; // used below; set here for ease in change
  2755.  
  2756. while(list(,$line) = @each($lines)) {
  2757. $lines_out = null;
  2758. if($line == "" && $in_headers) {
  2759. $in_headers = false;
  2760. }
  2761. // ok we need to break this line up into several smaller lines
  2762. while(strlen($line) > $max_line_length) {
  2763. $pos = strrpos(substr($line,0,$max_line_length)," ");
  2764.  
  2765. // Patch to fix DOS attack
  2766. if(!$pos) {
  2767. $pos = $max_line_length - 1;
  2768. $lines_out[] = substr($line,0,$pos);
  2769. $line = substr($line,$pos);
  2770. } else {
  2771. $lines_out[] = substr($line,0,$pos);
  2772. $line = substr($line,$pos + 1);
  2773. }
  2774.  
  2775. /* if processing headers add a LWSP-char to the front of new line
  2776. * rfc 822 on long msg headers
  2777. */
  2778. if($in_headers) {
  2779. $line = "\t" . $line;
  2780. }
  2781. }
  2782. $lines_out[] = $line;
  2783.  
  2784. // send the lines to the server
  2785. while(list(,$line_out) = @each($lines_out)) {
  2786. if(strlen($line_out) > 0)
  2787. {
  2788. if(substr($line_out, 0, 1) == ".") {
  2789. $line_out = "." . $line_out;
  2790. }
  2791. }
  2792. fputs($this->smtp_conn,$line_out . $this->CRLF);
  2793. }
  2794. }
  2795.  
  2796. // message data has been sent
  2797. fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
  2798.  
  2799. $rply = $this->get_lines();
  2800. $code = substr($rply,0,3);
  2801.  
  2802. if($this->do_debug >= 2) {
  2803. echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
  2804. }
  2805.  
  2806. if($code != 250) {
  2807. $this->error =
  2808. array("error" => "DATA not accepted from server",
  2809. "smtp_code" => $code,
  2810. "smtp_msg" => substr($rply,4));
  2811. if($this->do_debug >= 1) {
  2812. echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
  2813. }
  2814. return false;
  2815. }
  2816. return true;
  2817. }
  2818.  
  2819. /**
  2820. * Sends the HELO command to the smtp server.
  2821. * This makes sure that we and the server are in
  2822. * the same known state.
  2823. *
  2824. * Implements from rfc 821: HELO <SP> <domain> <CRLF>
  2825. *
  2826. * SMTP CODE SUCCESS: 250
  2827. * SMTP CODE ERROR : 500, 501, 504, 421
  2828. * @access public
  2829. * @return bool
  2830. */
  2831. public function Hello($host = '') {
  2832. $this->error = null; // so no confusion is caused
  2833.  
  2834. if(!$this->connected()) {
  2835. $this->error = array(
  2836. "error" => "Called Hello() without being connected");
  2837. return false;
  2838. }
  2839.  
  2840. // if hostname for HELO was not specified send default
  2841. if(empty($host)) {
  2842. // determine appropriate default to send to server
  2843. $host = "localhost";
  2844. }
  2845.  
  2846. // Send extended hello first (RFC 2821)
  2847. if(!$this->SendHello("EHLO", $host)) {
  2848. if(!$this->SendHello("HELO", $host)) {
  2849. return false;
  2850. }
  2851. }
  2852.  
  2853. return true;
  2854. }
  2855.  
  2856. /**
  2857. * Sends a HELO/EHLO command.
  2858. * @access private
  2859. * @return bool
  2860. */
  2861. private function SendHello($hello, $host) {
  2862. fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
  2863.  
  2864. $rply = $this->get_lines();
  2865. $code = substr($rply,0,3);
  2866.  
  2867. if($this->do_debug >= 2) {
  2868. echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';
  2869. }
  2870.  
  2871. if($code != 250) {
  2872. $this->error =
  2873. array("error" => $hello . " not accepted from server",
  2874. "smtp_code" => $code,
  2875. "smtp_msg" => substr($rply,4));
  2876. if($this->do_debug >= 1) {
  2877. echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
  2878. }
  2879. return false;
  2880. }
  2881.  
  2882. $this->helo_rply = $rply;
  2883.  
  2884. return true;
  2885. }
  2886.  
  2887. /**
  2888. * Starts a mail transaction from the email address specified in
  2889. * $from. Returns true if successful or false otherwise. If True
  2890. * the mail transaction is started and then one or more Recipient
  2891. * commands may be called followed by a Data command.
  2892. *
  2893. * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
  2894. *
  2895. * SMTP CODE SUCCESS: 250
  2896. * SMTP CODE SUCCESS: 552,451,452
  2897. * SMTP CODE SUCCESS: 500,501,421
  2898. * @access public
  2899. * @return bool
  2900. */
  2901. public function Mail($from) {
  2902. $this->error = null; // so no confusion is caused
  2903.  
  2904. if(!$this->connected()) {
  2905. $this->error = array(
  2906. "error" => "Called Mail() without being connected");
  2907. return false;
  2908. }
  2909.  
  2910. $useVerp = ($this->do_verp ? "XVERP" : "");
  2911. fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
  2912.  
  2913. $rply = $this->get_lines();
  2914. $code = substr($rply,0,3);
  2915.  
  2916. if($this->do_debug >= 2) {
  2917. echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
  2918. }
  2919.  
  2920. if($code != 250) {
  2921. $this->error =
  2922. array("error" => "MAIL not accepted from server",
  2923. "smtp_code" => $code,
  2924. "smtp_msg" => substr($rply,4));
  2925. if($this->do_debug >= 1) {
  2926. echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
  2927. }
  2928. return false;
  2929. }
  2930. return true;
  2931. }
  2932.  
  2933. /**
  2934. * Sends the quit command to the server and then closes the socket
  2935. * if there is no error or the $close_on_error argument is true.
  2936. *
  2937. * Implements from rfc 821: QUIT <CRLF>
  2938. *
  2939. * SMTP CODE SUCCESS: 221
  2940. * SMTP CODE ERROR : 500
  2941. * @access public
  2942. * @return bool
  2943. */
  2944. public function Quit($close_on_error = true) {
  2945. $this->error = null; // so there is no confusion
  2946.  
  2947. if(!$this->connected()) {
  2948. $this->error = array(
  2949. "error" => "Called Quit() without being connected");
  2950. return false;
  2951. }
  2952.  
  2953. // send the quit command to the server
  2954. fputs($this->smtp_conn,"quit" . $this->CRLF);
  2955.  
  2956. // get any good-bye messages
  2957. $byemsg = $this->get_lines();
  2958.  
  2959. if($this->do_debug >= 2) {
  2960. echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';
  2961. }
  2962.  
  2963. $rval = true;
  2964. $e = null;
  2965.  
  2966. $code = substr($byemsg,0,3);
  2967. if($code != 221) {
  2968. // use e as a tmp var cause Close will overwrite $this->error
  2969. $e = array("error" => "SMTP server rejected quit command",
  2970. "smtp_code" => $code,
  2971. "smtp_rply" => substr($byemsg,4));
  2972. $rval = false;
  2973. if($this->do_debug >= 1) {
  2974. echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';
  2975. }
  2976. }
  2977.  
  2978. if(empty($e) || $close_on_error) {
  2979. $this->Close();
  2980. }
  2981.  
  2982. return $rval;
  2983. }
  2984.  
  2985. /**
  2986. * Sends the command RCPT to the SMTP server with the TO: argument of $to.
  2987. * Returns true if the recipient was accepted false if it was rejected.
  2988. *
  2989. * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
  2990. *
  2991. * SMTP CODE SUCCESS: 250,251
  2992. * SMTP CODE FAILURE: 550,551,552,553,450,451,452
  2993. * SMTP CODE ERROR : 500,501,503,421
  2994. * @access public
  2995. * @return bool
  2996. */
  2997. public function Recipient($to) {
  2998. $this->error = null; // so no confusion is caused
  2999.  
  3000. if(!$this->connected()) {
  3001. $this->error = array(
  3002. "error" => "Called Recipient() without being connected");
  3003. return false;
  3004. }
  3005.  
  3006. fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
  3007.  
  3008. $rply = $this->get_lines();
  3009. $code = substr($rply,0,3);
  3010.  
  3011. if($this->do_debug >= 2) {
  3012. echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
  3013. }
  3014.  
  3015. if($code != 250 && $code != 251) {
  3016. $this->error =
  3017. array("error" => "RCPT not accepted from server",
  3018. "smtp_code" => $code,
  3019. "smtp_msg" => substr($rply,4));
  3020. if($this->do_debug >= 1) {
  3021. echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
  3022. }
  3023. return false;
  3024. }
  3025. return true;
  3026. }
  3027.  
  3028. /**
  3029. * Sends the RSET command to abort and transaction that is
  3030. * currently in progress. Returns true if successful false
  3031. * otherwise.
  3032. *
  3033. * Implements rfc 821: RSET <CRLF>
  3034. *
  3035. * SMTP CODE SUCCESS: 250
  3036. * SMTP CODE ERROR : 500,501,504,421
  3037. * @access public
  3038. * @return bool
  3039. */
  3040. public function Reset() {
  3041. $this->error = null; // so no confusion is caused
  3042.  
  3043. if(!$this->connected()) {
  3044. $this->error = array(
  3045. "error" => "Called Reset() without being connected");
  3046. return false;
  3047. }
  3048.  
  3049. fputs($this->smtp_conn,"RSET" . $this->CRLF);
  3050.  
  3051. $rply = $this->get_lines();
  3052. $code = substr($rply,0,3);
  3053.  
  3054. if($this->do_debug >= 2) {
  3055. echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
  3056. }
  3057.  
  3058. if($code != 250) {
  3059. $this->error =
  3060. array("error" => "RSET failed",
  3061. "smtp_code" => $code,
  3062. "smtp_msg" => substr($rply,4));
  3063. if($this->do_debug >= 1) {
  3064. echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
  3065. }
  3066. return false;
  3067. }
  3068.  
  3069. return true;
  3070. }
  3071.  
  3072. /**
  3073. * Starts a mail transaction from the email address specified in
  3074. * $from. Returns true if successful or false otherwise. If True
  3075. * the mail transaction is started and then one or more Recipient
  3076. * commands may be called followed by a Data command. This command
  3077. * will send the message to the users terminal if they are logged
  3078. * in and send them an email.
  3079. *
  3080. * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
  3081. *
  3082. * SMTP CODE SUCCESS: 250
  3083. * SMTP CODE SUCCESS: 552,451,452
  3084. * SMTP CODE SUCCESS: 500,501,502,421
  3085. * @access public
  3086. * @return bool
  3087. */
  3088. public function SendAndMail($from) {
  3089. $this->error = null; // so no confusion is caused
  3090.  
  3091. if(!$this->connected()) {
  3092. $this->error = array(
  3093. "error" => "Called SendAndMail() without being connected");
  3094. return false;
  3095. }
  3096.  
  3097. fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
  3098.  
  3099. $rply = $this->get_lines();
  3100. $code = substr($rply,0,3);
  3101.  
  3102. if($this->do_debug >= 2) {
  3103. echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
  3104. }
  3105.  
  3106. if($code != 250) {
  3107. $this->error =
  3108. array("error" => "SAML not accepted from server",
  3109. "smtp_code" => $code,
  3110. "smtp_msg" => substr($rply,4));
  3111. if($this->do_debug >= 1) {
  3112. echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
  3113. }
  3114. return false;
  3115. }
  3116. return true;
  3117. }
  3118.  
  3119. /**
  3120. * This is an optional command for SMTP that this class does not
  3121. * support. This method is here to make the RFC821 Definition
  3122. * complete for this class and __may__ be implimented in the future
  3123. *
  3124. * Implements from rfc 821: TURN <CRLF>
  3125. *
  3126. * SMTP CODE SUCCESS: 250
  3127. * SMTP CODE FAILURE: 502
  3128. * SMTP CODE ERROR : 500, 503
  3129. * @access public
  3130. * @return bool
  3131. */
  3132. public function Turn() {
  3133. $this->error = array("error" => "This method, TURN, of the SMTP ".
  3134. "is not implemented");
  3135. if($this->do_debug >= 1) {
  3136. echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
  3137. }
  3138. return false;
  3139. }
  3140.  
  3141. /**
  3142. * Get the current error
  3143. * @access public
  3144. * @return array
  3145. */
  3146. public function getError() {
  3147. return $this->error;
  3148. }
  3149.  
  3150. /////////////////////////////////////////////////
  3151. // INTERNAL FUNCTIONS
  3152. /////////////////////////////////////////////////
  3153.  
  3154. /**
  3155. * Read in as many lines as possible
  3156. * either before eof or socket timeout occurs on the operation.
  3157. * With SMTP we can tell if we have more lines to read if the
  3158. * 4th character is '-' symbol. If it is a space then we don't
  3159. * need to read anything else.
  3160. * @access private
  3161. * @return string
  3162. */
  3163. private function get_lines() {
  3164. $data = "";
  3165. while($str = @fgets($this->smtp_conn,515)) {
  3166. if($this->do_debug >= 4) {
  3167. echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />';
  3168. echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />';
  3169. }
  3170. $data .= $str;
  3171. if($this->do_debug >= 4) {
  3172. echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';
  3173. }
  3174. // if 4th character is a space, we are done reading, break the loop
  3175. if(substr($str,3,1) == " ") { break; }
  3176. }
  3177. return $data;
  3178. }
  3179.  
  3180. }
  3181.  
  3182. /*Function RegistrationMailSmtp($msg, $theme, $to)
  3183. {
  3184. $mail = new PHPMailer();
  3185. $body=$msg;
  3186. //$body = "Проверка связи<br><br>Вы проверяете связь...";
  3187. $body = eregi_replace("[\]",'',$body);
  3188.  
  3189. $mail->IsSMTP(); // telling the class to use SMTP
  3190.  
  3191.  
  3192. $mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
  3193. // 1 = errors and messages
  3194. // 2 = messages only
  3195.  
  3196. $mail->SMTPAuth = true; // enable SMTP authentication
  3197. $mail->Host = "smtp.yandex.ru"; // sets the SMTP server
  3198. $mail->Username = "robot@domains-keeper.ru"; // SMTP account username
  3199. $mail->Password = "12be34"; // SMTP account password
  3200. $mail->SetFrom('robot@domains-keeper.ru', 'Domains-keeper.ru');
  3201. $mail->AddReplyTo('robot@domains-keeper.ru', 'Domains-keeper.ru');
  3202.  
  3203. $mail->IsHTML(true);
  3204. $mail->CharSet = 'Windows-1251';
  3205. $mail->Subject = $theme;
  3206. $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  3207. $mail->MsgHTML($body);
  3208. $address = $to;
  3209. $mail->AddAddress($address);
  3210.  
  3211.  
  3212. if(!$mail->Send()) {
  3213. //echo "Mailer Error: " . $mail->ErrorInfo;
  3214. return false;
  3215. } else {
  3216. //echo "Message sent!";
  3217. return true;
  3218. }
  3219. }
  3220. */
Add Comment
Please, Sign In to add comment