Guest User

Untitled

a guest
Feb 16th, 2017
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 131.94 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3. //This is the NEW version 3.9.1
  4. /*
  5. 3.9.1
  6.  
  7. re-fixed send_to not chosen
  8. approx line 3468
  9. if(!isset($this->p_vars[drop_name]) || $this->p_vars[drop_name] =='' ||$this->p_vars[drop_name] = false)
  10.  
  11.  
  12. 3.9
  13. array of licenses
  14.  
  15. 3.8
  16. $this->ssl
  17. $this->port
  18.  
  19. version 2.02 phpmailer
  20.  
  21. fixed bug with quotation using confirmation == 1
  22. line 4727 htmlspecialchars
  23.  
  24. 3.7
  25. fixed licensing issue with new pathinfo code
  26. fixed confirm = true when $_GET['cid'] is used (line 4277)
  27.  
  28. 3.6
  29. fix Notice errors
  30. fix $dom (approx line 2961)
  31.  
  32. 3.5
  33. https fix
  34. removes underscore on error template
  35.  
  36. 3.4
  37. Fixes field required
  38.  
  39.  
  40. 3.3
  41. Makes filenames available in the templates.
  42. {{file1}}
  43.  
  44. 3.2.9
  45. Adjusted the licensing to compensate for urls like
  46. foobar.co.uk
  47. with this code
  48. if(count($dom1) > 2 && (strlen($dom1[1])+strlen($dom[2])) > 4) array_shift($dom1);
  49.  
  50. Fixed postTokenName
  51. and changed it to
  52. tokenPostName (x10 places)
  53.  
  54. 3.2.8
  55. Made field names available in mail merge template
  56. Added controls.php switcher
  57. Added config file for antispam token session code
  58. Make it possible to require files
  59.  
  60. 3.2.7
  61. Webmaster "From" over-ride
  62. BG image replacement for templates
  63. Fixed html receipt to visitor removing br tags
  64. Updated createToken code with my new sauce
  65. *Simplified temp code registration
  66. *New licensing to fix license errors with subdomains
  67. Ability to add CC
  68.  
  69. 3.2.6
  70. File names added to webmaster email
  71.  
  72. 3.2.5
  73. >Fixed multiple checkbox for sending email
  74. to multiple recipients
  75. >drop_down_default added to controls.php
  76. which when set to true will grab recipient[0]
  77. instead of throwing error if no dropdown chosen
  78. */
  79. /*3.2.4
  80. Made it possible to send text to recipient
  81. and html to webmaster or vice versa
  82. $set['recipient_html'] = true;
  83. $set['webmaster_html'] = true;
  84.  
  85. Removed extraneous <br> from text email
  86.  
  87. confirmation page
  88.  
  89. extra end routine
  90. */
  91.  
  92. /*3.2.3
  93. Changed
  94. antiSpam session info to actuall work ;)
  95. */
  96.  
  97. /*Licensing*/
  98.  
  99. /*free = 0
  100. basic = 1
  101. pro = 2
  102. */
  103.  
  104. /*~ class.smtp.php
  105. .---------------------------------------------------------------------------.
  106. | Software: PHPMailer - PHP email class |
  107. | Version: 2.0.2 |
  108. | Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
  109. | Info: http://phpmailer.sourceforge.net |
  110. | Support: http://sourceforge.net/projects/phpmailer/ |
  111. | ------------------------------------------------------------------------- |
  112. | Author: Andy Prevost (project admininistrator) |
  113. | Author: Brent R. Matzelle (original founder) |
  114. | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
  115. | Copyright (c) 2001-2003, Brent R. Matzelle |
  116. | ------------------------------------------------------------------------- |
  117. | License: Distributed under the Lesser General Public License (LGPL) |
  118. | http://www.gnu.org/copyleft/lesser.html |
  119. | This program is distributed in the hope that it will be useful - WITHOUT |
  120. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
  121. | FITNESS FOR A PARTICULAR PURPOSE. |
  122. | ------------------------------------------------------------------------- |
  123. | We offer a number of paid services (www.codeworxtech.com): |
  124. | - Web Hosting on highly optimized fast and secure servers |
  125. | - Technology Consulting |
  126. | - Oursourcing (highly qualified programmers and graphic designers) |
  127. '---------------------------------------------------------------------------'
  128.  
  129. /**
  130. * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
  131. * commands except TURN which will always return a not implemented
  132. * error. SMTP also provides some utility methods for sending mail
  133. * to an SMTP server.
  134. * @package PHPMailer
  135. * @author Chris Ryan
  136. */
  137.  
  138. class SMTP
  139. {
  140. /**
  141. * SMTP server port
  142. * @var int
  143. */
  144. var $SMTP_PORT = 25;
  145.  
  146. /**
  147. * SMTP reply line ending
  148. * @var string
  149. */
  150. var $CRLF = "\r\n";
  151.  
  152. /**
  153. * Sets whether debugging is turned on
  154. * @var bool
  155. */
  156. var $do_debug; # the level of debug to perform
  157.  
  158. /**
  159. * Sets VERP use on/off (default is off)
  160. * @var bool
  161. */
  162. var $do_verp = false;
  163.  
  164. /**#@+
  165. * @access private
  166. */
  167. var $smtp_conn; # the socket to the server
  168. var $error; # error if any on the last call
  169. var $helo_rply; # the reply the server sent to us for HELO
  170. /**#@-*/
  171.  
  172. /**
  173. * Initialize the class so that the data is in a known state.
  174. * @access public
  175. * @return void
  176. */
  177. function SMTP() {
  178. $this->smtp_conn = 0;
  179. $this->error = null;
  180. $this->helo_rply = null;
  181.  
  182. $this->do_debug = 0;
  183. }
  184.  
  185. /*************************************************************
  186. * CONNECTION FUNCTIONS *
  187. ***********************************************************/
  188.  
  189. /**
  190. * Connect to the server specified on the port specified.
  191. * If the port is not specified use the default SMTP_PORT.
  192. * If tval is specified then a connection will try and be
  193. * established with the server for that number of seconds.
  194. * If tval is not specified the default is 30 seconds to
  195. * try on the connection.
  196. *
  197. * SMTP CODE SUCCESS: 220
  198. * SMTP CODE FAILURE: 421
  199. * @access public
  200. * @return bool
  201. */
  202. function Connect($host,$port=0,$tval=30) {
  203. # set the error val to null so there is no confusion
  204. $this->error = null;
  205.  
  206. # make sure we are __not__ connected
  207. if($this->connected()) {
  208. # ok we are connected! what should we do?
  209. # for now we will just give an error saying we
  210. # are already connected
  211. $this->error = array("error" => "Already connected to a server");
  212. return false;
  213. }
  214.  
  215. if(empty($port)) {
  216. $port = $this->SMTP_PORT;
  217. }
  218.  
  219. #connect to the smtp server
  220. $this->smtp_conn = fsockopen($host, # the host of the server
  221. $port, # the port to use
  222. $errno, # error number if any
  223. $errstr, # error message if any
  224. $tval); # give up after ? secs
  225. # verify we connected properly
  226. if(empty($this->smtp_conn)) {
  227. $this->error = array("error" => "Failed to connect to server",
  228. "errno" => $errno,
  229. "errstr" => $errstr);
  230. if($this->do_debug >= 1) {
  231. echo "SMTP -> ERROR: " . $this->error["error"] .
  232. ": $errstr ($errno)" . $this->CRLF;
  233. }
  234. return false;
  235. }
  236.  
  237. # sometimes the SMTP server takes a little longer to respond
  238. # so we will give it a longer timeout for the first read
  239. // Windows still does not have support for this timeout function
  240. if(substr(PHP_OS, 0, 3) != "WIN")
  241. socket_set_timeout($this->smtp_conn, $tval, 0);
  242.  
  243. # get any announcement stuff
  244. $announce = $this->get_lines();
  245.  
  246. # set the timeout of any socket functions at 1/10 of a second
  247. //if(function_exists("socket_set_timeout"))
  248. // socket_set_timeout($this->smtp_conn, 0, 100000);
  249.  
  250. if($this->do_debug >= 2) {
  251. echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
  252. }
  253.  
  254. return true;
  255. }
  256.  
  257. /**
  258. * Performs SMTP authentication. Must be run after running the
  259. * Hello() method. Returns true if successfully authenticated.
  260. * @access public
  261. * @return bool
  262. */
  263. function Authenticate($username, $password) {
  264. // Start authentication
  265. fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
  266.  
  267. $rply = $this->get_lines();
  268. $code = substr($rply,0,3);
  269.  
  270. if($code != 334) {
  271. $this->error =
  272. array("error" => "AUTH not accepted from server",
  273. "smtp_code" => $code,
  274. "smtp_msg" => substr($rply,4));
  275. if($this->do_debug >= 1) {
  276. echo "SMTP -> ERROR: " . $this->error["error"] .
  277. ": " . $rply . $this->CRLF;
  278. }
  279. return false;
  280. }
  281.  
  282. // Send encoded username
  283. fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
  284.  
  285. $rply = $this->get_lines();
  286. $code = substr($rply,0,3);
  287.  
  288. if($code != 334) {
  289. $this->error =
  290. array("error" => "Username not accepted from server",
  291. "smtp_code" => $code,
  292. "smtp_msg" => substr($rply,4));
  293. if($this->do_debug >= 1) {
  294. echo "SMTP -> ERROR: " . $this->error["error"] .
  295. ": " . $rply . $this->CRLF;
  296. }
  297. return false;
  298. }
  299.  
  300. // Send encoded password
  301. fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
  302.  
  303. $rply = $this->get_lines();
  304. $code = substr($rply,0,3);
  305.  
  306. if($code != 235) {
  307. $this->error =
  308. array("error" => "Password not accepted from server",
  309. "smtp_code" => $code,
  310. "smtp_msg" => substr($rply,4));
  311. if($this->do_debug >= 1) {
  312. echo "SMTP -> ERROR: " . $this->error["error"] .
  313. ": " . $rply . $this->CRLF;
  314. }
  315. return false;
  316. }
  317.  
  318. return true;
  319. }
  320.  
  321. /**
  322. * Returns true if connected to a server otherwise false
  323. * @access private
  324. * @return bool
  325. */
  326. function Connected() {
  327. if(!empty($this->smtp_conn)) {
  328. $sock_status = socket_get_status($this->smtp_conn);
  329. if($sock_status["eof"]) {
  330. # hmm this is an odd situation... the socket is
  331. # valid but we are not connected anymore
  332. if($this->do_debug >= 1) {
  333. echo "SMTP -> NOTICE:" . $this->CRLF .
  334. "EOF caught while checking if connected";
  335. }
  336. $this->Close();
  337. return false;
  338. }
  339. return true; # everything looks good
  340. }
  341. return false;
  342. }
  343.  
  344. /**
  345. * Closes the socket and cleans up the state of the class.
  346. * It is not considered good to use this function without
  347. * first trying to use QUIT.
  348. * @access public
  349. * @return void
  350. */
  351. function Close() {
  352. $this->error = null; # so there is no confusion
  353. $this->helo_rply = null;
  354. if(!empty($this->smtp_conn)) {
  355. # close the connection and cleanup
  356. fclose($this->smtp_conn);
  357. $this->smtp_conn = 0;
  358. }
  359. }
  360.  
  361. /***************************************************************
  362. * SMTP COMMANDS *
  363. *************************************************************/
  364.  
  365. /**
  366. * Issues a data command and sends the msg_data to the server
  367. * finializing the mail transaction. $msg_data is the message
  368. * that is to be send with the headers. Each header needs to be
  369. * on a single line followed by a <CRLF> with the message headers
  370. * and the message body being seperated by and additional <CRLF>.
  371. *
  372. * Implements rfc 821: DATA <CRLF>
  373. *
  374. * SMTP CODE INTERMEDIATE: 354
  375. * [data]
  376. * <CRLF>.<CRLF>
  377. * SMTP CODE SUCCESS: 250
  378. * SMTP CODE FAILURE: 552,554,451,452
  379. * SMTP CODE FAILURE: 451,554
  380. * SMTP CODE ERROR : 500,501,503,421
  381. * @access public
  382. * @return bool
  383. */
  384. function Data($msg_data) {
  385. $this->error = null; # so no confusion is caused
  386.  
  387. if(!$this->connected()) {
  388. $this->error = array(
  389. "error" => "Called Data() without being connected");
  390. return false;
  391. }
  392.  
  393. fputs($this->smtp_conn,"DATA" . $this->CRLF);
  394.  
  395. $rply = $this->get_lines();
  396. $code = substr($rply,0,3);
  397.  
  398. if($this->do_debug >= 2) {
  399. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  400. }
  401.  
  402. if($code != 354) {
  403. $this->error =
  404. array("error" => "DATA command not accepted from server",
  405. "smtp_code" => $code,
  406. "smtp_msg" => substr($rply,4));
  407. if($this->do_debug >= 1) {
  408. echo "SMTP -> ERROR: " . $this->error["error"] .
  409. ": " . $rply . $this->CRLF;
  410. }
  411. return false;
  412. }
  413.  
  414. # the server is ready to accept data!
  415. # according to rfc 821 we should not send more than 1000
  416. # including the CRLF
  417. # characters on a single line so we will break the data up
  418. # into lines by \r and/or \n then if needed we will break
  419. # each of those into smaller lines to fit within the limit.
  420. # in addition we will be looking for lines that start with
  421. # a period '.' and append and additional period '.' to that
  422. # line. NOTE: this does not count towards are limit.
  423.  
  424. # normalize the line breaks so we know the explode works
  425. $msg_data = str_replace("\r\n","\n",$msg_data);
  426. $msg_data = str_replace("\r","\n",$msg_data);
  427. $lines = explode("\n",$msg_data);
  428.  
  429. # we need to find a good way to determine is headers are
  430. # in the msg_data or if it is a straight msg body
  431. # currently I am assuming rfc 822 definitions of msg headers
  432. # and if the first field of the first line (':' sperated)
  433. # does not contain a space then it _should_ be a header
  434. # and we can process all lines before a blank "" line as
  435. # headers.
  436. $field = substr($lines[0],0,strpos($lines[0],":"));
  437. $in_headers = false;
  438. if(!empty($field) && !strstr($field," ")) {
  439. $in_headers = true;
  440. }
  441.  
  442. $max_line_length = 998; # used below; set here for ease in change
  443.  
  444. while(list(,$line) = @each($lines)) {
  445. $lines_out = null;
  446. if($line == "" && $in_headers) {
  447. $in_headers = false;
  448. }
  449. # ok we need to break this line up into several
  450. # smaller lines
  451. while(strlen($line) > $max_line_length) {
  452. $pos = strrpos(substr($line,0,$max_line_length)," ");
  453.  
  454. # Patch to fix DOS attack
  455. if(!$pos) {
  456. $pos = $max_line_length - 1;
  457. }
  458.  
  459. $lines_out[] = substr($line,0,$pos);
  460. $line = substr($line,$pos + 1);
  461. # if we are processing headers we need to
  462. # add a LWSP-char to the front of the new line
  463. # rfc 822 on long msg headers
  464. if($in_headers) {
  465. $line = "\t" . $line;
  466. }
  467. }
  468. $lines_out[] = $line;
  469.  
  470. # now send the lines to the server
  471. while(list(,$line_out) = @each($lines_out)) {
  472. if(strlen($line_out) > 0)
  473. {
  474. if(substr($line_out, 0, 1) == ".") {
  475. $line_out = "." . $line_out;
  476. }
  477. }
  478. fputs($this->smtp_conn,$line_out . $this->CRLF);
  479. }
  480. }
  481.  
  482. # ok all the message data has been sent so lets get this
  483. # over with aleady
  484. fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
  485.  
  486. $rply = $this->get_lines();
  487. $code = substr($rply,0,3);
  488.  
  489. if($this->do_debug >= 2) {
  490. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  491. }
  492.  
  493. if($code != 250) {
  494. $this->error =
  495. array("error" => "DATA not accepted from server",
  496. "smtp_code" => $code,
  497. "smtp_msg" => substr($rply,4));
  498. if($this->do_debug >= 1) {
  499. echo "SMTP -> ERROR: " . $this->error["error"] .
  500. ": " . $rply . $this->CRLF;
  501. }
  502. return false;
  503. }
  504. return true;
  505. }
  506.  
  507. /**
  508. * Expand takes the name and asks the server to list all the
  509. * people who are members of the _list_. Expand will return
  510. * back and array of the result or false if an error occurs.
  511. * Each value in the array returned has the format of:
  512. * [ <full-name> <sp> ] <path>
  513. * The definition of <path> is defined in rfc 821
  514. *
  515. * Implements rfc 821: EXPN <SP> <string> <CRLF>
  516. *
  517. * SMTP CODE SUCCESS: 250
  518. * SMTP CODE FAILURE: 550
  519. * SMTP CODE ERROR : 500,501,502,504,421
  520. * @access public
  521. * @return string array
  522. */
  523. function Expand($name) {
  524. $this->error = null; # so no confusion is caused
  525.  
  526. if(!$this->connected()) {
  527. $this->error = array(
  528. "error" => "Called Expand() without being connected");
  529. return false;
  530. }
  531.  
  532. fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
  533.  
  534. $rply = $this->get_lines();
  535. $code = substr($rply,0,3);
  536.  
  537. if($this->do_debug >= 2) {
  538. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  539. }
  540.  
  541. if($code != 250) {
  542. $this->error =
  543. array("error" => "EXPN not accepted from server",
  544. "smtp_code" => $code,
  545. "smtp_msg" => substr($rply,4));
  546. if($this->do_debug >= 1) {
  547. echo "SMTP -> ERROR: " . $this->error["error"] .
  548. ": " . $rply . $this->CRLF;
  549. }
  550. return false;
  551. }
  552.  
  553. # parse the reply and place in our array to return to user
  554. $entries = explode($this->CRLF,$rply);
  555. while(list(,$l) = @each($entries)) {
  556. $list[] = substr($l,4);
  557. }
  558.  
  559. return $list;
  560. }
  561.  
  562. /**
  563. * Sends the HELO command to the smtp server.
  564. * This makes sure that we and the server are in
  565. * the same known state.
  566. *
  567. * Implements from rfc 821: HELO <SP> <domain> <CRLF>
  568. *
  569. * SMTP CODE SUCCESS: 250
  570. * SMTP CODE ERROR : 500, 501, 504, 421
  571. * @access public
  572. * @return bool
  573. */
  574. function Hello($host="") {
  575. $this->error = null; # so no confusion is caused
  576.  
  577. if(!$this->connected()) {
  578. $this->error = array(
  579. "error" => "Called Hello() without being connected");
  580. return false;
  581. }
  582.  
  583. # if a hostname for the HELO was not specified determine
  584. # a suitable one to send
  585. if(empty($host)) {
  586. # we need to determine some sort of appopiate default
  587. # to send to the server
  588. $host = "localhost";
  589. }
  590.  
  591. // Send extended hello first (RFC 2821)
  592. if(!$this->SendHello("EHLO", $host))
  593. {
  594. if(!$this->SendHello("HELO", $host))
  595. return false;
  596. }
  597.  
  598. return true;
  599. }
  600.  
  601. /**
  602. * Sends a HELO/EHLO command.
  603. * @access private
  604. * @return bool
  605. */
  606. function SendHello($hello, $host) {
  607. fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
  608.  
  609. $rply = $this->get_lines();
  610. $code = substr($rply,0,3);
  611.  
  612. if($this->do_debug >= 2) {
  613. echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
  614. }
  615.  
  616. if($code != 250) {
  617. $this->error =
  618. array("error" => $hello . " not accepted from server",
  619. "smtp_code" => $code,
  620. "smtp_msg" => substr($rply,4));
  621. if($this->do_debug >= 1) {
  622. echo "SMTP -> ERROR: " . $this->error["error"] .
  623. ": " . $rply . $this->CRLF;
  624. }
  625. return false;
  626. }
  627.  
  628. $this->helo_rply = $rply;
  629.  
  630. return true;
  631. }
  632.  
  633. /**
  634. * Gets help information on the keyword specified. If the keyword
  635. * is not specified then returns generic help, ussually contianing
  636. * A list of keywords that help is available on. This function
  637. * returns the results back to the user. It is up to the user to
  638. * handle the returned data. If an error occurs then false is
  639. * returned with $this->error set appropiately.
  640. *
  641. * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
  642. *
  643. * SMTP CODE SUCCESS: 211,214
  644. * SMTP CODE ERROR : 500,501,502,504,421
  645. * @access public
  646. * @return string
  647. */
  648. function Help($keyword="") {
  649. $this->error = null; # to avoid confusion
  650.  
  651. if(!$this->connected()) {
  652. $this->error = array(
  653. "error" => "Called Help() without being connected");
  654. return false;
  655. }
  656.  
  657. $extra = "";
  658. if(!empty($keyword)) {
  659. $extra = " " . $keyword;
  660. }
  661.  
  662. fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
  663.  
  664. $rply = $this->get_lines();
  665. $code = substr($rply,0,3);
  666.  
  667. if($this->do_debug >= 2) {
  668. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  669. }
  670.  
  671. if($code != 211 && $code != 214) {
  672. $this->error =
  673. array("error" => "HELP not accepted from server",
  674. "smtp_code" => $code,
  675. "smtp_msg" => substr($rply,4));
  676. if($this->do_debug >= 1) {
  677. echo "SMTP -> ERROR: " . $this->error["error"] .
  678. ": " . $rply . $this->CRLF;
  679. }
  680. return false;
  681. }
  682.  
  683. return $rply;
  684. }
  685.  
  686. /**
  687. * Starts a mail transaction from the email address specified in
  688. * $from. Returns true if successful or false otherwise. If True
  689. * the mail transaction is started and then one or more Recipient
  690. * commands may be called followed by a Data command.
  691. *
  692. * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
  693. *
  694. * SMTP CODE SUCCESS: 250
  695. * SMTP CODE SUCCESS: 552,451,452
  696. * SMTP CODE SUCCESS: 500,501,421
  697. * @access public
  698. * @return bool
  699. */
  700. function Mail($from) {
  701. $this->error = null; # so no confusion is caused
  702.  
  703. if(!$this->connected()) {
  704. $this->error = array(
  705. "error" => "Called Mail() without being connected");
  706. return false;
  707. }
  708.  
  709. $useVerp = ($this->do_verp ? "XVERP" : "");
  710. fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
  711.  
  712. $rply = $this->get_lines();
  713. $code = substr($rply,0,3);
  714.  
  715. if($this->do_debug >= 2) {
  716. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  717. }
  718.  
  719. if($code != 250) {
  720. $this->error =
  721. array("error" => "MAIL not accepted from server",
  722. "smtp_code" => $code,
  723. "smtp_msg" => substr($rply,4));
  724. if($this->do_debug >= 1) {
  725. echo "SMTP -> ERROR: " . $this->error["error"] .
  726. ": " . $rply . $this->CRLF;
  727. }
  728. return false;
  729. }
  730. return true;
  731. }
  732.  
  733. /**
  734. * Sends the command NOOP to the SMTP server.
  735. *
  736. * Implements from rfc 821: NOOP <CRLF>
  737. *
  738. * SMTP CODE SUCCESS: 250
  739. * SMTP CODE ERROR : 500, 421
  740. * @access public
  741. * @return bool
  742. */
  743. function Noop() {
  744. $this->error = null; # so no confusion is caused
  745.  
  746. if(!$this->connected()) {
  747. $this->error = array(
  748. "error" => "Called Noop() without being connected");
  749. return false;
  750. }
  751.  
  752. fputs($this->smtp_conn,"NOOP" . $this->CRLF);
  753.  
  754. $rply = $this->get_lines();
  755. $code = substr($rply,0,3);
  756.  
  757. if($this->do_debug >= 2) {
  758. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  759. }
  760.  
  761. if($code != 250) {
  762. $this->error =
  763. array("error" => "NOOP not accepted from server",
  764. "smtp_code" => $code,
  765. "smtp_msg" => substr($rply,4));
  766. if($this->do_debug >= 1) {
  767. echo "SMTP -> ERROR: " . $this->error["error"] .
  768. ": " . $rply . $this->CRLF;
  769. }
  770. return false;
  771. }
  772. return true;
  773. }
  774.  
  775. /**
  776. * Sends the quit command to the server and then closes the socket
  777. * if there is no error or the $close_on_error argument is true.
  778. *
  779. * Implements from rfc 821: QUIT <CRLF>
  780. *
  781. * SMTP CODE SUCCESS: 221
  782. * SMTP CODE ERROR : 500
  783. * @access public
  784. * @return bool
  785. */
  786. function Quit($close_on_error=true) {
  787. $this->error = null; # so there is no confusion
  788.  
  789. if(!$this->connected()) {
  790. $this->error = array(
  791. "error" => "Called Quit() without being connected");
  792. return false;
  793. }
  794.  
  795. # send the quit command to the server
  796. fputs($this->smtp_conn,"quit" . $this->CRLF);
  797.  
  798. # get any good-bye messages
  799. $byemsg = $this->get_lines();
  800.  
  801. if($this->do_debug >= 2) {
  802. echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
  803. }
  804.  
  805. $rval = true;
  806. $e = null;
  807.  
  808. $code = substr($byemsg,0,3);
  809. if($code != 221) {
  810. # use e as a tmp var cause Close will overwrite $this->error
  811. $e = array("error" => "SMTP server rejected quit command",
  812. "smtp_code" => $code,
  813. "smtp_rply" => substr($byemsg,4));
  814. $rval = false;
  815. if($this->do_debug >= 1) {
  816. echo "SMTP -> ERROR: " . $e["error"] . ": " .
  817. $byemsg . $this->CRLF;
  818. }
  819. }
  820.  
  821. if(empty($e) || $close_on_error) {
  822. $this->Close();
  823. }
  824.  
  825. return $rval;
  826. }
  827.  
  828. /**
  829. * Sends the command RCPT to the SMTP server with the TO: argument of $to.
  830. * Returns true if the recipient was accepted false if it was rejected.
  831. *
  832. * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
  833. *
  834. * SMTP CODE SUCCESS: 250,251
  835. * SMTP CODE FAILURE: 550,551,552,553,450,451,452
  836. * SMTP CODE ERROR : 500,501,503,421
  837. * @access public
  838. * @return bool
  839. */
  840. function Recipient($to) {
  841. $this->error = null; # so no confusion is caused
  842.  
  843. if(!$this->connected()) {
  844. $this->error = array(
  845. "error" => "Called Recipient() without being connected");
  846. return false;
  847. }
  848.  
  849. fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
  850.  
  851. $rply = $this->get_lines();
  852. $code = substr($rply,0,3);
  853.  
  854. if($this->do_debug >= 2) {
  855. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  856. }
  857.  
  858. if($code != 250 && $code != 251) {
  859. $this->error =
  860. array("error" => "RCPT not accepted from server",
  861. "smtp_code" => $code,
  862. "smtp_msg" => substr($rply,4));
  863. if($this->do_debug >= 1) {
  864. echo "SMTP -> ERROR: " . $this->error["error"] .
  865. ": " . $rply . $this->CRLF;
  866. }
  867. return false;
  868. }
  869. return true;
  870. }
  871.  
  872. /**
  873. * Sends the RSET command to abort and transaction that is
  874. * currently in progress. Returns true if successful false
  875. * otherwise.
  876. *
  877. * Implements rfc 821: RSET <CRLF>
  878. *
  879. * SMTP CODE SUCCESS: 250
  880. * SMTP CODE ERROR : 500,501,504,421
  881. * @access public
  882. * @return bool
  883. */
  884. function Reset() {
  885. $this->error = null; # so no confusion is caused
  886.  
  887. if(!$this->connected()) {
  888. $this->error = array(
  889. "error" => "Called Reset() without being connected");
  890. return false;
  891. }
  892.  
  893. fputs($this->smtp_conn,"RSET" . $this->CRLF);
  894.  
  895. $rply = $this->get_lines();
  896. $code = substr($rply,0,3);
  897.  
  898. if($this->do_debug >= 2) {
  899. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  900. }
  901.  
  902. if($code != 250) {
  903. $this->error =
  904. array("error" => "RSET failed",
  905. "smtp_code" => $code,
  906. "smtp_msg" => substr($rply,4));
  907. if($this->do_debug >= 1) {
  908. echo "SMTP -> ERROR: " . $this->error["error"] .
  909. ": " . $rply . $this->CRLF;
  910. }
  911. return false;
  912. }
  913.  
  914. return true;
  915. }
  916.  
  917. /**
  918. * Starts a mail transaction from the email address specified in
  919. * $from. Returns true if successful or false otherwise. If True
  920. * the mail transaction is started and then one or more Recipient
  921. * commands may be called followed by a Data command. This command
  922. * will send the message to the users terminal if they are logged
  923. * in.
  924. *
  925. * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
  926. *
  927. * SMTP CODE SUCCESS: 250
  928. * SMTP CODE SUCCESS: 552,451,452
  929. * SMTP CODE SUCCESS: 500,501,502,421
  930. * @access public
  931. * @return bool
  932. */
  933. function Send($from) {
  934. $this->error = null; # so no confusion is caused
  935.  
  936. if(!$this->connected()) {
  937. $this->error = array(
  938. "error" => "Called Send() without being connected");
  939. return false;
  940. }
  941.  
  942. fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
  943.  
  944. $rply = $this->get_lines();
  945. $code = substr($rply,0,3);
  946.  
  947. if($this->do_debug >= 2) {
  948. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  949. }
  950.  
  951. if($code != 250) {
  952. $this->error =
  953. array("error" => "SEND not accepted from server",
  954. "smtp_code" => $code,
  955. "smtp_msg" => substr($rply,4));
  956. if($this->do_debug >= 1) {
  957. echo "SMTP -> ERROR: " . $this->error["error"] .
  958. ": " . $rply . $this->CRLF;
  959. }
  960. return false;
  961. }
  962. return true;
  963. }
  964.  
  965. /**
  966. * Starts a mail transaction from the email address specified in
  967. * $from. Returns true if successful or false otherwise. If True
  968. * the mail transaction is started and then one or more Recipient
  969. * commands may be called followed by a Data command. This command
  970. * will send the message to the users terminal if they are logged
  971. * in and send them an email.
  972. *
  973. * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
  974. *
  975. * SMTP CODE SUCCESS: 250
  976. * SMTP CODE SUCCESS: 552,451,452
  977. * SMTP CODE SUCCESS: 500,501,502,421
  978. * @access public
  979. * @return bool
  980. */
  981. function SendAndMail($from) {
  982. $this->error = null; # so no confusion is caused
  983.  
  984. if(!$this->connected()) {
  985. $this->error = array(
  986. "error" => "Called SendAndMail() without being connected");
  987. return false;
  988. }
  989.  
  990. fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
  991.  
  992. $rply = $this->get_lines();
  993. $code = substr($rply,0,3);
  994.  
  995. if($this->do_debug >= 2) {
  996. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  997. }
  998.  
  999. if($code != 250) {
  1000. $this->error =
  1001. array("error" => "SAML not accepted from server",
  1002. "smtp_code" => $code,
  1003. "smtp_msg" => substr($rply,4));
  1004. if($this->do_debug >= 1) {
  1005. echo "SMTP -> ERROR: " . $this->error["error"] .
  1006. ": " . $rply . $this->CRLF;
  1007. }
  1008. return false;
  1009. }
  1010. return true;
  1011. }
  1012.  
  1013. /**
  1014. * Starts a mail transaction from the email address specified in
  1015. * $from. Returns true if successful or false otherwise. If True
  1016. * the mail transaction is started and then one or more Recipient
  1017. * commands may be called followed by a Data command. This command
  1018. * will send the message to the users terminal if they are logged
  1019. * in or mail it to them if they are not.
  1020. *
  1021. * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
  1022. *
  1023. * SMTP CODE SUCCESS: 250
  1024. * SMTP CODE SUCCESS: 552,451,452
  1025. * SMTP CODE SUCCESS: 500,501,502,421
  1026. * @access public
  1027. * @return bool
  1028. */
  1029. function SendOrMail($from) {
  1030. $this->error = null; # so no confusion is caused
  1031.  
  1032. if(!$this->connected()) {
  1033. $this->error = array(
  1034. "error" => "Called SendOrMail() without being connected");
  1035. return false;
  1036. }
  1037.  
  1038. fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
  1039.  
  1040. $rply = $this->get_lines();
  1041. $code = substr($rply,0,3);
  1042.  
  1043. if($this->do_debug >= 2) {
  1044. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  1045. }
  1046.  
  1047. if($code != 250) {
  1048. $this->error =
  1049. array("error" => "SOML not accepted from server",
  1050. "smtp_code" => $code,
  1051. "smtp_msg" => substr($rply,4));
  1052. if($this->do_debug >= 1) {
  1053. echo "SMTP -> ERROR: " . $this->error["error"] .
  1054. ": " . $rply . $this->CRLF;
  1055. }
  1056. return false;
  1057. }
  1058. return true;
  1059. }
  1060.  
  1061. /**
  1062. * This is an optional command for SMTP that this class does not
  1063. * support. This method is here to make the RFC821 Definition
  1064. * complete for this class and __may__ be implimented in the future
  1065. *
  1066. * Implements from rfc 821: TURN <CRLF>
  1067. *
  1068. * SMTP CODE SUCCESS: 250
  1069. * SMTP CODE FAILURE: 502
  1070. * SMTP CODE ERROR : 500, 503
  1071. * @access public
  1072. * @return bool
  1073. */
  1074. function Turn() {
  1075. $this->error = array("error" => "This method, TURN, of the SMTP ".
  1076. "is not implemented");
  1077. if($this->do_debug >= 1) {
  1078. echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
  1079. }
  1080. return false;
  1081. }
  1082.  
  1083. /**
  1084. * Verifies that the name is recognized by the server.
  1085. * Returns false if the name could not be verified otherwise
  1086. * the response from the server is returned.
  1087. *
  1088. * Implements rfc 821: VRFY <SP> <string> <CRLF>
  1089. *
  1090. * SMTP CODE SUCCESS: 250,251
  1091. * SMTP CODE FAILURE: 550,551,553
  1092. * SMTP CODE ERROR : 500,501,502,421
  1093. * @access public
  1094. * @return int
  1095. */
  1096. function Verify($name) {
  1097. $this->error = null; # so no confusion is caused
  1098.  
  1099. if(!$this->connected()) {
  1100. $this->error = array(
  1101. "error" => "Called Verify() without being connected");
  1102. return false;
  1103. }
  1104.  
  1105. fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
  1106.  
  1107. $rply = $this->get_lines();
  1108. $code = substr($rply,0,3);
  1109.  
  1110. if($this->do_debug >= 2) {
  1111. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  1112. }
  1113.  
  1114. if($code != 250 && $code != 251) {
  1115. $this->error =
  1116. array("error" => "VRFY failed on name '$name'",
  1117. "smtp_code" => $code,
  1118. "smtp_msg" => substr($rply,4));
  1119. if($this->do_debug >= 1) {
  1120. echo "SMTP -> ERROR: " . $this->error["error"] .
  1121. ": " . $rply . $this->CRLF;
  1122. }
  1123. return false;
  1124. }
  1125. return $rply;
  1126. }
  1127.  
  1128. /*******************************************************************
  1129. * INTERNAL FUNCTIONS *
  1130. ******************************************************************/
  1131.  
  1132. /**
  1133. * Read in as many lines as possible
  1134. * either before eof or socket timeout occurs on the operation.
  1135. * With SMTP we can tell if we have more lines to read if the
  1136. * 4th character is '-' symbol. If it is a space then we don't
  1137. * need to read anything else.
  1138. * @access private
  1139. * @return string
  1140. */
  1141. function get_lines() {
  1142. $data = "";
  1143. while($str = @fgets($this->smtp_conn,515)) {
  1144. if($this->do_debug >= 4) {
  1145. echo "SMTP -> get_lines(): \$data was \"$data\"" .
  1146. $this->CRLF;
  1147. echo "SMTP -> get_lines(): \$str is \"$str\"" .
  1148. $this->CRLF;
  1149. }
  1150. $data .= $str;
  1151. if($this->do_debug >= 4) {
  1152. echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
  1153. }
  1154. # if the 4th character is a space then we are done reading
  1155. # so just break the loop
  1156. if(substr($str,3,1) == " ") { break; }
  1157. }
  1158. return $data;
  1159. }
  1160.  
  1161. }
  1162.  
  1163.  
  1164. /*~ class.phpmailer.php
  1165. .---------------------------------------------------------------------------.
  1166. | Software: PHPMailer - PHP email class |
  1167. | Version: 2.0.2 |
  1168. | Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
  1169. | Info: http://phpmailer.sourceforge.net |
  1170. | Support: http://sourceforge.net/projects/phpmailer/ |
  1171. | ------------------------------------------------------------------------- |
  1172. | Author: Andy Prevost (project admininistrator) |
  1173. | Author: Brent R. Matzelle (original founder) |
  1174. | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
  1175. | Copyright (c) 2001-2003, Brent R. Matzelle |
  1176. | ------------------------------------------------------------------------- |
  1177. | License: Distributed under the Lesser General Public License (LGPL) |
  1178. | http://www.gnu.org/copyleft/lesser.html |
  1179. | This program is distributed in the hope that it will be useful - WITHOUT |
  1180. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
  1181. | FITNESS FOR A PARTICULAR PURPOSE. |
  1182. | ------------------------------------------------------------------------- |
  1183. | We offer a number of paid services (www.codeworxtech.com): |
  1184. | - Web Hosting on highly optimized fast and secure servers |
  1185. | - Technology Consulting |
  1186. | - Oursourcing (highly qualified programmers and graphic designers) |
  1187. '---------------------------------------------------------------------------'
  1188.  
  1189. /**
  1190. * PHPMailer - PHP email transport class
  1191. * @package PHPMailer
  1192. * @author Andy Prevost
  1193. * @copyright 2004 - 2008 Andy Prevost
  1194. */
  1195.  
  1196. class PHPMailer {
  1197.  
  1198. /////////////////////////////////////////////////
  1199. // PROPERTIES, PUBLIC
  1200. /////////////////////////////////////////////////
  1201.  
  1202. /**
  1203. * Email priority (1 = High, 3 = Normal, 5 = low).
  1204. * @var int
  1205. */
  1206. var $Priority = 3;
  1207.  
  1208. /**
  1209. * Sets the CharSet of the message.
  1210. * @var string
  1211. */
  1212. var $CharSet = 'iso-8859-1';
  1213.  
  1214. /**
  1215. * Sets the Content-type of the message.
  1216. * @var string
  1217. */
  1218. var $ContentType = 'text/plain';
  1219.  
  1220. /**
  1221. * Sets the Encoding of the message. Options for this are "8bit",
  1222. * "7bit", "binary", "base64", and "quoted-printable".
  1223. * @var string
  1224. */
  1225. var $Encoding = '8bit';
  1226.  
  1227. /**
  1228. * Holds the most recent mailer error message.
  1229. * @var string
  1230. */
  1231. var $ErrorInfo = '';
  1232.  
  1233. /**
  1234. * Sets the From email address for the message.
  1235. * @var string
  1236. */
  1237. var $From = 'root@localhost';
  1238.  
  1239. /**
  1240. * Sets the From name of the message.
  1241. * @var string
  1242. */
  1243. var $FromName = 'Root User';
  1244.  
  1245. /**
  1246. * Sets the Sender email (Return-Path) of the message. If not empty,
  1247. * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  1248. * @var string
  1249. */
  1250. var $Sender = '';
  1251.  
  1252. /**
  1253. * Sets the Subject of the message.
  1254. * @var string
  1255. */
  1256. var $Subject = '';
  1257.  
  1258. /**
  1259. * Sets the Body of the message. This can be either an HTML or text body.
  1260. * If HTML then run IsHTML(true).
  1261. * @var string
  1262. */
  1263. var $Body = '';
  1264.  
  1265. /**
  1266. * Sets the text-only body of the message. This automatically sets the
  1267. * email to multipart/alternative. This body can be read by mail
  1268. * clients that do not have HTML email capability such as mutt. Clients
  1269. * that can read HTML will view the normal Body.
  1270. * @var string
  1271. */
  1272. var $AltBody = '';
  1273.  
  1274. /**
  1275. * Sets word wrapping on the body of the message to a given number of
  1276. * characters.
  1277. * @var int
  1278. */
  1279. var $WordWrap = 0;
  1280.  
  1281. /**
  1282. * Method to send mail: ("mail", "sendmail", or "smtp").
  1283. * @var string
  1284. */
  1285. var $Mailer = 'mail';
  1286.  
  1287. /**
  1288. * Sets the path of the sendmail program.
  1289. * @var string
  1290. */
  1291. var $Sendmail = '/usr/sbin/sendmail';
  1292.  
  1293. /**
  1294. * Path to PHPMailer plugins. This is now only useful if the SMTP class
  1295. * is in a different directory than the PHP include path.
  1296. * @var string
  1297. */
  1298. var $PluginDir = '';
  1299.  
  1300. /**
  1301. * Holds PHPMailer version.
  1302. * @var string
  1303. */
  1304. var $Version = "2.0.2";
  1305.  
  1306. /**
  1307. * Sets the email address that a reading confirmation will be sent.
  1308. * @var string
  1309. */
  1310. var $ConfirmReadingTo = '';
  1311.  
  1312. /**
  1313. * Sets the hostname to use in Message-Id and Received headers
  1314. * and as default HELO string. If empty, the value returned
  1315. * by SERVER_NAME is used or 'localhost.localdomain'.
  1316. * @var string
  1317. */
  1318. var $Hostname = '';
  1319.  
  1320. /**
  1321. * Sets the message ID to be used in the Message-Id header.
  1322. * If empty, a unique id will be generated.
  1323. * @var string
  1324. */
  1325. var $MessageID = '';
  1326.  
  1327. /////////////////////////////////////////////////
  1328. // PROPERTIES FOR SMTP
  1329. /////////////////////////////////////////////////
  1330.  
  1331. /**
  1332. * Sets the SMTP hosts. All hosts must be separated by a
  1333. * semicolon. You can also specify a different port
  1334. * for each host by using this format: [hostname:port]
  1335. * (e.g. "smtp1.example.com:25;smtp2.example.com").
  1336. * Hosts will be tried in order.
  1337. * @var string
  1338. */
  1339. var $Host = 'localhost';
  1340.  
  1341. /**
  1342. * Sets the default SMTP server port.
  1343. * @var int
  1344. */
  1345. var $Port = 25;
  1346.  
  1347. /**
  1348. * Sets the SMTP HELO of the message (Default is $Hostname).
  1349. * @var string
  1350. */
  1351. var $Helo = '';
  1352.  
  1353. /**
  1354. * Sets connection prefix.
  1355. * Options are "", "ssl" or "tls"
  1356. * @var string
  1357. */
  1358. var $SMTPSecure = "";
  1359.  
  1360. /**
  1361. * Sets SMTP authentication. Utilizes the Username and Password variables.
  1362. * @var bool
  1363. */
  1364. var $SMTPAuth = false;
  1365.  
  1366. /**
  1367. * Sets SMTP username.
  1368. * @var string
  1369. */
  1370. var $Username = '';
  1371.  
  1372. /**
  1373. * Sets SMTP password.
  1374. * @var string
  1375. */
  1376. var $Password = '';
  1377.  
  1378. /**
  1379. * Sets the SMTP server timeout in seconds. This function will not
  1380. * work with the win32 version.
  1381. * @var int
  1382. */
  1383. var $Timeout = 10;
  1384.  
  1385. /**
  1386. * Sets SMTP class debugging on or off.
  1387. * @var bool
  1388. */
  1389. var $SMTPDebug = false;
  1390.  
  1391. /**
  1392. * Prevents the SMTP connection from being closed after each mail
  1393. * sending. If this is set to true then to close the connection
  1394. * requires an explicit call to SmtpClose().
  1395. * @var bool
  1396. */
  1397. var $SMTPKeepAlive = false;
  1398.  
  1399. /**
  1400. * Provides the ability to have the TO field process individual
  1401. * emails, instead of sending to entire TO addresses
  1402. * @var bool
  1403. */
  1404. var $SingleTo = false;
  1405.  
  1406. /////////////////////////////////////////////////
  1407. // PROPERTIES, PRIVATE
  1408. /////////////////////////////////////////////////
  1409.  
  1410. var $smtp = NULL;
  1411. var $to = array();
  1412. var $cc = array();
  1413. var $bcc = array();
  1414. var $ReplyTo = array();
  1415. var $attachment = array();
  1416. var $CustomHeader = array();
  1417. var $message_type = '';
  1418. var $boundary = array();
  1419. var $language = array();
  1420. var $error_count = 0;
  1421. var $LE = "\n";
  1422. var $sign_key_file = "";
  1423. var $sign_key_pass = "";
  1424.  
  1425. /////////////////////////////////////////////////
  1426. // METHODS, VARIABLES
  1427. /////////////////////////////////////////////////
  1428.  
  1429. /**
  1430. * Sets message type to HTML.
  1431. * @param bool $bool
  1432. * @return void
  1433. */
  1434. function IsHTML($bool) {
  1435. if($bool == true) {
  1436. $this->ContentType = 'text/html';
  1437. } else {
  1438. $this->ContentType = 'text/plain';
  1439. }
  1440. }
  1441.  
  1442. /**
  1443. * Sets Mailer to send message using SMTP.
  1444. * @return void
  1445. */
  1446. function IsSMTP() {
  1447. $this->Mailer = 'smtp';
  1448. }
  1449.  
  1450. /**
  1451. * Sets Mailer to send message using PHP mail() function.
  1452. * @return void
  1453. */
  1454. function IsMail() {
  1455. $this->Mailer = 'mail';
  1456. }
  1457.  
  1458. /**
  1459. * Sets Mailer to send message using the $Sendmail program.
  1460. * @return void
  1461. */
  1462. function IsSendmail() {
  1463. $this->Mailer = 'sendmail';
  1464. }
  1465.  
  1466. /**
  1467. * Sets Mailer to send message using the qmail MTA.
  1468. * @return void
  1469. */
  1470. function IsQmail() {
  1471. $this->Sendmail = '/var/qmail/bin/sendmail';
  1472. $this->Mailer = 'sendmail';
  1473. }
  1474.  
  1475. /////////////////////////////////////////////////
  1476. // METHODS, RECIPIENTS
  1477. /////////////////////////////////////////////////
  1478.  
  1479. /**
  1480. * Adds a "To" address.
  1481. * @param string $address
  1482. * @param string $name
  1483. * @return void
  1484. */
  1485. function AddAddress($address, $name = '') {
  1486. $cur = count($this->to);
  1487. $this->to[$cur][0] = trim($address);
  1488. $this->to[$cur][1] = $name;
  1489. }
  1490.  
  1491. /**
  1492. * Adds a "Cc" address. Note: this function works
  1493. * with the SMTP mailer on win32, not with the "mail"
  1494. * mailer.
  1495. * @param string $address
  1496. * @param string $name
  1497. * @return void
  1498. */
  1499. function AddCC($address, $name = '') {
  1500. $cur = count($this->cc);
  1501. $this->cc[$cur][0] = trim($address);
  1502. $this->cc[$cur][1] = $name;
  1503. }
  1504.  
  1505. /**
  1506. * Adds a "Bcc" address. Note: this function works
  1507. * with the SMTP mailer on win32, not with the "mail"
  1508. * mailer.
  1509. * @param string $address
  1510. * @param string $name
  1511. * @return void
  1512. */
  1513. function AddBCC($address, $name = '') {
  1514. $cur = count($this->bcc);
  1515. $this->bcc[$cur][0] = trim($address);
  1516. $this->bcc[$cur][1] = $name;
  1517. }
  1518.  
  1519. /**
  1520. * Adds a "Reply-To" address.
  1521. * @param string $address
  1522. * @param string $name
  1523. * @return void
  1524. */
  1525. function AddReplyTo($address, $name = '') {
  1526. $cur = count($this->ReplyTo);
  1527. $this->ReplyTo[$cur][0] = trim($address);
  1528. $this->ReplyTo[$cur][1] = $name;
  1529. }
  1530.  
  1531. /////////////////////////////////////////////////
  1532. // METHODS, MAIL SENDING
  1533. /////////////////////////////////////////////////
  1534.  
  1535. /**
  1536. * Creates message and assigns Mailer. If the message is
  1537. * not sent successfully then it returns false. Use the ErrorInfo
  1538. * variable to view description of the error.
  1539. * @return bool
  1540. */
  1541. function Send() {
  1542. $header = '';
  1543. $body = '';
  1544. $result = true;
  1545.  
  1546. if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  1547. $this->SetError($this->Lang('provide_address'));
  1548. return false;
  1549. }
  1550.  
  1551. /* Set whether the message is multipart/alternative */
  1552. if(!empty($this->AltBody)) {
  1553. $this->ContentType = 'multipart/alternative';
  1554. }
  1555.  
  1556. $this->error_count = 0; // reset errors
  1557. $this->SetMessageType();
  1558. $header .= $this->CreateHeader();
  1559. $body = $this->CreateBody();
  1560.  
  1561. if($body == '') {
  1562. return false;
  1563. }
  1564.  
  1565. /* Choose the mailer */
  1566. switch($this->Mailer) {
  1567. case 'sendmail':
  1568. $result = $this->SendmailSend($header, $body);
  1569. break;
  1570. case 'smtp':
  1571. $result = $this->SmtpSend($header, $body);
  1572. break;
  1573. case 'mail':
  1574. $result = $this->MailSend($header, $body);
  1575. break;
  1576. default:
  1577. $result = $this->MailSend($header, $body);
  1578. break;
  1579. //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
  1580. //$result = false;
  1581. //break;
  1582. }
  1583.  
  1584. return $result;
  1585. }
  1586.  
  1587. /**
  1588. * Sends mail using the $Sendmail program.
  1589. * @access private
  1590. * @return bool
  1591. */
  1592. function SendmailSend($header, $body) {
  1593. if ($this->Sender != '') {
  1594. $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  1595. } else {
  1596. $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
  1597. }
  1598.  
  1599. if(!@$mail = popen($sendmail, 'w')) {
  1600. $this->SetError($this->Lang('execute') . $this->Sendmail);
  1601. return false;
  1602. }
  1603.  
  1604. fputs($mail, $header);
  1605. fputs($mail, $body);
  1606.  
  1607. $result = pclose($mail);
  1608. if (version_compare(phpversion(), '4.2.3') == -1) {
  1609. $result = $result >> 8 & 0xFF;
  1610. }
  1611. if($result != 0) {
  1612. $this->SetError($this->Lang('execute') . $this->Sendmail);
  1613. return false;
  1614. }
  1615. return true;
  1616. }
  1617.  
  1618. /**
  1619. * Sends mail using the PHP mail() function.
  1620. * @access private
  1621. * @return bool
  1622. */
  1623. function MailSend($header, $body) {
  1624.  
  1625. $to = '';
  1626. for($i = 0; $i < count($this->to); $i++) {
  1627. if($i != 0) { $to .= ', '; }
  1628. $to .= $this->AddrFormat($this->to[$i]);
  1629. }
  1630.  
  1631. $toArr = split(',', $to);
  1632.  
  1633. $params = sprintf("-oi -f %s", $this->Sender);
  1634. if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
  1635. $old_from = ini_get('sendmail_from');
  1636. ini_set('sendmail_from', $this->Sender);
  1637. if ($this->SingleTo === true && count($toArr) > 1) {
  1638. foreach ($toArr as $key => $val) {
  1639. $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  1640. }
  1641. } else {
  1642. $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  1643. }
  1644. } else {
  1645. if ($this->SingleTo === true && count($toArr) > 1) {
  1646. foreach ($toArr as $key => $val) {
  1647. $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  1648. }
  1649. } else {
  1650. $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
  1651. }
  1652. }
  1653.  
  1654. if (isset($old_from)) {
  1655. ini_set('sendmail_from', $old_from);
  1656. }
  1657.  
  1658. if(!$rt) {
  1659. $this->SetError($this->Lang('instantiate'));
  1660. return false;
  1661. }
  1662.  
  1663. return true;
  1664. }
  1665.  
  1666. /**
  1667. * Sends mail via SMTP using PhpSMTP (Author:
  1668. * Chris Ryan). Returns bool. Returns false if there is a
  1669. * bad MAIL FROM, RCPT, or DATA input.
  1670. * @access private
  1671. * @return bool
  1672. */
  1673. function SmtpSend($header, $body) {
  1674. include_once($this->PluginDir . 'class.smtp.php');
  1675. $error = '';
  1676. $bad_rcpt = array();
  1677.  
  1678. if(!$this->SmtpConnect()) {
  1679. return false;
  1680. }
  1681.  
  1682. $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
  1683. if(!$this->smtp->Mail($smtp_from)) {
  1684. $error = $this->Lang('from_failed') . $smtp_from;
  1685. $this->SetError($error);
  1686. $this->smtp->Reset();
  1687. return false;
  1688. }
  1689.  
  1690. /* Attempt to send attach all recipients */
  1691. for($i = 0; $i < count($this->to); $i++) {
  1692. if(!$this->smtp->Recipient($this->to[$i][0])) {
  1693. $bad_rcpt[] = $this->to[$i][0];
  1694. }
  1695. }
  1696. for($i = 0; $i < count($this->cc); $i++) {
  1697. if(!$this->smtp->Recipient($this->cc[$i][0])) {
  1698. $bad_rcpt[] = $this->cc[$i][0];
  1699. }
  1700. }
  1701. for($i = 0; $i < count($this->bcc); $i++) {
  1702. if(!$this->smtp->Recipient($this->bcc[$i][0])) {
  1703. $bad_rcpt[] = $this->bcc[$i][0];
  1704. }
  1705. }
  1706.  
  1707. if(count($bad_rcpt) > 0) { // Create error message
  1708. for($i = 0; $i < count($bad_rcpt); $i++) {
  1709. if($i != 0) {
  1710. $error .= ', ';
  1711. }
  1712. $error .= $bad_rcpt[$i];
  1713. }
  1714. $error = $this->Lang('recipients_failed') . $error;
  1715. $this->SetError($error);
  1716. $this->smtp->Reset();
  1717. return false;
  1718. }
  1719.  
  1720. if(!$this->smtp->Data($header . $body)) {
  1721. $this->SetError($this->Lang('data_not_accepted'));
  1722. $this->smtp->Reset();
  1723. return false;
  1724. }
  1725. if($this->SMTPKeepAlive == true) {
  1726. $this->smtp->Reset();
  1727. } else {
  1728. $this->SmtpClose();
  1729. }
  1730.  
  1731. return true;
  1732. }
  1733.  
  1734. /**
  1735. * Initiates a connection to an SMTP server. Returns false if the
  1736. * operation failed.
  1737. * @access private
  1738. * @return bool
  1739. */
  1740. function SmtpConnect() {
  1741. if($this->smtp == NULL) {
  1742. $this->smtp = new SMTP();
  1743. }
  1744.  
  1745. $this->smtp->do_debug = $this->SMTPDebug;
  1746. $hosts = explode(';', $this->Host);
  1747. $index = 0;
  1748. $connection = ($this->smtp->Connected());
  1749.  
  1750. /* Retry while there is no connection */
  1751. while($index < count($hosts) && $connection == false) {
  1752. $hostinfo = array();
  1753. if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
  1754. $host = $hostinfo[1];
  1755. $port = $hostinfo[2];
  1756. } else {
  1757. $host = $hosts[$index];
  1758. $port = $this->Port;
  1759. }
  1760.  
  1761. if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
  1762. if ($this->Helo != '') {
  1763. $this->smtp->Hello($this->Helo);
  1764. } else {
  1765. $this->smtp->Hello($this->ServerHostname());
  1766. }
  1767.  
  1768. $connection = true;
  1769. if($this->SMTPAuth) {
  1770. if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
  1771. $this->SetError($this->Lang('authenticate'));
  1772. $this->smtp->Reset();
  1773. $connection = false;
  1774. }
  1775. }
  1776. }
  1777. $index++;
  1778. }
  1779. if(!$connection) {
  1780. $this->SetError($this->Lang('connect_host'));
  1781. }
  1782.  
  1783. return $connection;
  1784. }
  1785.  
  1786. /**
  1787. * Closes the active SMTP session if one exists.
  1788. * @return void
  1789. */
  1790. function SmtpClose() {
  1791. if($this->smtp != NULL) {
  1792. if($this->smtp->Connected()) {
  1793. $this->smtp->Quit();
  1794. $this->smtp->Close();
  1795. }
  1796. }
  1797. }
  1798.  
  1799. /**
  1800. * Sets the language for all class error messages. Returns false
  1801. * if it cannot load the language file. The default language type
  1802. * is English.
  1803. * @param string $lang_type Type of language (e.g. Portuguese: "br")
  1804. * @param string $lang_path Path to the language file directory
  1805. * @access public
  1806. * @return bool
  1807. */
  1808. function SetLanguage($lang_type, $lang_path = 'language/') {
  1809. if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
  1810. include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
  1811. } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
  1812. include($lang_path.'phpmailer.lang-en.php');
  1813. } else {
  1814. $this->SetError('Could not load language file');
  1815. return false;
  1816. }
  1817. $this->language = $PHPMAILER_LANG;
  1818.  
  1819. return true;
  1820. }
  1821.  
  1822. /////////////////////////////////////////////////
  1823. // METHODS, MESSAGE CREATION
  1824. /////////////////////////////////////////////////
  1825.  
  1826. /**
  1827. * Creates recipient headers.
  1828. * @access private
  1829. * @return string
  1830. */
  1831. function AddrAppend($type, $addr) {
  1832. $addr_str = $type . ': ';
  1833. $addr_str .= $this->AddrFormat($addr[0]);
  1834. if(count($addr) > 1) {
  1835. for($i = 1; $i < count($addr); $i++) {
  1836. $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
  1837. }
  1838. }
  1839. $addr_str .= $this->LE;
  1840.  
  1841. return $addr_str;
  1842. }
  1843.  
  1844. /**
  1845. * Formats an address correctly.
  1846. * @access private
  1847. * @return string
  1848. */
  1849. function AddrFormat($addr) {
  1850. if(empty($addr[1])) {
  1851. $formatted = $this->SecureHeader($addr[0]);
  1852. } else {
  1853. $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
  1854. }
  1855.  
  1856. return $formatted;
  1857. }
  1858.  
  1859. /**
  1860. * Wraps message for use with mailers that do not
  1861. * automatically perform wrapping and for quoted-printable.
  1862. * Original written by philippe.
  1863. * @access private
  1864. * @return string
  1865. */
  1866. function WrapText($message, $length, $qp_mode = false) {
  1867. $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  1868. // If utf-8 encoding is used, we will need to make sure we don't
  1869. // split multibyte characters when we wrap
  1870. $is_utf8 = (strtolower($this->CharSet) == "utf-8");
  1871.  
  1872. $message = $this->FixEOL($message);
  1873. if (substr($message, -1) == $this->LE) {
  1874. $message = substr($message, 0, -1);
  1875. }
  1876.  
  1877. $line = explode($this->LE, $message);
  1878. $message = '';
  1879. for ($i=0 ;$i < count($line); $i++) {
  1880. $line_part = explode(' ', $line[$i]);
  1881. $buf = '';
  1882. for ($e = 0; $e<count($line_part); $e++) {
  1883. $word = $line_part[$e];
  1884. if ($qp_mode and (strlen($word) > $length)) {
  1885. $space_left = $length - strlen($buf) - 1;
  1886. if ($e != 0) {
  1887. if ($space_left > 20) {
  1888. $len = $space_left;
  1889. if ($is_utf8) {
  1890. $len = $this->UTF8CharBoundary($word, $len);
  1891. } elseif (substr($word, $len - 1, 1) == "=") {
  1892. $len--;
  1893. } elseif (substr($word, $len - 2, 1) == "=") {
  1894. $len -= 2;
  1895. }
  1896. $part = substr($word, 0, $len);
  1897. $word = substr($word, $len);
  1898. $buf .= ' ' . $part;
  1899. $message .= $buf . sprintf("=%s", $this->LE);
  1900. } else {
  1901. $message .= $buf . $soft_break;
  1902. }
  1903. $buf = '';
  1904. }
  1905. while (strlen($word) > 0) {
  1906. $len = $length;
  1907. if ($is_utf8) {
  1908. $len = $this->UTF8CharBoundary($word, $len);
  1909. } elseif (substr($word, $len - 1, 1) == "=") {
  1910. $len--;
  1911. } elseif (substr($word, $len - 2, 1) == "=") {
  1912. $len -= 2;
  1913. }
  1914. $part = substr($word, 0, $len);
  1915. $word = substr($word, $len);
  1916.  
  1917. if (strlen($word) > 0) {
  1918. $message .= $part . sprintf("=%s", $this->LE);
  1919. } else {
  1920. $buf = $part;
  1921. }
  1922. }
  1923. } else {
  1924. $buf_o = $buf;
  1925. $buf .= ($e == 0) ? $word : (' ' . $word);
  1926.  
  1927. if (strlen($buf) > $length and $buf_o != '') {
  1928. $message .= $buf_o . $soft_break;
  1929. $buf = $word;
  1930. }
  1931. }
  1932. }
  1933. $message .= $buf . $this->LE;
  1934. }
  1935.  
  1936. return $message;
  1937. }
  1938.  
  1939. /**
  1940. * Finds last character boundary prior to maxLength in a utf-8
  1941. * quoted (printable) encoded string.
  1942. * Original written by Colin Brown.
  1943. * @access private
  1944. * @param string $encodedText utf-8 QP text
  1945. * @param int $maxLength find last character boundary prior to this length
  1946. * @return int
  1947. */
  1948. function UTF8CharBoundary($encodedText, $maxLength) {
  1949. $foundSplitPos = false;
  1950. $lookBack = 3;
  1951. while (!$foundSplitPos) {
  1952. $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  1953. $encodedCharPos = strpos($lastChunk, "=");
  1954. if ($encodedCharPos !== false) {
  1955. // Found start of encoded character byte within $lookBack block.
  1956. // Check the encoded byte value (the 2 chars after the '=')
  1957. $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  1958. $dec = hexdec($hex);
  1959. if ($dec < 128) { // Single byte character.
  1960. // If the encoded char was found at pos 0, it will fit
  1961. // otherwise reduce maxLength to start of the encoded char
  1962. $maxLength = ($encodedCharPos == 0) ? $maxLength :
  1963. $maxLength - ($lookBack - $encodedCharPos);
  1964. $foundSplitPos = true;
  1965. } elseif ($dec >= 192) { // First byte of a multi byte character
  1966. // Reduce maxLength to split at start of character
  1967. $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  1968. $foundSplitPos = true;
  1969. } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
  1970. $lookBack += 3;
  1971. }
  1972. } else {
  1973. // No encoded character found
  1974. $foundSplitPos = true;
  1975. }
  1976. }
  1977. return $maxLength;
  1978. }
  1979.  
  1980. /**
  1981. * Set the body wrapping.
  1982. * @access private
  1983. * @return void
  1984. */
  1985. function SetWordWrap() {
  1986. if($this->WordWrap < 1) {
  1987. return;
  1988. }
  1989.  
  1990. switch($this->message_type) {
  1991. case 'alt':
  1992. /* fall through */
  1993. case 'alt_attachments':
  1994. $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  1995. break;
  1996. default:
  1997. $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  1998. break;
  1999. }
  2000. }
  2001.  
  2002. /**
  2003. * Assembles message header.
  2004. * @access private
  2005. * @return string
  2006. */
  2007. function CreateHeader() {
  2008. $result = '';
  2009.  
  2010. /* Set the boundaries */
  2011. $uniq_id = md5(uniqid(time()));
  2012. $this->boundary[1] = 'b1_' . $uniq_id;
  2013. $this->boundary[2] = 'b2_' . $uniq_id;
  2014.  
  2015. $result .= $this->HeaderLine('Date', $this->RFCDate());
  2016. if($this->Sender == '') {
  2017. $result .= $this->HeaderLine('Return-Path', trim($this->From));
  2018. } else {
  2019. $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
  2020. }
  2021.  
  2022. /* To be created automatically by mail() */
  2023. if($this->Mailer != 'mail') {
  2024. if(count($this->to) > 0) {
  2025. $result .= $this->AddrAppend('To', $this->to);
  2026. } elseif (count($this->cc) == 0) {
  2027. $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
  2028. }
  2029. if(count($this->cc) > 0) {
  2030. $result .= $this->AddrAppend('Cc', $this->cc);
  2031. }
  2032. }
  2033.  
  2034. $from = array();
  2035. $from[0][0] = trim($this->From);
  2036. $from[0][1] = $this->FromName;
  2037. $result .= $this->AddrAppend('From', $from);
  2038.  
  2039. /* sendmail and mail() extract Cc from the header before sending */
  2040. if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
  2041. $result .= $this->AddrAppend('Cc', $this->cc);
  2042. }
  2043.  
  2044. /* sendmail and mail() extract Bcc from the header before sending */
  2045. if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
  2046. $result .= $this->AddrAppend('Bcc', $this->bcc);
  2047. }
  2048.  
  2049. if(count($this->ReplyTo) > 0) {
  2050. $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
  2051. }
  2052.  
  2053. /* mail() sets the subject itself */
  2054. if($this->Mailer != 'mail') {
  2055. $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
  2056. }
  2057.  
  2058. if($this->MessageID != '') {
  2059. $result .= $this->HeaderLine('Message-ID',$this->MessageID);
  2060. } else {
  2061. $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  2062. }
  2063. $result .= $this->HeaderLine('X-Priority', $this->Priority);
  2064. $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
  2065.  
  2066. if($this->ConfirmReadingTo != '') {
  2067. $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  2068. }
  2069.  
  2070. // Add custom headers
  2071. for($index = 0; $index < count($this->CustomHeader); $index++) {
  2072. $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  2073. }
  2074. if (!$this->sign_key_file) {
  2075. $result .= $this->HeaderLine('MIME-Version', '1.0');
  2076. $result .= $this->GetMailMIME();
  2077. }
  2078.  
  2079. return $result;
  2080. }
  2081.  
  2082. /**
  2083. * Returns the message MIME.
  2084. * @access private
  2085. * @return string
  2086. */
  2087. function GetMailMIME() {
  2088. $result = '';
  2089. switch($this->message_type) {
  2090. case 'plain':
  2091. $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
  2092. $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
  2093. break;
  2094. case 'attachments':
  2095. /* fall through */
  2096. case 'alt_attachments':
  2097. if($this->InlineImageExists()){
  2098. $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
  2099. } else {
  2100. $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
  2101. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  2102. }
  2103. break;
  2104. case 'alt':
  2105. $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
  2106. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  2107. break;
  2108. }
  2109.  
  2110. if($this->Mailer != 'mail') {
  2111. $result .= $this->LE.$this->LE;
  2112. }
  2113.  
  2114. return $result;
  2115. }
  2116.  
  2117. /**
  2118. * Assembles the message body. Returns an empty string on failure.
  2119. * @access private
  2120. * @return string
  2121. */
  2122. function CreateBody() {
  2123. $result = '';
  2124. if ($this->sign_key_file) {
  2125. $result .= $this->GetMailMIME();
  2126. }
  2127.  
  2128. $this->SetWordWrap();
  2129.  
  2130. switch($this->message_type) {
  2131. case 'alt':
  2132. $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
  2133. $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  2134. $result .= $this->LE.$this->LE;
  2135. $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
  2136. $result .= $this->EncodeString($this->Body, $this->Encoding);
  2137. $result .= $this->LE.$this->LE;
  2138. $result .= $this->EndBoundary($this->boundary[1]);
  2139. break;
  2140. case 'plain':
  2141. $result .= $this->EncodeString($this->Body, $this->Encoding);
  2142. break;
  2143. case 'attachments':
  2144. $result .= $this->GetBoundary($this->boundary[1], '', '', '');
  2145. $result .= $this->EncodeString($this->Body, $this->Encoding);
  2146. $result .= $this->LE;
  2147. $result .= $this->AttachAll();
  2148. break;
  2149. case 'alt_attachments':
  2150. $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
  2151. $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
  2152. $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
  2153. $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  2154. $result .= $this->LE.$this->LE;
  2155. $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
  2156. $result .= $this->EncodeString($this->Body, $this->Encoding);
  2157. $result .= $this->LE.$this->LE;
  2158. $result .= $this->EndBoundary($this->boundary[2]);
  2159. $result .= $this->AttachAll();
  2160. break;
  2161. }
  2162.  
  2163. if($this->IsError()) {
  2164. $result = '';
  2165. } else if ($this->sign_key_file) {
  2166. $file = tempnam("", "mail");
  2167. $fp = fopen($file, "w");
  2168. fwrite($fp, $result);
  2169. fclose($fp);
  2170. $signed = tempnam("", "signed");
  2171.  
  2172. if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_key_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
  2173. $fp = fopen($signed, "r");
  2174. $result = fread($fp, filesize($this->sign_key_file));
  2175. fclose($fp);
  2176. } else {
  2177. $this->SetError($this->Lang("signing").openssl_error_string());
  2178. $result = '';
  2179. }
  2180.  
  2181. unlink($file);
  2182. unlink($signed);
  2183. }
  2184.  
  2185. return $result;
  2186. }
  2187.  
  2188. /**
  2189. * Returns the start of a message boundary.
  2190. * @access private
  2191. */
  2192. function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  2193. $result = '';
  2194. if($charSet == '') {
  2195. $charSet = $this->CharSet;
  2196. }
  2197. if($contentType == '') {
  2198. $contentType = $this->ContentType;
  2199. }
  2200. if($encoding == '') {
  2201. $encoding = $this->Encoding;
  2202. }
  2203. $result .= $this->TextLine('--' . $boundary);
  2204. $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
  2205. $result .= $this->LE;
  2206. $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
  2207. $result .= $this->LE;
  2208.  
  2209. return $result;
  2210. }
  2211.  
  2212. /**
  2213. * Returns the end of a message boundary.
  2214. * @access private
  2215. */
  2216. function EndBoundary($boundary) {
  2217. return $this->LE . '--' . $boundary . '--' . $this->LE;
  2218. }
  2219.  
  2220. /**
  2221. * Sets the message type.
  2222. * @access private
  2223. * @return void
  2224. */
  2225. function SetMessageType() {
  2226. if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
  2227. $this->message_type = 'plain';
  2228. } else {
  2229. if(count($this->attachment) > 0) {
  2230. $this->message_type = 'attachments';
  2231. }
  2232. if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
  2233. $this->message_type = 'alt';
  2234. }
  2235. if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
  2236. $this->message_type = 'alt_attachments';
  2237. }
  2238. }
  2239. }
  2240.  
  2241. /* Returns a formatted header line.
  2242. * @access private
  2243. * @return string
  2244. */
  2245. function HeaderLine($name, $value) {
  2246. return $name . ': ' . $value . $this->LE;
  2247. }
  2248.  
  2249. /**
  2250. * Returns a formatted mail line.
  2251. * @access private
  2252. * @return string
  2253. */
  2254. function TextLine($value) {
  2255. return $value . $this->LE;
  2256. }
  2257.  
  2258. /////////////////////////////////////////////////
  2259. // CLASS METHODS, ATTACHMENTS
  2260. /////////////////////////////////////////////////
  2261.  
  2262. /**
  2263. * Adds an attachment from a path on the filesystem.
  2264. * Returns false if the file could not be found
  2265. * or accessed.
  2266. * @param string $path Path to the attachment.
  2267. * @param string $name Overrides the attachment name.
  2268. * @param string $encoding File encoding (see $Encoding).
  2269. * @param string $type File extension (MIME) type.
  2270. * @return bool
  2271. */
  2272. function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  2273. if(!@is_file($path)) {
  2274. $this->SetError($this->Lang('file_access') . $path);
  2275. return false;
  2276. }
  2277.  
  2278. $filename = basename($path);
  2279. if($name == '') {
  2280. $name = $filename;
  2281. }
  2282.  
  2283. $cur = count($this->attachment);
  2284. $this->attachment[$cur][0] = $path;
  2285. $this->attachment[$cur][1] = $filename;
  2286. $this->attachment[$cur][2] = $name;
  2287. $this->attachment[$cur][3] = $encoding;
  2288. $this->attachment[$cur][4] = $type;
  2289. $this->attachment[$cur][5] = false; // isStringAttachment
  2290. $this->attachment[$cur][6] = 'attachment';
  2291. $this->attachment[$cur][7] = 0;
  2292.  
  2293. return true;
  2294. }
  2295.  
  2296. /**
  2297. * Attaches all fs, string, and binary attachments to the message.
  2298. * Returns an empty string on failure.
  2299. * @access private
  2300. * @return string
  2301. */
  2302. function AttachAll() {
  2303. /* Return text of body */
  2304. $mime = array();
  2305.  
  2306. /* Add all attachments */
  2307. for($i = 0; $i < count($this->attachment); $i++) {
  2308. /* Check for string attachment */
  2309. $bString = $this->attachment[$i][5];
  2310. if ($bString) {
  2311. $string = $this->attachment[$i][0];
  2312. } else {
  2313. $path = $this->attachment[$i][0];
  2314. }
  2315.  
  2316. $filename = $this->attachment[$i][1];
  2317. $name = $this->attachment[$i][2];
  2318. $encoding = $this->attachment[$i][3];
  2319. $type = $this->attachment[$i][4];
  2320. $disposition = $this->attachment[$i][6];
  2321. $cid = $this->attachment[$i][7];
  2322.  
  2323. $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
  2324. $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
  2325. $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  2326.  
  2327. if($disposition == 'inline') {
  2328. $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  2329. }
  2330.  
  2331. $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
  2332.  
  2333. /* Encode as string attachment */
  2334. if($bString) {
  2335. $mime[] = $this->EncodeString($string, $encoding);
  2336. if($this->IsError()) {
  2337. return '';
  2338. }
  2339. $mime[] = $this->LE.$this->LE;
  2340. } else {
  2341. $mime[] = $this->EncodeFile($path, $encoding);
  2342. if($this->IsError()) {
  2343. return '';
  2344. }
  2345. $mime[] = $this->LE.$this->LE;
  2346. }
  2347. }
  2348.  
  2349. $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
  2350.  
  2351. return join('', $mime);
  2352. }
  2353.  
  2354. /**
  2355. * Encodes attachment in requested format. Returns an
  2356. * empty string on failure.
  2357. * @access private
  2358. * @return string
  2359. */
  2360. function EncodeFile ($path, $encoding = 'base64') {
  2361. if(!@$fd = fopen($path, 'rb')) {
  2362. $this->SetError($this->Lang('file_open') . $path);
  2363. return '';
  2364. }
  2365. $magic_quotes = get_magic_quotes_runtime();
  2366. set_magic_quotes_runtime(0);
  2367. $file_buffer = fread($fd, filesize($path));
  2368. $file_buffer = $this->EncodeString($file_buffer, $encoding);
  2369. fclose($fd);
  2370. set_magic_quotes_runtime($magic_quotes);
  2371.  
  2372. return $file_buffer;
  2373. }
  2374.  
  2375. /**
  2376. * Encodes string to requested format. Returns an
  2377. * empty string on failure.
  2378. * @access private
  2379. * @return string
  2380. */
  2381. function EncodeString ($str, $encoding = 'base64') {
  2382. $encoded = '';
  2383. switch(strtolower($encoding)) {
  2384. case 'base64':
  2385. /* chunk_split is found in PHP >= 3.0.6 */
  2386. $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  2387. break;
  2388. case '7bit':
  2389. case '8bit':
  2390. $encoded = $this->FixEOL($str);
  2391. if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  2392. $encoded .= $this->LE;
  2393. break;
  2394. case 'binary':
  2395. $encoded = $str;
  2396. break;
  2397. case 'quoted-printable':
  2398. $encoded = $this->EncodeQP($str);
  2399. break;
  2400. default:
  2401. $this->SetError($this->Lang('encoding') . $encoding);
  2402. break;
  2403. }
  2404. return $encoded;
  2405. }
  2406.  
  2407. /**
  2408. * Encode a header string to best of Q, B, quoted or none.
  2409. * @access private
  2410. * @return string
  2411. */
  2412. function EncodeHeader ($str, $position = 'text') {
  2413. $x = 0;
  2414.  
  2415. switch (strtolower($position)) {
  2416. case 'phrase':
  2417. if (!preg_match('/[\200-\377]/', $str)) {
  2418. /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
  2419. $encoded = addcslashes($str, "\0..\37\177\\\"");
  2420. if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  2421. return ($encoded);
  2422. } else {
  2423. return ("\"$encoded\"");
  2424. }
  2425. }
  2426. $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  2427. break;
  2428. case 'comment':
  2429. $x = preg_match_all('/[()"]/', $str, $matches);
  2430. /* Fall-through */
  2431. case 'text':
  2432. default:
  2433. $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  2434. break;
  2435. }
  2436.  
  2437. if ($x == 0) {
  2438. return ($str);
  2439. }
  2440.  
  2441. $maxlen = 75 - 7 - strlen($this->CharSet);
  2442. /* Try to select the encoding which should produce the shortest output */
  2443. if (strlen($str)/3 < $x) {
  2444. $encoding = 'B';
  2445. if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
  2446. // Use a custom function which correctly encodes and wraps long
  2447. // multibyte strings without breaking lines within a character
  2448. $encoded = $this->Base64EncodeWrapMB($str);
  2449. } else {
  2450. $encoded = base64_encode($str);
  2451. $maxlen -= $maxlen % 4;
  2452. $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  2453. }
  2454. } else {
  2455. $encoding = 'Q';
  2456. $encoded = $this->EncodeQ($str, $position);
  2457. $encoded = $this->WrapText($encoded, $maxlen, true);
  2458. $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
  2459. }
  2460.  
  2461. $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  2462. $encoded = trim(str_replace("\n", $this->LE, $encoded));
  2463.  
  2464. return $encoded;
  2465. }
  2466.  
  2467. /**
  2468. * Checks if a string contains multibyte characters.
  2469. * @access private
  2470. * @param string $str multi-byte text to wrap encode
  2471. * @return bool
  2472. */
  2473. function HasMultiBytes($str) {
  2474. if (function_exists('mb_strlen')) {
  2475. return (strlen($str) > mb_strlen($str, $this->CharSet));
  2476. } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  2477. return False;
  2478. }
  2479. }
  2480.  
  2481. /**
  2482. * Correctly encodes and wraps long multibyte strings for mail headers
  2483. * without breaking lines within a character.
  2484. * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
  2485. * @access private
  2486. * @param string $str multi-byte text to wrap encode
  2487. * @return string
  2488. */
  2489. function Base64EncodeWrapMB($str) {
  2490. $start = "=?".$this->CharSet."?B?";
  2491. $end = "?=";
  2492. $encoded = "";
  2493.  
  2494. $mb_length = mb_strlen($str, $this->CharSet);
  2495. // Each line must have length <= 75, including $start and $end
  2496. $length = 75 - strlen($start) - strlen($end);
  2497. // Average multi-byte ratio
  2498. $ratio = $mb_length / strlen($str);
  2499. // Base64 has a 4:3 ratio
  2500. $offset = $avgLength = floor($length * $ratio * .75);
  2501.  
  2502. for ($i = 0; $i < $mb_length; $i += $offset) {
  2503. $lookBack = 0;
  2504.  
  2505. do {
  2506. $offset = $avgLength - $lookBack;
  2507. $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  2508. $chunk = base64_encode($chunk);
  2509. $lookBack++;
  2510. }
  2511. while (strlen($chunk) > $length);
  2512.  
  2513. $encoded .= $chunk . $this->LE;
  2514. }
  2515.  
  2516. // Chomp the last linefeed
  2517. $encoded = substr($encoded, 0, -strlen($this->LE));
  2518. return $encoded;
  2519. }
  2520.  
  2521. /**
  2522. * Encode string to quoted-printable.
  2523. * @access private
  2524. * @return string
  2525. */
  2526. function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
  2527. $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  2528. $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
  2529. $eol = "\r\n";
  2530. $escape = '=';
  2531. $output = '';
  2532. while( list(, $line) = each($lines) ) {
  2533. $linlen = strlen($line);
  2534. $newline = '';
  2535. for($i = 0; $i < $linlen; $i++) {
  2536. $c = substr( $line, $i, 1 );
  2537. $dec = ord( $c );
  2538. if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
  2539. $c = '=2E';
  2540. }
  2541. if ( $dec == 32 ) {
  2542. if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
  2543. $c = '=20';
  2544. } else if ( $space_conv ) {
  2545. $c = '=20';
  2546. }
  2547. } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
  2548. $h2 = floor($dec/16);
  2549. $h1 = floor($dec%16);
  2550. $c = $escape.$hex[$h2].$hex[$h1];
  2551. }
  2552. if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
  2553. $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
  2554. $newline = '';
  2555. // check if newline first character will be point or not
  2556. if ( $dec == 46 ) {
  2557. $c = '=2E';
  2558. }
  2559. }
  2560. $newline .= $c;
  2561. } // end of for
  2562. $output .= $newline.$eol;
  2563. } // end of while
  2564. return trim($output);
  2565. }
  2566.  
  2567. /**
  2568. * Encode string to q encoding.
  2569. * @access private
  2570. * @return string
  2571. */
  2572. function EncodeQ ($str, $position = 'text') {
  2573. /* There should not be any EOL in the string */
  2574. $encoded = preg_replace("[\r\n]", '', $str);
  2575.  
  2576. switch (strtolower($position)) {
  2577. case 'phrase':
  2578. $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  2579. break;
  2580. case 'comment':
  2581. $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  2582. case 'text':
  2583. default:
  2584. /* Replace every high ascii, control =, ? and _ characters */
  2585. $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
  2586. "'='.sprintf('%02X', ord('\\1'))", $encoded);
  2587. break;
  2588. }
  2589.  
  2590. /* Replace every spaces to _ (more readable than =20) */
  2591. $encoded = str_replace(' ', '_', $encoded);
  2592.  
  2593. return $encoded;
  2594. }
  2595.  
  2596. /**
  2597. * Adds a string or binary attachment (non-filesystem) to the list.
  2598. * This method can be used to attach ascii or binary data,
  2599. * such as a BLOB record from a database.
  2600. * @param string $string String attachment data.
  2601. * @param string $filename Name of the attachment.
  2602. * @param string $encoding File encoding (see $Encoding).
  2603. * @param string $type File extension (MIME) type.
  2604. * @return void
  2605. */
  2606. function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
  2607. /* Append to $attachment array */
  2608. $cur = count($this->attachment);
  2609. $this->attachment[$cur][0] = $string;
  2610. $this->attachment[$cur][1] = $filename;
  2611. $this->attachment[$cur][2] = $filename;
  2612. $this->attachment[$cur][3] = $encoding;
  2613. $this->attachment[$cur][4] = $type;
  2614. $this->attachment[$cur][5] = true; // isString
  2615. $this->attachment[$cur][6] = 'attachment';
  2616. $this->attachment[$cur][7] = 0;
  2617. }
  2618.  
  2619. /**
  2620. * Adds an embedded attachment. This can include images, sounds, and
  2621. * just about any other document. Make sure to set the $type to an
  2622. * image type. For JPEG images use "image/jpeg" and for GIF images
  2623. * use "image/gif".
  2624. * @param string $path Path to the attachment.
  2625. * @param string $cid Content ID of the attachment. Use this to identify
  2626. * the Id for accessing the image in an HTML form.
  2627. * @param string $name Overrides the attachment name.
  2628. * @param string $encoding File encoding (see $Encoding).
  2629. * @param string $type File extension (MIME) type.
  2630. * @return bool
  2631. */
  2632. function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  2633.  
  2634. if(!@is_file($path)) {
  2635. $this->SetError($this->Lang('file_access') . $path);
  2636. return false;
  2637. }
  2638.  
  2639. $filename = basename($path);
  2640. if($name == '') {
  2641. $name = $filename;
  2642. }
  2643.  
  2644. /* Append to $attachment array */
  2645. $cur = count($this->attachment);
  2646. $this->attachment[$cur][0] = $path;
  2647. $this->attachment[$cur][1] = $filename;
  2648. $this->attachment[$cur][2] = $name;
  2649. $this->attachment[$cur][3] = $encoding;
  2650. $this->attachment[$cur][4] = $type;
  2651. $this->attachment[$cur][5] = false;
  2652. $this->attachment[$cur][6] = 'inline';
  2653. $this->attachment[$cur][7] = $cid;
  2654.  
  2655. return true;
  2656. }
  2657.  
  2658. /**
  2659. * Returns true if an inline attachment is present.
  2660. * @access private
  2661. * @return bool
  2662. */
  2663. function InlineImageExists() {
  2664. $result = false;
  2665. for($i = 0; $i < count($this->attachment); $i++) {
  2666. if($this->attachment[$i][6] == 'inline') {
  2667. $result = true;
  2668. break;
  2669. }
  2670. }
  2671.  
  2672. return $result;
  2673. }
  2674.  
  2675. /////////////////////////////////////////////////
  2676. // CLASS METHODS, MESSAGE RESET
  2677. /////////////////////////////////////////////////
  2678.  
  2679. /**
  2680. * Clears all recipients assigned in the TO array. Returns void.
  2681. * @return void
  2682. */
  2683. function ClearAddresses() {
  2684. $this->to = array();
  2685. }
  2686.  
  2687. /**
  2688. * Clears all recipients assigned in the CC array. Returns void.
  2689. * @return void
  2690. */
  2691. function ClearCCs() {
  2692. $this->cc = array();
  2693. }
  2694.  
  2695. /**
  2696. * Clears all recipients assigned in the BCC array. Returns void.
  2697. * @return void
  2698. */
  2699. function ClearBCCs() {
  2700. $this->bcc = array();
  2701. }
  2702.  
  2703. /**
  2704. * Clears all recipients assigned in the ReplyTo array. Returns void.
  2705. * @return void
  2706. */
  2707. function ClearReplyTos() {
  2708. $this->ReplyTo = array();
  2709. }
  2710.  
  2711. /**
  2712. * Clears all recipients assigned in the TO, CC and BCC
  2713. * array. Returns void.
  2714. * @return void
  2715. */
  2716. function ClearAllRecipients() {
  2717. $this->to = array();
  2718. $this->cc = array();
  2719. $this->bcc = array();
  2720. }
  2721.  
  2722. /**
  2723. * Clears all previously set filesystem, string, and binary
  2724. * attachments. Returns void.
  2725. * @return void
  2726. */
  2727. function ClearAttachments() {
  2728. $this->attachment = array();
  2729. }
  2730.  
  2731. /**
  2732. * Clears all custom headers. Returns void.
  2733. * @return void
  2734. */
  2735. function ClearCustomHeaders() {
  2736. $this->CustomHeader = array();
  2737. }
  2738.  
  2739. /////////////////////////////////////////////////
  2740. // CLASS METHODS, MISCELLANEOUS
  2741. /////////////////////////////////////////////////
  2742.  
  2743. /**
  2744. * Adds the error message to the error container.
  2745. * Returns void.
  2746. * @access private
  2747. * @return void
  2748. */
  2749. function SetError($msg) {
  2750. $this->error_count++;
  2751. $this->ErrorInfo = $msg;
  2752. }
  2753.  
  2754. /**
  2755. * Returns the proper RFC 822 formatted date.
  2756. * @access private
  2757. * @return string
  2758. */
  2759. function RFCDate() {
  2760. $tz = date('Z');
  2761. $tzs = ($tz < 0) ? '-' : '+';
  2762. $tz = abs($tz);
  2763. $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
  2764. $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
  2765.  
  2766. return $result;
  2767. }
  2768.  
  2769. /**
  2770. * Returns the appropriate server variable. Should work with both
  2771. * PHP 4.1.0+ as well as older versions. Returns an empty string
  2772. * if nothing is found.
  2773. * @access private
  2774. * @return mixed
  2775. */
  2776. function ServerVar($varName) {
  2777. global $HTTP_SERVER_VARS;
  2778. global $HTTP_ENV_VARS;
  2779.  
  2780. if(!isset($_SERVER)) {
  2781. $_SERVER = $HTTP_SERVER_VARS;
  2782. if(!isset($_SERVER['REMOTE_ADDR'])) {
  2783. $_SERVER = $HTTP_ENV_VARS; // must be Apache
  2784. }
  2785. }
  2786.  
  2787. if(isset($_SERVER[$varName])) {
  2788. return $_SERVER[$varName];
  2789. } else {
  2790. return '';
  2791. }
  2792. }
  2793.  
  2794. /**
  2795. * Returns the server hostname or 'localhost.localdomain' if unknown.
  2796. * @access private
  2797. * @return string
  2798. */
  2799. function ServerHostname() {
  2800. if ($this->Hostname != '') {
  2801. $result = $this->Hostname;
  2802. } elseif ($this->ServerVar('SERVER_NAME') != '') {
  2803. $result = $this->ServerVar('SERVER_NAME');
  2804. } else {
  2805. $result = 'localhost.localdomain';
  2806. }
  2807.  
  2808. return $result;
  2809. }
  2810.  
  2811. /**
  2812. * Returns a message in the appropriate language.
  2813. * @access private
  2814. * @return string
  2815. */
  2816. function Lang($key) {
  2817. if(count($this->language) < 1) {
  2818. $this->SetLanguage('en'); // set the default language
  2819. }
  2820.  
  2821. if(isset($this->language[$key])) {
  2822. return $this->language[$key];
  2823. } else {
  2824. return 'Language string failed to load: ' . $key;
  2825. }
  2826. }
  2827.  
  2828. /**
  2829. * Returns true if an error occurred.
  2830. * @return bool
  2831. */
  2832. function IsError() {
  2833. return ($this->error_count > 0);
  2834. }
  2835.  
  2836. /**
  2837. * Changes every end of line from CR or LF to CRLF.
  2838. * @access private
  2839. * @return string
  2840. */
  2841. function FixEOL($str) {
  2842. $str = str_replace("\r\n", "\n", $str);
  2843. $str = str_replace("\r", "\n", $str);
  2844. $str = str_replace("\n", $this->LE, $str);
  2845. return $str;
  2846. }
  2847.  
  2848. /**
  2849. * Adds a custom header.
  2850. * @return void
  2851. */
  2852. function AddCustomHeader($custom_header) {
  2853. $this->CustomHeader[] = explode(':', $custom_header, 2);
  2854. }
  2855.  
  2856. /**
  2857. * Evaluates the message and returns modifications for inline images and backgrounds
  2858. * @access public
  2859. * @return $message
  2860. */
  2861. function MsgHTML($message,$basedir='') {
  2862. preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
  2863. if(isset($images[2])) {
  2864. foreach($images[2] as $i => $url) {
  2865. // do not change urls for absolute images (thanks to corvuscorax)
  2866. if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
  2867. $filename = basename($url);
  2868. $directory = dirname($url);
  2869. ($directory == '.')?$directory='':'';
  2870. $cid = 'cid:' . md5($filename);
  2871. $fileParts = split("\.", $filename);
  2872. $ext = $fileParts[1];
  2873. $mimeType = $this->_mime_types($ext);
  2874. if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
  2875. if ( strlen($directory) > 1 && substr($basedir,-1) != '/') { $directory .= '/'; }
  2876. $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType);
  2877. if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
  2878. $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
  2879. }
  2880. }
  2881. }
  2882. }
  2883. $this->IsHTML(true);
  2884. $this->Body = $message;
  2885. $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
  2886. if ( !empty($textMsg) && empty($this->AltBody) ) {
  2887. $this->AltBody = $textMsg;
  2888. }
  2889. if ( empty($this->AltBody) ) {
  2890. $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
  2891. }
  2892. }
  2893.  
  2894. /**
  2895. * Gets the mime type of the embedded or inline image
  2896. * @access private
  2897. * @return mime type of ext
  2898. */
  2899. function _mime_types($ext = '') {
  2900. $mimes = array(
  2901. 'hqx' => 'application/mac-binhex40',
  2902. 'cpt' => 'application/mac-compactpro',
  2903. 'doc' => 'application/msword',
  2904. 'bin' => 'application/macbinary',
  2905. 'dms' => 'application/octet-stream',
  2906. 'lha' => 'application/octet-stream',
  2907. 'lzh' => 'application/octet-stream',
  2908. 'exe' => 'application/octet-stream',
  2909. 'class' => 'application/octet-stream',
  2910. 'psd' => 'application/octet-stream',
  2911. 'so' => 'application/octet-stream',
  2912. 'sea' => 'application/octet-stream',
  2913. 'dll' => 'application/octet-stream',
  2914. 'oda' => 'application/oda',
  2915. 'pdf' => 'application/pdf',
  2916. 'ai' => 'application/postscript',
  2917. 'eps' => 'application/postscript',
  2918. 'ps' => 'application/postscript',
  2919. 'smi' => 'application/smil',
  2920. 'smil' => 'application/smil',
  2921. 'mif' => 'application/vnd.mif',
  2922. 'xls' => 'application/vnd.ms-excel',
  2923. 'ppt' => 'application/vnd.ms-powerpoint',
  2924. 'wbxml' => 'application/vnd.wap.wbxml',
  2925. 'wmlc' => 'application/vnd.wap.wmlc',
  2926. 'dcr' => 'application/x-director',
  2927. 'dir' => 'application/x-director',
  2928. 'dxr' => 'application/x-director',
  2929. 'dvi' => 'application/x-dvi',
  2930. 'gtar' => 'application/x-gtar',
  2931. 'php' => 'application/x-httpd-php',
  2932. 'php4' => 'application/x-httpd-php',
  2933. 'php3' => 'application/x-httpd-php',
  2934. 'phtml' => 'application/x-httpd-php',
  2935. 'phps' => 'application/x-httpd-php-source',
  2936. 'js' => 'application/x-javascript',
  2937. 'swf' => 'application/x-shockwave-flash',
  2938. 'sit' => 'application/x-stuffit',
  2939. 'tar' => 'application/x-tar',
  2940. 'tgz' => 'application/x-tar',
  2941. 'xhtml' => 'application/xhtml+xml',
  2942. 'xht' => 'application/xhtml+xml',
  2943. 'zip' => 'application/zip',
  2944. 'mid' => 'audio/midi',
  2945. 'midi' => 'audio/midi',
  2946. 'mpga' => 'audio/mpeg',
  2947. 'mp2' => 'audio/mpeg',
  2948. 'mp3' => 'audio/mpeg',
  2949. 'aif' => 'audio/x-aiff',
  2950. 'aiff' => 'audio/x-aiff',
  2951. 'aifc' => 'audio/x-aiff',
  2952. 'ram' => 'audio/x-pn-realaudio',
  2953. 'rm' => 'audio/x-pn-realaudio',
  2954. 'rpm' => 'audio/x-pn-realaudio-plugin',
  2955. 'ra' => 'audio/x-realaudio',
  2956. 'rv' => 'video/vnd.rn-realvideo',
  2957. 'wav' => 'audio/x-wav',
  2958. 'bmp' => 'image/bmp',
  2959. 'gif' => 'image/gif',
  2960. 'jpeg' => 'image/jpeg',
  2961. 'jpg' => 'image/jpeg',
  2962. 'jpe' => 'image/jpeg',
  2963. 'png' => 'image/png',
  2964. 'tiff' => 'image/tiff',
  2965. 'tif' => 'image/tiff',
  2966. 'css' => 'text/css',
  2967. 'html' => 'text/html',
  2968. 'htm' => 'text/html',
  2969. 'shtml' => 'text/html',
  2970. 'txt' => 'text/plain',
  2971. 'text' => 'text/plain',
  2972. 'log' => 'text/plain',
  2973. 'rtx' => 'text/richtext',
  2974. 'rtf' => 'text/rtf',
  2975. 'xml' => 'text/xml',
  2976. 'xsl' => 'text/xml',
  2977. 'mpeg' => 'video/mpeg',
  2978. 'mpg' => 'video/mpeg',
  2979. 'mpe' => 'video/mpeg',
  2980. 'qt' => 'video/quicktime',
  2981. 'mov' => 'video/quicktime',
  2982. 'avi' => 'video/x-msvideo',
  2983. 'movie' => 'video/x-sgi-movie',
  2984. 'doc' => 'application/msword',
  2985. 'word' => 'application/msword',
  2986. 'xl' => 'application/excel',
  2987. 'eml' => 'message/rfc822'
  2988. );
  2989. return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
  2990. }
  2991.  
  2992. /**
  2993. * Set (or reset) Class Objects (variables)
  2994. *
  2995. * Usage Example:
  2996. * $page->set('X-Priority', '3');
  2997. *
  2998. * @access public
  2999. * @param string $name Parameter Name
  3000. * @param mixed $value Parameter Value
  3001. * NOTE: will not work with arrays, there are no arrays to set/reset
  3002. */
  3003. function set ( $name, $value = '' ) {
  3004. if ( isset($this->$name) ) {
  3005. $this->$name = $value;
  3006. } else {
  3007. $this->SetError('Cannot set or reset variable ' . $name);
  3008. return false;
  3009. }
  3010. }
  3011.  
  3012. /**
  3013. * Read a file from a supplied filename and return it.
  3014. *
  3015. * @access public
  3016. * @param string $filename Parameter File Name
  3017. */
  3018. function getFile($filename) {
  3019. $return = '';
  3020. if ($fp = fopen($filename, 'rb')) {
  3021. while (!feof($fp)) {
  3022. $return .= fread($fp, 1024);
  3023. }
  3024. fclose($fp);
  3025. return $return;
  3026. } else {
  3027. return false;
  3028. }
  3029. }
  3030.  
  3031. /**
  3032. * Strips newlines to prevent header injection.
  3033. * @access private
  3034. * @param string $str String
  3035. * @return string
  3036. */
  3037. function SecureHeader($str) {
  3038. $str = trim($str);
  3039. $str = str_replace("\r", "", $str);
  3040. $str = str_replace("\n", "", $str);
  3041. return $str;
  3042. }
  3043.  
  3044. /**
  3045. * Set the private key file and password to sign the message.
  3046. *
  3047. * @access public
  3048. * @param string $key_filename Parameter File Name
  3049. * @param string $key_pass Password for private key
  3050. */
  3051. function Sign($key_filename, $key_pass) {
  3052. $this->sign_key_file = $key_filename;
  3053. $this->sign_key_pass = $key_pass;
  3054. }
  3055.  
  3056. }
  3057.  
  3058.  
  3059.  
  3060. /**
  3061. * Copyright (c) 2003 Brian E. Lozier ([email protected])
  3062. *
  3063. * set_vars() method contributed by Ricardo Garcia (Thanks!)
  3064. *
  3065. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3066. * of this software and associated documentation files (the "Software"), to
  3067. * deal in the Software without restriction, including without limitation the
  3068. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  3069. * sell copies of the Software, and to permit persons to whom the Software is
  3070. * furnished to do so, subject to the following conditions:
  3071. *
  3072. * The above copyright notice and this permission notice shall be included in
  3073. * all copies or substantial portions of the Software.
  3074. *
  3075. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3076. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3077. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3078. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3079. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  3080. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  3081. * IN THE SOFTWARE.
  3082. */
  3083.  
  3084. class UFMTemplate {
  3085. var $vars; /// Holds all the template variables
  3086. var $path; /// Path to the templates
  3087.  
  3088.  
  3089. /**
  3090. * Constructor
  3091. *
  3092. * @param string $path the path to the templates
  3093. *
  3094. * @return void
  3095. */
  3096. function UFMTemplate($path = null) {
  3097. $this->path = $path;
  3098. $this->vars = array();
  3099. }
  3100.  
  3101. /**
  3102. * Set the path to the template files.
  3103. *
  3104. * @param string $path path to template files
  3105. *
  3106. * @return void
  3107. */
  3108. function set_path($path) {
  3109. $this->path = $path;
  3110. }
  3111.  
  3112. /**
  3113. * Set a template variable.
  3114. *
  3115. * @param string $name name of the variable to set
  3116. * @param mixed $value the value of the variable
  3117. *
  3118. * @return void
  3119. */
  3120. function set($name, $value) {
  3121. $this->vars[$name] = $value;
  3122. }
  3123.  
  3124. /**
  3125. * Set a bunch of variables at once using an associative array.
  3126. *
  3127. * @param array $vars array of vars to set
  3128. * @param bool $clear whether to completely overwrite the existing vars
  3129. *
  3130. * @return void
  3131. */
  3132. function set_vars($vars, $clear = false) {
  3133. if($clear) {
  3134. $this->vars = $vars;
  3135. }
  3136. else {
  3137. if(is_array($vars)) $this->vars = array_merge($this->vars, $vars);
  3138. }
  3139.  
  3140. }
  3141.  
  3142. function set_vars_new($vars) {
  3143. if(is_array($vars)) {
  3144. foreach($vars as $vvv){
  3145. $this->vars[$vvv] = $_POST[$vvv];
  3146. }//foreach
  3147. //$this->vars = array_merge($this->vars, $this->newVars);
  3148. }//is_array
  3149.  
  3150. }
  3151. /**
  3152. * Open, parse, and return the template file.
  3153. *
  3154. * @param string string the template file name
  3155. *
  3156. * @return string
  3157. */
  3158. function fetch($ufmFile) {
  3159.  
  3160. extract($this->vars); // Extract the vars to local namespace
  3161. ob_start(); // Start output buffering
  3162. include($this->path . $ufmFile); // Include the file
  3163.  
  3164. $contents = ob_get_contents(); // Get the contents of the buffer
  3165. ob_end_clean(); // End buffering and discard
  3166. return $contents; // Return the contents
  3167. }
  3168. }
  3169.  
  3170. /**
  3171. * An extension to Template that provides automatic caching of
  3172. * template contents.
  3173. */
  3174. class UFMCachedTemplate extends UFMTemplate {
  3175. var $cache_id;
  3176. var $expire;
  3177. var $cached;
  3178.  
  3179. /**
  3180. * Constructor.
  3181. *
  3182. * @param string $path path to template files
  3183. * @param string $cache_id unique cache identifier
  3184. * @param int $expire number of seconds the cache will live
  3185. *
  3186. * @return void
  3187. */
  3188. function UFMCachedTemplate($path, $cache_id = null, $expire = 900) {
  3189. $this->UFMTemplate($path);
  3190. $this->cache_id = $cache_id ? 'cache/' . md5($cache_id) : $cache_id;
  3191. $this->expire = $expire;
  3192. }
  3193.  
  3194. /**
  3195. * Test to see whether the currently loaded cache_id has a valid
  3196. * corrosponding cache file.
  3197. *
  3198. * @return bool
  3199. */
  3200. function is_cached() {
  3201. if($this->cached) return true;
  3202.  
  3203. // Passed a cache_id?
  3204. if(!$this->cache_id) return false;
  3205.  
  3206. // Cache file exists?
  3207. if(!file_exists($this->cache_id)) return false;
  3208.  
  3209. // Can get the time of the file?
  3210. if(!($mtime = filemtime($this->cache_id))) return false;
  3211.  
  3212. // Cache expired?
  3213. if(($mtime + $this->expire) < time()) {
  3214. @unlink($this->cache_id);
  3215. return false;
  3216. }
  3217. else {
  3218. /**
  3219. * Cache the results of this is_cached() call. Why? So
  3220. * we don't have to double the overhead for each template.
  3221. * If we didn't cache, it would be hitting the file system
  3222. * twice as much (file_exists() & filemtime() [twice each]).
  3223. */
  3224. $this->cached = true;
  3225. return true;
  3226. }
  3227. }
  3228.  
  3229. /**
  3230. * This function returns a cached copy of a template (if it exists),
  3231. * otherwise, it parses it as normal and caches the content.
  3232. *
  3233. * @param $file string the template file
  3234. *
  3235. * @return string
  3236. */
  3237. function fetch_cache($file) {
  3238. if($this->is_cached()) {
  3239. $fp = @fopen($this->cache_id, 'r');
  3240. $contents = fread($fp, filesize($this->cache_id));
  3241. fclose($fp);
  3242. return $contents;
  3243. }
  3244. else {
  3245. $contents = $this->fetch($file);
  3246.  
  3247. // Write the cache
  3248. if($fp = @fopen($this->cache_id, 'w')) {
  3249. fwrite($fp, $contents);
  3250. fclose($fp);
  3251. }
  3252. else {
  3253. die('Unable to write cache.');
  3254. }
  3255.  
  3256. return $contents;
  3257. }
  3258. }
  3259. }
  3260.  
  3261. class MailMerge extends UFMTemplate{
  3262. var $test_array = '';
  3263. var $new_string = '';
  3264. var $string = '';
  3265.  
  3266. function plug($plugFile, $array, $optional_array='')
  3267. {
  3268. //$contents = implode(" ", file($file));
  3269.  
  3270. $this->set_vars_new($array);
  3271. $jkbArray = $array;
  3272. $contents = $this->fetch($plugFile);
  3273.  
  3274. $old = $this->create_array($array);
  3275. if($optional_array != '')
  3276. {
  3277. $new = $this->clean_array($array, $optional_array);
  3278.  
  3279. }
  3280. else
  3281. {
  3282. $new = $array;
  3283. }
  3284. $contents = str_replace($old, $new, $contents);
  3285. $contents = preg_replace('/{{(.*)}}/iU', '', $contents);/*removes {{whatever}} left over*/
  3286.  
  3287. return $contents;
  3288. }//end of constructor
  3289.  
  3290. function create_array($array)
  3291. {
  3292. foreach($array as $ar)
  3293. {
  3294. $new_stuff[] = "{{" . $ar . "}}";
  3295. }
  3296. return $new_stuff;
  3297. }//end of create_array()
  3298.  
  3299. function clean_array ($array, $optional_array)
  3300. {
  3301. foreach($array as $ab)
  3302. {
  3303. if(isset($_POST[$ab]) && $_POST[$ab] != "")
  3304. {
  3305. $ar = $_POST[$ab];
  3306. }
  3307. else
  3308. {
  3309. if(isset($optional_array[$ab]) && $optional_array[$ab] != "")
  3310. {
  3311. $ar = $optional_array[$ab];
  3312. }
  3313. else
  3314. {
  3315. $ar = "";
  3316. }
  3317. }
  3318.  
  3319. if(!is_array($ar))
  3320. //if(1==1)
  3321. {
  3322. $new_array[] = stripslashes($ar);
  3323. }
  3324. else
  3325. {
  3326. foreach($ar as $key2=>$arr)
  3327. {
  3328. $arr = stripslashes($arr);
  3329. $string .= " " . $arr . ",";
  3330. }
  3331. $string = substr($string, 0, (strlen($string) - 1));
  3332. $new_array[] = $string;
  3333. unset($string);
  3334. }
  3335. }
  3336. return $new_array;
  3337. }//end of clean_array
  3338. }//end of class MailMerge
  3339.  
  3340. class UFMdb {
  3341.  
  3342. function connect($database_vars)
  3343. {
  3344. if(isset($database_vars) && is_array($database_vars))
  3345. {
  3346. foreach($database_vars as $var=>$value)
  3347. {
  3348. $this->{$var} = $value;
  3349. }
  3350. }
  3351. @mysql_connect($this->host, $this->user, $this->pass);
  3352. mysql_select_db($this->dbase) or die(
  3353. "Cannot connect to database");
  3354. }//end of connect
  3355.  
  3356. function query($query) {
  3357.  
  3358. $query = mysql_query($query) or die(mysql_error());
  3359. return $query;
  3360. }
  3361.  
  3362. function fetch_array($query) {
  3363.  
  3364. $query = mysql_fetch_array($query);
  3365. return $query;
  3366. }
  3367.  
  3368. function fetch_row($query) {
  3369.  
  3370. $query = mysql_fetch_row($query);
  3371. return $query;
  3372. }
  3373.  
  3374. function close() {
  3375.  
  3376. mysql_close();
  3377. }
  3378. }//end of class db
  3379.  
  3380. class UFMail {
  3381. var $website;
  3382. var $email;
  3383. var $p_vars;
  3384. var $recipient;
  3385. var $testing;
  3386. var $subject;
  3387. var $redirect;
  3388. var $banlist;
  3389. var $headerfile;
  3390. var $footerfile;
  3391. var $cssfile;
  3392. var $banned_ext;
  3393. var $max_file_size;
  3394. var $env_report;
  3395. var $autoresponder;
  3396. var $auto_from;
  3397. var $auto_from_name;
  3398.  
  3399. var $auto_content;
  3400. var $auto_reply;
  3401. var $auto_reply_name;
  3402. var $first_name;
  3403. var $ignore_these;
  3404. var $error_message;
  3405. var $webmaster_body;
  3406. var $required;
  3407. var $required_check;
  3408. var $receipt;
  3409. var $rcpt;
  3410. var $referer_check;
  3411. var $date_format;
  3412. var $dropdown_name;
  3413. var $dropdown_recipient;
  3414. var $dropdown_list;
  3415. var $p_file;
  3416. var $field_check_ereg;
  3417. var $auto_reply_body_alt;
  3418. var $auto_reply_signaturesignature_alt;
  3419. var $webmaster_body_intro_alt;
  3420. var $dropdown_email_match;
  3421. var $bcc;
  3422. var $cc;
  3423. var $file_name_array;
  3424. var $send_attachment;
  3425.  
  3426. var $jkbLicense;
  3427. var $jkbLicenseType;
  3428. var $dom;
  3429. var $drop_down_default;
  3430.  
  3431. var $required_filefields;
  3432.  
  3433.  
  3434. function initialize($setup)
  3435. {
  3436. $url = trim($_SERVER['HTTP_HOST']);
  3437. $parts = pathinfo($url);
  3438. $bad = array('http://', 'www.','https://');
  3439.  
  3440. $this->dom = str_replace($bad, '', $parts['basename']);
  3441.  
  3442.  
  3443.  
  3444. /*prevent any chance of messing with my configuration scheme*/
  3445. $set = '';
  3446. unset($set);
  3447. /*************
  3448. Controls switcher
  3449.  
  3450. *************/
  3451. $controlFile = 'controls.php';
  3452. if(isset($_GET['cid']) && is_numeric($_GET['cid']) && $_GET['cid'] != ''):
  3453. if(is_file('controls-'.$_GET['cid'].'.php')):
  3454. $controlFile = 'controls-'.$_GET['cid'].'.php';
  3455. elseif(is_file('controls'.$_GET['cid'].'.php')):
  3456. $controlFile = 'controls'.$_GET['cid'].'.php';
  3457. endif;//file found, either controls-N.php or controlsN.php
  3458. endif;//cid is set
  3459. include $controlFile;
  3460. /**** End controls file switch *********/
  3461. foreach($set as $a=>$b)
  3462. {
  3463. $this->{$a} = $b;
  3464. }//end of foreach setup variable
  3465.  
  3466. $this->p_vars = $_POST;
  3467. $this->p_file = $_FILES;
  3468. $this->post_keys = array_keys($this->p_vars);
  3469. $this->keep_these = array_diff($this->post_keys, $this->ignore_these);
  3470.  
  3471. //set the recipient
  3472. if(isset($this->dropdown_recipient) && ($this->dropdown_recipient == '1'))
  3473. {
  3474.  
  3475.  
  3476. if(!isset($this->p_vars[$this->dropdown_name]) || $this->p_vars[$this->dropdown_name] =='')
  3477. {
  3478. if(isset($this->drop_down_default) && $this->drop_down_default == true)
  3479. {
  3480. $chosen_email = $this->recipient[0];
  3481. $this->recipient = "";
  3482. $this->recipient = array($chosen_email);
  3483. }
  3484. else
  3485. {
  3486. $this->error_message .= $this->drop_down_error;
  3487. }
  3488. }
  3489. else
  3490. {
  3491. define('chosen_email_id', $this->p_vars[$this->dropdown_name]);
  3492. if(!is_array($this->p_vars[$this->dropdown_name]))
  3493. {
  3494. $chosen_email = $this->dropdown_list[$this->p_vars[$this->dropdown_name]];
  3495. $this->recipient = "";
  3496. $this->recipient = array($chosen_email);
  3497. }
  3498. else
  3499. {
  3500. foreach($this->p_vars[$this->dropdown_name] as $ceid)
  3501. {
  3502. $chosen_email[] = $this->dropdown_list[$ceid];
  3503. }//end of foreach
  3504. $this->recipient = "";
  3505. $this->recipient = $chosen_email;
  3506. }//end of else is array
  3507. }
  3508. if(isset($this->dropdown_email_match) && $this->dropdown_email_match == '1' && count($this->recipient) == '1')
  3509. {
  3510. $this->auto_from = $this->recipient[0];
  3511. }
  3512. }//end of dropdown
  3513.  
  3514.  
  3515.  
  3516.  
  3517.  
  3518. /****************************
  3519. New licensing procedure
  3520. ***************************/
  3521. $fi = explode('(',__FILE__);/*IIS*/
  3522. if($_SERVER["SCRIPT_FILENAME"] && $_SERVER["SCRIPT_FILENAME"] != '')
  3523. {
  3524. $illegalInclude = ((realpath ($_SERVER["SCRIPT_FILENAME"]) != realpath ($fi[0])) && (realpath ($_SERVER["PATH_TRANSLATED"]) != realpath ($fi[0])));
  3525. }
  3526. else
  3527. {
  3528. /*IIS*/
  3529. $illegalInclude = (realpath($_SERVER["PATH_TRANSLATED"]) != realpath ($fi[0]));
  3530. }
  3531. if($illegalInclude)
  3532. {
  3533. print "License error: i";
  3534. exit;
  3535. }
  3536.  
  3537.  
  3538. if($license) {
  3539. if(!is_array($license)) {
  3540. $licenseParts = explode('-', $license);
  3541. if(!$this->checkLicense($license)){
  3542. echo 'License error - please check your configuration settings';
  3543. exit;
  3544. }
  3545. } else {
  3546. $licTest = false;//assume false
  3547. foreach($license as $lic){
  3548. if($this->checkLicense($lic)){
  3549. $licTest = true;
  3550. }
  3551. }
  3552. if(!$licTest){
  3553. echo 'License error - please check your configuration settings';
  3554. exit;
  3555. }
  3556. }
  3557. }//license exists
  3558.  
  3559. /*************************/
  3560.  
  3561. $this->webmaster_body_intro_alt = $this->webmaster_body_intro;
  3562. $this->webmaster_body_intro = $this->convert_language($this->webmaster_html, $this->webmaster_body_intro);
  3563. $this->receipt_intro = $this->convert_language($this->recipient_html, $this->receipt_intro);
  3564. $this->auto_reply_body_alt = $this->auto_reply_body;
  3565. $this->auto_reply_body = $this->convert_language($this->recipient_html, $this->auto_reply_body);
  3566.  
  3567. //this next line was added for advertisement version
  3568. $this->auto_reply_signaturesignature_alt = $this->auto_reply_signaturesignature;
  3569. $this->auto_reply_signaturesignature = $this->subvert_fix($this->auto_reply_signaturesignature);
  3570.  
  3571. $this->auto_reply_signaturesignature = $this->convert_language($this->recipient_html, $this->auto_reply_signaturesignature);
  3572.  
  3573.  
  3574. /*****************************
  3575. New cleaner procudure
  3576. **************************/
  3577. if($this->extraSecurity == 1)
  3578. {
  3579. $this->p_vars = $this->dataCleaner($this->p_vars);
  3580. }
  3581. /***************************
  3582. New AntiSpam
  3583. ***************************/
  3584. if($this->spamBlock == 1)
  3585. {
  3586. $this->antiSpam();
  3587. }
  3588. }//end of function initialize
  3589.  
  3590. /****************************/
  3591.  
  3592. function checkLicense($license){
  3593. $licType = substr($license, -1, 1);
  3594.  
  3595. $licenseParts = explode('-', $license);
  3596. $test1 = substr(md5($this->dom.'oceanView'.$licType), 3, 10);
  3597. $test2 = substr_replace(md5($this->dom.'forestPath'.$licType), '-', 5, 22);
  3598. $test3 = substr(md5($test1.$test2.$licType), 20, 12);
  3599. $testAll = strtoupper($test1.$test2.$test3.$licType);
  3600.  
  3601. if(count($licenseParts) == 3)
  3602. {
  3603. /****Temp License Check********/
  3604. $licenseStart = substr($licenseParts[2], 3);
  3605. $licenseStart = $licenseStart/3;
  3606. $testPeriod = 15;/*days*/
  3607. $testTime = $testPeriod * 60 * 60 *24;
  3608. if((mktime()-$testTime) > $licenseStart)
  3609. {
  3610. echo 'Your temporary license has expired';
  3611. exit;
  3612. }
  3613. $test1 = substr(md5($this->dom.'oceanViewTemp'), 3, 10);
  3614. $licenseStart = $licenseStart*3;
  3615. $test4 = '-'.substr(md5($licenseStart.'abyssTemp'), 3, 3).$licenseStart;
  3616. $test2 = substr_replace(md5($this->dom.$test1.$test4.'forestPathTemp'), '-', 5, 17);
  3617. $testAll = strtoupper($test1.$test2.$test4);
  3618. $licType = 2;/*Show them everything*/
  3619. }
  3620.  
  3621. if(!$license || $license != $testAll)
  3622. {
  3623. if($license == '' || $license == 'LicenseGoesHere') {
  3624. $tempDomain = $_SERVER['HTTP_HOST'];
  3625. echo 'Your license has not been set<br><br>';
  3626. echo 'To set up a temporary license, click the button below:<br><br>
  3627.  
  3628. <form action="http://www.ultimateformmail.com/tempLicense/tempLicense.php" method="post" enctype="multipart/form-data" name="form1">
  3629. <input name="tempDomain" type="hidden" id="tempDomain" value="'.$tempDomain.'">
  3630. Register a temporary license for <strong>'.$tempDomain .'</strong>
  3631. now
  3632. <input name="Register" type="submit" id="Register" value="Register &raquo;">
  3633. </form>';
  3634. exit;
  3635. }
  3636. else
  3637. {
  3638. return false;
  3639. }
  3640. }
  3641. $this->jkbLicense = $license;
  3642. $this->jkbLicenseType = $licType;
  3643. return true;
  3644. }//end of function checkLicense
  3645.  
  3646.  
  3647. function check_vars()
  3648. {
  3649. //first check the referer
  3650. if($this->referer_check == 1)
  3651. {
  3652. //nothing
  3653. }//end of referer check
  3654.  
  3655. if(!isset($this->p_vars['email']) && isset($this->autoresponder) && ($this->autoresponder == '1'))
  3656. {
  3657. $this->error_message .= $this->no_email_field;
  3658. }
  3659.  
  3660. $test = array_merge(array_keys($this->p_vars),array_keys($this->p_file));
  3661. if(is_array($this->required))
  3662. {
  3663. $diff = array_diff($this->required, $test);
  3664. if($diff)
  3665. {
  3666. foreach($diff as $dif)
  3667. {
  3668. $dif = $this->formatEmailContent($dif);
  3669. $this->error_message .= sprintf($this->required_error, $dif);
  3670. }
  3671. }
  3672. }
  3673. /** 3.2.8 required files */
  3674. $ftest = array();
  3675.  
  3676. foreach($this->p_file as $fkey=>$fval):
  3677. if(isset($fval['name']) && $fval['name'] != '' && $fval['size'] > 0) $ftest[] = $fkey;
  3678. endforeach;
  3679.  
  3680. if(is_array($this->required_filefields))
  3681. {
  3682. $diff = array_diff($this->required_filefields, $ftest);
  3683. if($diff)
  3684. {
  3685. foreach($diff as $dif)
  3686. {
  3687. $dif = $this->formatEmailContent($dif);
  3688. $this->error_message .= sprintf($this->required_error, $dif);
  3689. }
  3690. }
  3691. }
  3692.  
  3693. /***/
  3694. foreach($this->p_vars as $key=>$value)
  3695. {
  3696. if(!in_array($key, $this->keep_these))
  3697. {
  3698. continue;
  3699. }
  3700. if(is_array($this->required))
  3701. {
  3702. if((in_array($key, $this->required)) && ($value == ""))
  3703. {
  3704. $key = $this->formatEmailContent($key);
  3705. $this->error_message .= sprintf($this->required_error, $key);
  3706. }
  3707. if((in_array($key, $this->required)) && ($value != ""))
  3708. {
  3709. $this->required_check .= sprintf($this->required_no_error, $key);
  3710. }
  3711. }
  3712.  
  3713. if(is_array($value))
  3714. {
  3715. $key1 = $key;
  3716. if(is_array($this->required))
  3717. {
  3718. if((in_array($key, $this->required)) && (count($value) < 1))
  3719. {
  3720. $key = $this->formatEmailContent($key);
  3721. $this->error_message .= sprintf($this->required_error, $key);
  3722. }
  3723. if((in_array($key, $this->required)) && (count($value) > 0))
  3724. {
  3725. $this->required_check .= sprintf($this->required_no_error, $key);
  3726. }
  3727. }
  3728.  
  3729. if($this->dropdown_name != '' && $key == $this->dropdown_name && is_numeric($value))
  3730. {
  3731. $value = $this->recipient;
  3732. $this->p_vars[$key] = $this->recipient;
  3733. }
  3734. foreach($value as $k=>$v)
  3735. {
  3736. $t = $k+1;
  3737. $rrr = $key1 . "(" . $t . ")";
  3738. $rrr = $this->formatEmailContent($rrr);
  3739. $this->webmaster_body .= sprintf($this->post_info, $rrr, $v);
  3740. }
  3741. }
  3742. else
  3743. {
  3744.  
  3745. if(isset($this->field_check_eregi[$key]) && $this->field_check_eregi[$key] != "" && isset($value) && $value != "")
  3746. {
  3747. if($this->eregi_check($key) == FALSE)
  3748. {
  3749. $this->error_message .= sprintf($this->invalid_error, $key);
  3750. }
  3751. }
  3752.  
  3753.  
  3754. if(isset($this->field_check_ereg[$key]) && $this->field_check_ereg[$key] != "" && isset($value) && $value != "")
  3755. {
  3756. if($this->ereg_check($key) == FALSE)
  3757. {
  3758. $this->error_message .= sprintf($this->invalid_error, $key);
  3759. }
  3760. }
  3761.  
  3762.  
  3763. if($key == 'email')
  3764. {
  3765. if($value == "" && $this->autoresponder == '1')
  3766. {
  3767. if(!in_array($key, $this->required))
  3768. {
  3769. $this->error_message .= sprintf($this->required_error, $key);
  3770. }
  3771. }
  3772. else
  3773. {
  3774. if($this->check_banlist($value) == 0)
  3775. {
  3776. $this->error_message .= $this->email_banned;
  3777. }
  3778. }
  3779. }//end of if email
  3780.  
  3781. if($key == 'recipient_menu')//this is for drop down list of recipients in form
  3782. {
  3783. if(in_array($value, $this->recipient))
  3784. {
  3785. $this->recipient = "";
  3786. $this->recipient = array($value);
  3787. }
  3788. else
  3789. {
  3790. $this->error_message .= sprintf($this->recipient_error, $value);
  3791. }
  3792. }//end of recipient_menu
  3793.  
  3794. if($this->dropdown_name != '' && $key == $this->dropdown_name && is_numeric($value))
  3795. {
  3796. $value = $this->recipient[0];
  3797. $this->p_vars[$key] = $this->recipient[0];
  3798. $_POST[$key] = $this->recipient[0];
  3799. }
  3800. $rrr = $this->formatEmailContent($key);
  3801. $this->webmaster_body .= sprintf($this->post_info, $rrr, $value);
  3802. }
  3803. }
  3804.  
  3805. if(isset($this->p_file) && $this->p_file != "")
  3806. {
  3807. $this->check_files($this->p_file);
  3808. }
  3809. }//end function check_vars
  3810.  
  3811. /****************************/
  3812.  
  3813. function subvert_fix($string)
  3814. {
  3815.  
  3816. $letters = count_chars($string, 1);
  3817. arsort($letters);
  3818.  
  3819. $e = explode("\n", $string);
  3820.  
  3821. $marker = 0;
  3822. foreach($e as $a=>$b)
  3823. {
  3824. if(strlen(trim($b)) > 5)
  3825. {
  3826. $marker = $a;
  3827. }
  3828. }
  3829.  
  3830. $diff = count($e) - $marker;
  3831. for($i = $marker + 1; $i < count($e) + 1; $i++)
  3832. {
  3833. if(isset($e[$i]) && $e[$i] != "")
  3834. {
  3835. $test_array .= $e[$i];
  3836. }
  3837. }
  3838. $test = count_chars($test_array, 1);
  3839. $test_count = count($test);
  3840.  
  3841. if($diff > $test_count)
  3842. {
  3843. for($t=0; $t<($marker + 1); $t++)
  3844. {
  3845. $new_string .= $e[$t] . "\n";
  3846. }
  3847. }
  3848. else
  3849. $new_string = $string;
  3850. return $new_string;
  3851. }//end of subvert_fix()
  3852.  
  3853. /****************************************/
  3854.  
  3855. function eregi_check($field)
  3856. {
  3857. if(!eregi($this->field_check_eregi[$field], $this->p_vars[$field]))
  3858. {
  3859. return FALSE;
  3860. }
  3861. else
  3862. {
  3863. return TRUE;
  3864. }
  3865. }//end of function eregi_check
  3866.  
  3867. function ereg_check($field)
  3868. {
  3869. if(!ereg($this->field_check_ereg[$field], $this->p_vars[$field]))
  3870. {
  3871. return FALSE;
  3872. }
  3873. else
  3874. {
  3875. return TRUE;
  3876. }
  3877. }//end of function ereg_check
  3878.  
  3879.  
  3880.  
  3881.  
  3882. function branch()
  3883. {
  3884. if($this->testing == 1 || isset($this->error_message))
  3885. {
  3886. //error_reporting(0);
  3887. }
  3888. if($this->testing == 1)
  3889. {
  3890.  
  3891. $error_content = $this->testing_title;
  3892. if($this->error_message && $this->error_message != "")
  3893. {
  3894. $error_content .= "<h2>No email would be sent</h2>$this->error_message<br><br>";
  3895. }
  3896. else
  3897. {
  3898. if(is_array($this->recipient))
  3899. {
  3900. foreach($this->recipient as $to)
  3901. {
  3902. $error_content .= "<h2>The message would have been sent to $to</h2>";
  3903. }
  3904. }
  3905. else
  3906. {
  3907. $error_content .= "<h2>The message would have been sent to $this->recipient</h2>";
  3908. }
  3909. }
  3910. if($this->required_check && $this->required_check != "")
  3911. {
  3912. $error_content .= $this->required_check . "<br>";
  3913. }
  3914. $offset1 = $this->offset * 60 * 60;
  3915. $now = date($this->date_format, mktime()+$offset1);
  3916. $error_content .= sprintf($this->timestamp, $now);
  3917.  
  3918. $this->webmaster_body = $this->convert_language(1, $this->webmaster_body);
  3919. $error_content .= "<h2>The message would be:</h2>$this->webmaster_body";
  3920. $error_content .= "<h2>These variables were set in the configuration</h2>";
  3921. if($this->autoresponder == 1)
  3922. {
  3923. $error_content .= "An auto reply would be sent from " . $this->auto_from_name ." at email address " . $this->auto_from . ".<br>";
  3924. if($this->receipt == 1)
  3925. {
  3926. $error_content .= "And you have decided to send a receipt.<br>";
  3927. }
  3928. }
  3929. else
  3930. {
  3931. $error_content .= "NO auto reply would be sent from " . $this->auto_from_name ." at email address " . $this->auto_from . ".<br>";
  3932. }
  3933. if(isset($this->website))
  3934. {
  3935. $error_content .= "You indicate the website address is " . $this->website . ".<br>";
  3936. }
  3937.  
  3938. $error_content .= "<h2>You should turn off testing mode if you are satisfied with the results</h2>";
  3939.  
  3940. $tpl = new UFMTemplate('');
  3941. $error_content = $this->formatEmailContent($error_content);
  3942. $tpl->set('error_content', $error_content);
  3943. $testing_content = $tpl->fetch($this->error_template);
  3944. echo $testing_content;
  3945. }//end of testing = 1
  3946. else
  3947. {
  3948. if($this->error_message && $this->error_message != "")
  3949. {
  3950. $error_content = sprintf($this->error_title, $this->error_message);
  3951. $tpl = & new UFMTemplate('');
  3952.  
  3953. $tpl->set('error_content', $error_content);
  3954. $error_stuff = $tpl->fetch($this->error_template);
  3955. echo $error_stuff;
  3956. }//end of if error message
  3957. else
  3958. {
  3959. /*Are we using a confirmation page?
  3960. And is the confirmation var already set?*/
  3961. if($this->confirmation_step && $this->confirmation_step == '1' && $this->p_vars['confirmFinal'] != '1')
  3962. {
  3963. $this->confirmationPage();
  3964. }
  3965.  
  3966.  
  3967. $this->webmaster_body = $this->convert_language($this->webmaster_html, $this->webmaster_body);
  3968.  
  3969. if(isset($this->p_file) && $this->p_file != "")
  3970. {
  3971.  
  3972. foreach($this->p_file as $pkey=>$pvalue)
  3973. {
  3974. if($pvalue['name'] != '')
  3975. {
  3976. $this->file_upload_name = ($this->prevent_overwrite == 1 && (isset($this->file_save_dir) && $this->file_save_dir != '')) ? mktime() . $pvalue['name'] : $pvalue['name'];
  3977.  
  3978. $file_name_array_tmp = array($pkey=>$this->file_upload_name);
  3979. $file_name_ar[$pkey] = $this->file_upload_name;
  3980. $this->p_vars = array_merge($this->p_vars, $file_name_array_tmp);
  3981.  
  3982. array_push($this->keep_these, $pkey);
  3983. }//if $pvalue['name'] != ''
  3984. }//foreach
  3985. $this->file_name_array = $file_name_ar;
  3986. }
  3987.  
  3988. //send the emails
  3989. if($this->autoresponder == 1) $this->autoreply();
  3990. $this->webmaster_notify();
  3991. if($this->jkbLicenseType > 1)/*Pro or better*/
  3992. {
  3993. if(isset($this->file_save_dir) && $this->file_save_dir != '' && $this->file_upload == 1)
  3994. {
  3995. $this->file_save();
  3996. }
  3997.  
  3998.  
  3999. }
  4000.  
  4001.  
  4002.  
  4003. if($this->jkbLicenseType > 1)/*Pro or better*/
  4004. {
  4005. if($this->use_database)
  4006. {
  4007. $this->database_put($this->keep_these);
  4008. }
  4009. }
  4010.  
  4011. if($this->jkbLicenseType > 1 && $this->mail_list == 1)/*Pro or better*/
  4012. {
  4013.  
  4014. $this->mailList($this->p_vars);
  4015.  
  4016. }
  4017.  
  4018. if($this->extra_end_routine != '') $this->extra_perform($this->extra_end_routine);
  4019.  
  4020. }
  4021. }
  4022.  
  4023.  
  4024. }//end of function branch
  4025.  
  4026. /***************************/
  4027.  
  4028.  
  4029. function autoreply()
  4030. {
  4031.  
  4032. $this->webmaster_body = stripslashes($this->webmaster_body);
  4033. $rcpt = "";
  4034. $html_rcpt = "";
  4035. if($this->receipt == 1)
  4036. {
  4037. $html_rcpt = $this->receipt_intro. $this->webmaster_body;
  4038.  
  4039. $rcpt = $this->receipt_intro;
  4040. $rcpt .= str_replace("<br>", "
  4041. ", $this->webmaster_body);
  4042. $rcpt .= "
  4043. ";
  4044. $rcpt = stripslashes($rcpt);
  4045.  
  4046. }
  4047. if($this->auto_reply_name == "")
  4048. {
  4049. $this->auto_reply_name = $this->auto_from_name;
  4050. }
  4051. if($this->auto_reply == "")
  4052. {
  4053. $this->auto_reply = $this->auto_from;
  4054. }
  4055. $mail = new phpmailer();
  4056. switch($this->email_type)
  4057. {
  4058. case 1:
  4059. $mail->IsSMTP();
  4060. break;
  4061. case 2:
  4062. $mail->IsMail();
  4063. break;
  4064. case 3:
  4065. $mail->IsQmail();
  4066. break;
  4067. case 4:
  4068. $mail->IsSendmail();
  4069. break;
  4070. default:
  4071. $mail->IsSMTP();
  4072. }
  4073.  
  4074.  
  4075.  
  4076.  
  4077. $mail->Host = $this->host; // specify main and backup server
  4078. $mail->SMTPAuth = $this->authorization; // turn on SMTP authentication
  4079. if($this->authorization == "true")
  4080. {
  4081. $mail->Username = $this->username;
  4082. $mail->Password = $this->password;
  4083. }
  4084. $mail->From = $this->auto_from;
  4085. $mail->FromName = $this->auto_from_name;
  4086. $mail->AddAddress($this->p_vars['email']); // name is optional
  4087. $mail->AddReplyTo($this->auto_reply, $this->auto_reply_name);
  4088. if(isset($this->recipient_html) && $this->recipient_html == '1')
  4089. {
  4090. $mail->IsHTML(true); // set email format to HTML
  4091. //$mail->Body = $this->auto_reply_body . $html_rcpt . $this->auto_reply_signaturesignature;
  4092.  
  4093.  
  4094.  
  4095. $rcpt_array = array('email_content');
  4096. $this->keep_these = array_merge($this->keep_these, $rcpt_array);
  4097. $email_content = $this->auto_reply_body . $html_rcpt . $this->auto_reply_signaturesignature;
  4098. $mail_merge = array('email_content' => $email_content);
  4099. if(!isset($this->template_bg_image_dir) || $this->template_bg_image_dir == '') $mail_merge['background_image_location']= 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/template/';
  4100. else $mail_merge['background_image_location'] = $this->template_bg_image_dir;
  4101.  
  4102. $tpl = & new MailMerge('');
  4103. $tpl->set('email_content', $this->auto_reply_body . $html_rcpt . $this->auto_reply_signaturesignature);
  4104. if(!isset($this->template_bg_image_dir) || $this->template_bg_image_dir == '') $mail_merge['background_image_location']= 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/template/';
  4105. else $mail_merge['background_image_location'] = $this->template_bg_image_dir;
  4106. //$mail->Body = $tpl->fetch($this->visitor_template);
  4107. $mail->Body = $tpl->plug($this->visitor_template, $this->keep_these, $mail_merge);
  4108. $searchAr = array('<br>','<br />');
  4109. $replaceAr = '';
  4110. $mail->AltBody = str_replace($searchAr, $replaceAr, $this->auto_reply_body . $rcpt . $this->auto_reply_signaturesignature_alt);
  4111.  
  4112.  
  4113. }
  4114. else
  4115. {
  4116.  
  4117. /*advertising or not*/
  4118. //$mail->Body = $this->auto_reply_body . $rcpt . $this->auto_reply_signaturesignature . $jkb_advertisement;
  4119.  
  4120. $mail->Body = $this->convert_language(0,$this->auto_reply_body . $rcpt . $this->auto_reply_signaturesignature);
  4121. }
  4122.  
  4123.  
  4124.  
  4125. $mail->Subject = sprintf($this->auto_reply_subject, $this->website);
  4126.  
  4127. /**************************
  4128. Are there files to attach to the autoreply?
  4129. **************************/
  4130.  
  4131. if($this->reply_attach_files != '' && is_array($this->reply_attach_files) && $this->jkbLicenseType > 1)
  4132. {
  4133. foreach($this->reply_attach_files as $aK=>$attachF)
  4134. {
  4135.  
  4136. $aHandle = fopen($attachF, "rb");
  4137. $aContents = fread($aHandle, filesize($attachF));
  4138. fclose($aHandle);
  4139. if(is_numeric($aK))
  4140. {
  4141. /*try to grab the file name only*/
  4142. $path_parts = pathinfo($attachF);
  4143. $aName = $path_parts['basename'];
  4144. }
  4145. else
  4146. {
  4147. $aName = $aK;
  4148. }
  4149.  
  4150. $mail->AddStringAttachment($aContents, $aName);
  4151. }//end of foreach
  4152.  
  4153.  
  4154. }//end of reply_attach_files
  4155.  
  4156. //$mail->AltBody = "Alt body here";
  4157.  
  4158. $emailTypesToTry = array();
  4159.  
  4160. if(!$mail->Send())
  4161. {
  4162. echo "Message could not be sent. ";
  4163. echo "Mailer Error: " . $mail->ErrorInfo;
  4164. }
  4165. else
  4166. {
  4167. if($this->redirect != "")
  4168. {
  4169. //nothing
  4170.  
  4171. }
  4172. else
  4173. {
  4174. printf($this->auto_reply_confirm, $this->p_vars['email']);
  4175. }
  4176. }
  4177.  
  4178.  
  4179. }//end of function autoreply
  4180.  
  4181. function webmaster_notify()
  4182. {
  4183. $offset1 = $this->offset * 60 * 60;
  4184. $now = date($this->date_format, mktime() + $offset1);
  4185.  
  4186. $message_body = str_replace("<br>", "
  4187. ", $this->webmaster_body);
  4188. $message_body = stripslashes($message_body);
  4189. $this->webmaster_body = stripslashes($this->webmaster_body);
  4190.  
  4191. $mail = new phpmailer();
  4192. switch($this->email_type)
  4193. {
  4194. case 1:
  4195. $mail->IsSMTP();
  4196. break;
  4197. case 2:
  4198. $mail->IsMail();
  4199. break;
  4200. case 3:
  4201. $mail->IsQmail();
  4202. break;
  4203. case 4:
  4204. $mail->IsSendmail();
  4205. break;
  4206. default:
  4207. $mail->IsSMTP();
  4208. }
  4209.  
  4210. $mail->Host = $this->host; // specify main and backup server
  4211. $mail->SMTPAuth = $this->authorization; // turn on SMTP authentication
  4212. if(isset($this->ssl) && ($this->ssl == true || $this->ssl == 1)){
  4213. $mail->SMTPSecure = 'ssl';
  4214. }
  4215. if(isset($this->port) && $this->port != ''){
  4216. $mail->Port = $this->port;
  4217. }
  4218. if($this->authorization == "true")
  4219. {
  4220. $mail->Username = $this->username;
  4221. $mail->Password = $this->password;
  4222. }
  4223. //did this in 2.6 to fix for forms without any email
  4224. if(isset($this->p_vars['email']) && $this->p_vars['email'] != "")
  4225. {
  4226. $mail->From = $this->p_vars['email'];
  4227. $mail->FromName = $this->p_vars['email'];
  4228. }
  4229. else
  4230. {
  4231. $mail->From = $this->recipient[0];
  4232. $mail->FromName = $this->recipient[0];
  4233. }
  4234. if(isset($this->webmaster_from_override) && $this->webmaster_from_override != '') {
  4235. $mail->From = $this->webmaster_from_override;
  4236. $mail->FromName = $this->webmaster_from_override;
  4237. }
  4238.  
  4239. if(is_array($this->recipient))
  4240. {
  4241. foreach($this->recipient as $to)
  4242. {
  4243. $mail->AddAddress($to);
  4244. }
  4245. }
  4246. else
  4247. {
  4248. $mail->AddAddress($this->recipient);
  4249. } // name is optional
  4250. //did this in 2.6 to fix for forms without any email
  4251. if(isset($this->p_vars['email']) && $this->p_vars['email'] != "")
  4252. {
  4253. $mail->AddReplyTo($this->p_vars['email']);
  4254. }
  4255. else
  4256. {
  4257. $mail->AddReplyTo($this->recipient[0]);
  4258. }
  4259.  
  4260. if(isset($this->p_file) && $this->p_file != "")
  4261. {
  4262.  
  4263. foreach($this->p_file as $pkey=>$pvalue)
  4264. {
  4265. if(isset($pvalue['tmp_name']) && $pvalue['name'] != "" && $this->send_attachment == '1')
  4266. {
  4267. $mail->AddAttachment($pvalue['tmp_name'], $pvalue['name']); // add attachments
  4268. }
  4269. }
  4270. }
  4271.  
  4272. $mail->Subject = sprintf($this->webmaster_subject, $this->website);
  4273.  
  4274. if(isset($this->bcc) && $this->bcc != '')
  4275. {
  4276. if(!is_array($this->bcc))
  4277. {
  4278. $mail->AddBCC($this->bcc);
  4279. }
  4280. else
  4281. {
  4282. foreach($this->bcc as $bccc)
  4283. {
  4284. $mail->AddBCC($bccc);
  4285. }
  4286. }
  4287. }
  4288.  
  4289. if(isset($this->cc) && $this->cc != '')
  4290. {
  4291. if(!is_array($this->cc))
  4292. {
  4293. $mail->AddCC($this->cc);
  4294. }
  4295. else
  4296. {
  4297. foreach($this->cc as $ccc)
  4298. {
  4299. $mail->AddCC($ccc);
  4300. }
  4301. }
  4302. }
  4303.  
  4304. if(isset($this->webmaster_html) && ($this->webmaster_html == '1'))
  4305. {
  4306. $mail->IsHTML(true); // set email format to HTML
  4307.  
  4308. $rcpt_array = array('email_content','background_image_location');
  4309. $this->keep_these = array_merge($this->keep_these, $rcpt_array);
  4310.  
  4311. $email_content = sprintf($this->webmaster_body_intro, $now) . $this->webmaster_body;
  4312. $mail_merge = array('email_content' => $email_content);
  4313. $mail_merge = array_merge($mail_merge, $this->p_vars);//3.3
  4314. if(!isset($this->template_bg_image_dir) || $this->template_bg_image_dir == '') $mail_merge['background_image_location']= 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/template/';
  4315. else $mail_merge['background_image_location'] = $this->template_bg_image_dir;
  4316.  
  4317. $tpl = & new MailMerge;
  4318. $tpl->set('email_content', sprintf($this->webmaster_body_intro, $now) . $this->webmaster_body);
  4319. if(!isset($this->template_bg_image_dir) || $this->template_bg_image_dir == '') $tpl->set('background_image_location', 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/template/');
  4320. else $tpl->set('background_image_location', $this->template_bg_image_dir);
  4321.  
  4322. $mail->Body = $tpl->plug($this->webmaster_template, $this->keep_these, $mail_merge);
  4323. /*print $mail->Body;
  4324. print "<br>".$this->webmaster_template;
  4325. print "<br>";
  4326. print_r($this->keep_these);
  4327. print "<br>";
  4328. print_r($mail_merge);
  4329. exit;*/
  4330. $searchAr = array('<br>','<br />');
  4331. $replaceAr = '';
  4332. $mail->AltBody = str_replace($searchAr, $replaceAr, sprintf($this->webmaster_body_intro_alt, $now) . $message_body);
  4333.  
  4334. }
  4335. else
  4336. {
  4337. /*$rcpt_array = array('email_content');
  4338. $this->keep_these = array_merge($this->keep_these, $rcpt_array);
  4339. $email_content = sprintf($this->webmaster_body_intro, $now) . $this->webmaster_body;
  4340. $mail_merge = array('email_content' => $email_content);
  4341.  
  4342.  
  4343. $tpl = & new MailMerge;
  4344. $tpl->set('email_content', sprintf($this->webmaster_body_intro, $now) . $this->webmaster_body);
  4345. $mail->Body = $this->html_to_text($tpl->plug($this->webmaster_template, $this->keep_these, $mail_merge));
  4346. */
  4347. $mail->Body = sprintf($this->webmaster_body_intro, $now) . $message_body;
  4348. }
  4349. // = "Alt body here";
  4350.  
  4351. if(!$mail->Send())
  4352. {
  4353. echo "Message could not be sent. ";
  4354. echo "Mailer Error: " . $mail->ErrorInfo;
  4355. }
  4356. else
  4357. {
  4358. if($this->redirect != "")
  4359. {
  4360. //nothing
  4361. }
  4362. else
  4363. {
  4364. if(is_array($this->recipient))
  4365. {
  4366. foreach($this->recipient as $to)
  4367. {
  4368. printf($this->webmaster_confirm, $to);
  4369. }
  4370. }
  4371. else
  4372. {
  4373. printf($this->webmaster_confirm, $this->recipient);
  4374. }
  4375. }
  4376. }
  4377. }//end of function webmaster_notify
  4378.  
  4379. function database_put($variable_array)
  4380. {
  4381. $db = &new UFMdb;
  4382. $db->connect($this->database);
  4383. $new = MailMerge::clean_array($variable_array, $this->p_vars);
  4384. foreach($variable_array as $vv)
  4385. {
  4386. if(isset($this->p_vars[$vv]) && $this->p_vars[$vv] != "")
  4387. {
  4388. $first_part .= $vv . ", ";
  4389. }
  4390. }
  4391. foreach($new as $ne=>$va)
  4392. {
  4393. if(isset($va) && $va != "")
  4394. {
  4395. $va = mysql_real_escape_string($va);
  4396. $second_part .= "'" . $va . "', ";
  4397. }
  4398. }
  4399.  
  4400. $sql = "INSERT INTO " . $this->database['table'] . " (" . substr($first_part, 0 , -2) . ") VALUES (" . substr($second_part, 0, -2) . ")";
  4401. //print $sql;
  4402. $db->query($sql);
  4403.  
  4404. }//end of database_put()
  4405.  
  4406. function thanks_page()
  4407. {
  4408. if($this->redirect != "" && (!isset($this->error_message)))
  4409. {
  4410. $page = $this->redirect;
  4411. header("Location: $page");
  4412. exit;
  4413. }
  4414. }//end of function thanks_page
  4415.  
  4416. /******************************/
  4417.  
  4418. // function to check the banlist
  4419. function check_banlist($email)
  4420. {
  4421. $allow = 0;
  4422. if (count($this->banlist))
  4423. {
  4424. $allow = true;
  4425. foreach($this->banlist as $banned)
  4426. {
  4427. $temp = explode("@", $banned);
  4428. if ($temp[0] == "*")
  4429. {
  4430. $temp2 = explode("@", $email);
  4431. if(count($temp2) == '2')
  4432. {
  4433. if (trim(strtolower($temp2[1])) == trim(strtolower($temp[1])))
  4434. {
  4435. $allow = 0;
  4436. }
  4437. }
  4438. }
  4439. else {
  4440.  
  4441. if (trim(strtolower($email)) == trim(strtolower($banned)))
  4442. {
  4443. $allow = 0;
  4444. }
  4445. }
  4446. }
  4447. }
  4448. return $allow;
  4449. }//end check_banlist function
  4450.  
  4451. /************************************/
  4452.  
  4453. function check_files($files)
  4454. {
  4455. $no = 1;
  4456. $total_size = '0';
  4457. foreach($files as $key=>$value)
  4458. {
  4459. $size = (int) $value['size']/1024;
  4460.  
  4461. $total_size = $size + $total_size;
  4462. $name = $value['name'];
  4463. $test = explode(".", $value['name']);
  4464. $last_part = count($test)-1;
  4465. $ext = $test[$last_part];
  4466.  
  4467. if(in_array($ext, $this->banned_ext))
  4468. {
  4469. $this->error_message = sprintf($this->file_type_error, $ext);
  4470. break;
  4471. }
  4472.  
  4473. if($size > $this->file_max_size)
  4474. {
  4475. $this->error_message = sprintf($this->file_size_error, $size, $this->file_max_size);
  4476. break;
  4477. }
  4478.  
  4479. if($total_size > $this->file_max_size_total)
  4480. {
  4481. $this->error_message = sprintf($this->total_file_size_error, $total_size, $this->file_max_size_total);
  4482. break;
  4483. }
  4484.  
  4485. $attach['name'] = $name;
  4486. $attach['tmp_name'] = $value['tmp_name'];
  4487. $attach['size'] = $size;
  4488.  
  4489. $attachment[] = $attach;
  4490. if($name != '') {
  4491. $this->webmaster_body .= sprintf($this->post_info, 'File - '.$no, $name);
  4492. $no++;
  4493. }
  4494. }//end of foreach files
  4495.  
  4496. $this->total_attachment_size = $total_size;
  4497.  
  4498. }//end of check_files function
  4499.  
  4500. /**************************************/
  4501.  
  4502. function file_save()
  4503. {
  4504.  
  4505.  
  4506. if(isset($this->p_file) && $this->p_file != "")
  4507. {
  4508.  
  4509. foreach($this->p_file as $pkey=>$pvalue)
  4510. {
  4511. if(isset($pvalue['tmp_name']) && $pvalue['name'] != "")
  4512. {
  4513. if (!@move_uploaded_file($pvalue['tmp_name'], $this->file_save_dir . '/' . $this->file_name_array[$pkey]))
  4514. {
  4515. // error moving file. check file permissions.
  4516. unlink($file_tmp);
  4517. $this->error_message = "Unable to move file to designated directory.<br>";
  4518.  
  4519. }
  4520. else
  4521. {
  4522. /****/
  4523. /*add file name to db and post variables*/
  4524. /***/
  4525. //$file_name_array_tmp = array('file_name'=>$pvalue['name']);
  4526.  
  4527. /*$file_name_array_tmp = array($pkey);
  4528. $this->keep_these = array_merge($this->keep_these, $file_name_array_tmp);
  4529. $file_name_array_tmp = array($pkey=>$this->file_upload_name);
  4530. $this->p_vars = array_merge($this->p_vars, $file_name_array_tmp);*/
  4531.  
  4532.  
  4533. //unlink($pvalue['tmp_name']);
  4534.  
  4535.  
  4536. }
  4537.  
  4538.  
  4539. }
  4540. }
  4541. }
  4542.  
  4543. }//end of file_save()
  4544.  
  4545. /****************************************/
  4546.  
  4547.  
  4548. function convert_language($html, $language)
  4549. {
  4550. if($html)
  4551. //if($html)
  4552. {
  4553. $lang = str_replace("\n", "<br>", $language);
  4554. }
  4555. else
  4556. {
  4557. $lang = str_replace("<br><br>", '
  4558. ', $language);
  4559. $lang = str_replace('<br>','', $lang);
  4560.  
  4561. }
  4562.  
  4563. return $lang;
  4564. }//end of convert language function
  4565.  
  4566.  
  4567. function dataCleaner($postVars)
  4568. {
  4569. $postKeys = array_keys($postVars);
  4570.  
  4571. if(is_array($this->onlyAllow))
  4572. {
  4573. $postKeeper = array_intersect($this->onlyAllow, $postKeys);
  4574. }
  4575. else
  4576. {
  4577. $postKeeper = $postKeys;
  4578. }
  4579. /*************/
  4580. foreach($postKeeper as $pk)
  4581. {
  4582. if(!is_array($postVars[$pk]))
  4583. {
  4584. if(isset($this->lengthSpecifics[$pk]) && is_array($this->lengthSpecifics) && $this->lengthSpecifics[$pk] != '')
  4585. {
  4586. $one[$pk] = substr($postVars[$pk],0,$this->lengthSpecifics[$pk]);
  4587.  
  4588. }
  4589. else
  4590. {
  4591. $one[$pk] = substr($postVars[$pk],0,$this->lengthDefault);
  4592.  
  4593. }
  4594.  
  4595. if(!in_array($pk, $this->emailFieldValues))
  4596. {
  4597. $two[$pk] = str_replace('@','[at-symbol]',$one[$pk]);
  4598. }
  4599. else
  4600. {
  4601. $bad = array("\r","\n");
  4602. $good = '[carriage-return]';
  4603. $two[$pk] = str_replace($bad, $good ,$one[$pk]);
  4604. if(substr_count($two[$pk], '@') > 1)
  4605. {
  4606. $this->error_message .= 'Sending more than one email is not allowed';
  4607. }
  4608. }
  4609. }
  4610. /****************/
  4611. else
  4612. {/*pk is array*/
  4613. foreach($postVars[$pk] as $apk)
  4614. {
  4615. if(isset($this->lengthSpecifics[$pk]) && is_array($this->lengthSpecifics) && $this->lengthSpecifics[$pk] != '')
  4616. {
  4617. $carr[] = substr($apk,0,$this->lengthSpecifics[$pk]);
  4618.  
  4619. }
  4620. else
  4621. {
  4622. $carr[] = substr($apk,0,$this->lengthDefault);
  4623.  
  4624. }
  4625. }//foreach apk
  4626. $one[$pk] = $carr;
  4627. unset($carr);
  4628.  
  4629. foreach($one[$pk] as $opk)
  4630. {
  4631. if(!in_array($pk, $this->emailFieldValues))
  4632. {
  4633. $two[$pk][] = str_replace('@','[at-symbol]',$opk);
  4634. }
  4635. else
  4636. {
  4637. $bad = array("\r","\n");
  4638. $good = '[carriage-return]';
  4639. $cr = str_replace($bad, $good ,$opk);
  4640. if(substr_count($cr, '@') > 1)
  4641. {
  4642. $this->error_message .= 'Sending more than one email is not allowed';
  4643. }
  4644. else
  4645. {
  4646. $two[$pk][] = $cr;
  4647. }
  4648. }
  4649. }//foreach opk
  4650. }//end of pk is array
  4651. }//foreach pk
  4652. return $two;
  4653. }//end of dataCleaner()
  4654.  
  4655.  
  4656. function antiSpam() {
  4657. session_start();
  4658. $antiS = FALSE;
  4659. if(isset($_SESSION[$this->tokenName]) && $_SESSION[$this->tokenName] != '' && isset($_POST[$this->tokenPostName]) && $_POST[$this->tokenPostName] != '')
  4660. {
  4661. if($_SESSION[$this->tokenName] == md5($_POST[$this->tokenPostName].$_SESSION[$this->tokenTimeStamp]))
  4662. {
  4663. $debugCompare = md5($_POST[$this->tokenPostName].$_SESSION[$this->tokenTimeStamp]);
  4664. /*Now we check to see if there is a time limit on sending form data
  4665. and if so, check to see if too much time has passed*/
  4666. if(isset($_SESSION[$this->timeToLive]) && $_SESSION[$this->timeToLive] != '' && $_SESSION[$this->timeToLive] != 0)
  4667. {
  4668. //ttl is a value we need to compare against the session info
  4669. if(isset($_SESSION[$this->tokenTimeStamp]) && $_SESSION[$this->tokenTimeStamp] != '' && ($_SESSION[$this->tokenTimeStamp] + $_SESSION[$this->timeToLive]) > time())
  4670. {
  4671. $antiS = TRUE;
  4672. }
  4673.  
  4674. }
  4675. else
  4676. {
  4677. $antiS = TRUE;
  4678. }//end of no ttl or ttl = 0
  4679. }
  4680.  
  4681. }
  4682. if(!$antiS)
  4683. {
  4684. $this->error_message .= $this->token_error;
  4685. }
  4686. }//end of antiSpam()
  4687.  
  4688.  
  4689. function formatEmailContent($kd) {
  4690. if($this->convertUnderscore == 1)
  4691. {
  4692. $kd = str_replace('_', ' ', $kd);
  4693. }
  4694. if($this->convertDash == 1)
  4695. {
  4696. $kd = str_replace('-', ' ', $kd);
  4697. }
  4698. switch($this->formatStyle)
  4699. {
  4700. case 1:
  4701. //Title case
  4702. $kd = ucwords(strtolower($kd));
  4703. break;
  4704. case 2:
  4705. //Sentence case
  4706. $kd = ucfirst(strtolower($kd));
  4707. break;
  4708. case 3:
  4709. //Upper all
  4710. $kd = strtoupper($kd);
  4711. break;
  4712.  
  4713. default:
  4714. //nothing
  4715. break;
  4716. }//switch
  4717. return $kd;
  4718. }//function formatEmailContent
  4719.  
  4720. function mailList($postVars) {
  4721. if($this->mail_list != '')/*Should already be set*/
  4722. {
  4723. if(@include 'includes/Snoopy.class.php'){
  4724. $snoopy = new Snoopy;
  4725.  
  4726. $submit_url = $this->mail_list_url;
  4727. $snoopy->submit($submit_url,$postVars);
  4728. }//end of successful include
  4729. else
  4730. {
  4731. /*possible error reporting here*/
  4732. }
  4733. return;
  4734. }//if mail_list
  4735. }//end of mailList()
  4736.  
  4737. function extra_perform($fileToUse){
  4738. if(is_file($fileToUse))
  4739. {
  4740. @include($fileToUse);
  4741. }
  4742. return;
  4743. }//end of extra_perform
  4744.  
  4745. function confirmationPage() {
  4746. if(!$this->confirmButton || $this->confirmButton == '')
  4747. {
  4748. $label = 'Confirm';
  4749. }
  4750. else
  4751. {
  4752. $label = $this->confirmButton;
  4753. }
  4754. $hidden = '<input type="hidden" name="confirmFinal" value="1" />';
  4755. if($this->tokenPostName && $this->tokenPostName != '' && isset($_POST[$this->tokenPostName]) && $_POST[$this->tokenPostName] != '') {
  4756. $hidden .= '<input type="hidden" name="'.$this->tokenPostName.'" value="'.htmlspecialchars($_POST[$this->tokenPostName]).'" />';
  4757. }
  4758. foreach($this->p_vars as $k=>$v)
  4759. {
  4760. if(!in_array($k, $this->keep_these)) continue;
  4761. if(!is_array($v)) {
  4762. $confirmation .= $k .' &raquo; '.$v.'<br />
  4763. ';
  4764. $hidden .= '<input type="hidden" name="'.$k.'" value="'.htmlspecialchars($v).'" />
  4765. ';
  4766. }
  4767. else
  4768. {
  4769.  
  4770. foreach($v as $kk=>$vv) {
  4771. $num = $kk + 1;
  4772. $confirmation .= $k .'-'.$num.' &raquo; '.$vv.'<br />
  4773. ';
  4774. $hidden .= '<input type="hidden" name="'.$k.'[]" value="'.$vv.'" />
  4775. ';
  4776. }
  4777. }
  4778. }
  4779. $formAction = $_SERVER['PHP_SELF'];
  4780. if(isset($_GET['cid']) && $_GET['cid'] != ''){
  4781. $formAction .= '?cid='.$_GET['cid'];
  4782. }
  4783. $confirmationContent = '<form action="'.$formAction.'" method="post" enctype="multipart/form-data" name="form1" id="form1">
  4784. '.$confirmation.'
  4785. <input type="submit" name="Submit" value="'.$label.'" />
  4786. '.$hidden.'</form>';
  4787.  
  4788. $gen = array('email_content');
  4789. $this->confirm_array = array_merge($this->keep_these, $gen);
  4790. $mail_merge = array('email_content' => $confirmationContent);
  4791.  
  4792. $tpl = & new MailMerge('');
  4793. $tpl->set('email_content', $confirmationContent);
  4794. session_start();
  4795. echo $tpl->plug($this->confirmation_template, $this->confirm_array, $mail_merge);
  4796. exit;
  4797. }//end of confirmationPage
  4798.  
  4799. }//end of class
  4800.  
  4801. /*=============
  4802. Leave these next several lines alone
  4803. ==============*/
  4804. $obj = new UFMail;
  4805. $obj->initialize($set); //Gets things going
  4806. $obj->check_vars(); //Runs the error checking
  4807. $obj->branch(); //Sends the emails
  4808. $obj->thanks_page(); /* Redirects if the corresponding variable is set */
  4809. ?>
Add Comment
Please, Sign In to add comment