class.phpmailer.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  1. <?php
  2. ////////////////////////////////////////////////////
  3. // PHPMailer - PHP email class
  4. //
  5. // Class for sending email using either
  6. // sendmail, PHP mail(), or SMTP. Methods are
  7. // based upon the standard AspEmail(tm) classes.
  8. //
  9. // Copyright (C) 2001 - 2003 Brent R. Matzelle
  10. //
  11. // License: LGPL, see LICENSE
  12. ////////////////////////////////////////////////////
  13. /**
  14. * PHPMailer - PHP email transport class
  15. * @package PHPMailer
  16. * @author Brent R. Matzelle
  17. * @copyright 2001 - 2003 Brent R. Matzelle
  18. */
  19. class PHPMailer
  20. {
  21. /////////////////////////////////////////////////
  22. // PUBLIC VARIABLES
  23. /////////////////////////////////////////////////
  24. /**
  25. * Email priority (1 = High, 3 = Normal, 5 = low).
  26. * @var int
  27. */
  28. var $Priority = 3;
  29. /**
  30. * Sets the CharSet of the message.
  31. * @var string
  32. */
  33. var $CharSet = "iso-8859-1";
  34. /**
  35. * Sets the Content-type of the message.
  36. * @var string
  37. */
  38. var $ContentType = "text/plain";
  39. /**
  40. * Sets the Encoding of the message. Options for this are "8bit",
  41. * "7bit", "binary", "base64", and "quoted-printable".
  42. * @var string
  43. */
  44. var $Encoding = "8bit";
  45. /**
  46. * Holds the most recent mailer error message.
  47. * @var string
  48. */
  49. var $ErrorInfo = "";
  50. /**
  51. * Sets the From email address for the message.
  52. * @var string
  53. */
  54. var $From = "root@localhost";
  55. /**
  56. * Sets the From name of the message.
  57. * @var string
  58. */
  59. var $FromName = "Root User";
  60. /**
  61. * Sets the Sender email (Return-Path) of the message. If not empty,
  62. * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  63. * @var string
  64. */
  65. var $Sender = "";
  66. /**
  67. * Sets the Subject of the message.
  68. * @var string
  69. */
  70. var $Subject = "";
  71. /**
  72. * Sets the Body of the message. This can be either an HTML or text body.
  73. * If HTML then run IsHTML(true).
  74. * @var string
  75. */
  76. var $Body = "";
  77. /**
  78. * Sets the text-only body of the message. This automatically sets the
  79. * email to multipart/alternative. This body can be read by mail
  80. * clients that do not have HTML email capability such as mutt. Clients
  81. * that can read HTML will view the normal Body.
  82. * @var string
  83. */
  84. var $AltBody = "";
  85. /**
  86. * Sets word wrapping on the body of the message to a given number of
  87. * characters.
  88. * @var int
  89. */
  90. var $WordWrap = 0;
  91. /**
  92. * Method to send mail: ("mail", "sendmail", or "smtp").
  93. * @var string
  94. */
  95. var $Mailer = "mail";
  96. /**
  97. * Sets the path of the sendmail program.
  98. * @var string
  99. */
  100. var $Sendmail = "/usr/sbin/sendmail";
  101. /**
  102. * Path to PHPMailer plugins. This is now only useful if the SMTP class
  103. * is in a different directory than the PHP include path.
  104. * @var string
  105. */
  106. var $PluginDir = "";
  107. /**
  108. * Holds PHPMailer version.
  109. * @var string
  110. */
  111. var $Version = "1.73";
  112. /**
  113. * Sets the email address that a reading confirmation will be sent.
  114. * @var string
  115. */
  116. var $ConfirmReadingTo = "";
  117. /**
  118. * Sets the hostname to use in Message-Id and Received headers
  119. * and as default HELO string. If empty, the value returned
  120. * by SERVER_NAME is used or 'localhost.localdomain'.
  121. * @var string
  122. */
  123. var $Hostname = "";
  124. /////////////////////////////////////////////////
  125. // SMTP VARIABLES
  126. /////////////////////////////////////////////////
  127. /**
  128. * Sets the SMTP hosts. All hosts must be separated by a
  129. * semicolon. You can also specify a different port
  130. * for each host by using this format: [hostname:port]
  131. * (e.g. "smtp1.example.com:25;smtp2.example.com").
  132. * Hosts will be tried in order.
  133. * @var string
  134. */
  135. var $Host = "localhost";
  136. /**
  137. * Sets the default SMTP server port.
  138. * @var int
  139. */
  140. var $Port = 25;
  141. /**
  142. * Sets the SMTP HELO of the message (Default is $Hostname).
  143. * @var string
  144. */
  145. var $Helo = "";
  146. /**
  147. * Sets SMTP authentication. Utilizes the Username and Password variables.
  148. * @var bool
  149. */
  150. var $SMTPAuth = false;
  151. /**
  152. * Sets SMTP username.
  153. * @var string
  154. */
  155. var $Username = "";
  156. /**
  157. * Sets SMTP password.
  158. * @var string
  159. */
  160. var $Password = "";
  161. /**
  162. * Sets the SMTP server timeout in seconds. This function will not
  163. * work with the win32 version.
  164. * @var int
  165. */
  166. var $Timeout = 10;
  167. /**
  168. * Sets SMTP class debugging on or off.
  169. * @var bool
  170. */
  171. var $SMTPDebug = false;
  172. /**
  173. * Prevents the SMTP connection from being closed after each mail
  174. * sending. If this is set to true then to close the connection
  175. * requires an explicit call to SmtpClose().
  176. * @var bool
  177. */
  178. var $SMTPKeepAlive = false;
  179. /**#@+
  180. * @access private
  181. */
  182. var $smtp = NULL;
  183. var $to = array();
  184. var $cc = array();
  185. var $bcc = array();
  186. var $ReplyTo = array();
  187. var $attachment = array();
  188. var $CustomHeader = array();
  189. var $message_type = "";
  190. var $boundary = array();
  191. var $language = array();
  192. var $error_count = 0;
  193. var $LE = "\n";
  194. /**#@-*/
  195. /////////////////////////////////////////////////
  196. // VARIABLE METHODS
  197. /////////////////////////////////////////////////
  198. /**
  199. * Sets message type to HTML.
  200. * @param bool $bool
  201. * @return void
  202. */
  203. function IsHTML($bool) {
  204. if($bool == true)
  205. $this->ContentType = "text/html";
  206. else
  207. $this->ContentType = "text/plain";
  208. }
  209. /**
  210. * Sets Mailer to send message using SMTP.
  211. * @return void
  212. */
  213. function IsSMTP() {
  214. $this->Mailer = "smtp";
  215. }
  216. /**
  217. * Sets Mailer to send message using PHP mail() function.
  218. * @return void
  219. */
  220. function IsMail() {
  221. $this->Mailer = "mail";
  222. }
  223. /**
  224. * Sets Mailer to send message using the $Sendmail program.
  225. * @return void
  226. */
  227. function IsSendmail() {
  228. $this->Mailer = "sendmail";
  229. }
  230. /**
  231. * Sets Mailer to send message using the qmail MTA.
  232. * @return void
  233. */
  234. function IsQmail() {
  235. $this->Sendmail = "/var/qmail/bin/sendmail";
  236. $this->Mailer = "sendmail";
  237. }
  238. /////////////////////////////////////////////////
  239. // RECIPIENT METHODS
  240. /////////////////////////////////////////////////
  241. /**
  242. * Adds a "To" address.
  243. * @param string $address
  244. * @param string $name
  245. * @return void
  246. */
  247. function AddAddress($address, $name = "") {
  248. $cur = count($this->to);
  249. $this->to[$cur][0] = trim($address);
  250. $this->to[$cur][1] = $name;
  251. }
  252. /**
  253. * Adds a "Cc" address. Note: this function works
  254. * with the SMTP mailer on win32, not with the "mail"
  255. * mailer.
  256. * @param string $address
  257. * @param string $name
  258. * @return void
  259. */
  260. function AddCC($address, $name = "") {
  261. $cur = count($this->cc);
  262. $this->cc[$cur][0] = trim($address);
  263. $this->cc[$cur][1] = $name;
  264. }
  265. /**
  266. * Adds a "Bcc" address. Note: this function works
  267. * with the SMTP mailer on win32, not with the "mail"
  268. * mailer.
  269. * @param string $address
  270. * @param string $name
  271. * @return void
  272. */
  273. function AddBCC($address, $name = "") {
  274. $cur = count($this->bcc);
  275. $this->bcc[$cur][0] = trim($address);
  276. $this->bcc[$cur][1] = $name;
  277. }
  278. /**
  279. * Adds a "Reply-to" address.
  280. * @param string $address
  281. * @param string $name
  282. * @return void
  283. */
  284. function AddReplyTo($address, $name = "") {
  285. $cur = count($this->ReplyTo);
  286. $this->ReplyTo[$cur][0] = trim($address);
  287. $this->ReplyTo[$cur][1] = $name;
  288. }
  289. /////////////////////////////////////////////////
  290. // MAIL SENDING METHODS
  291. /////////////////////////////////////////////////
  292. /**
  293. * Creates message and assigns Mailer. If the message is
  294. * not sent successfully then it returns false. Use the ErrorInfo
  295. * variable to view description of the error.
  296. * @return bool
  297. */
  298. function Send() {
  299. $header = "";
  300. $body = "";
  301. $result = true;
  302. if((count($this->to) + count($this->cc) + count($this->bcc)) < 1)
  303. {
  304. $this->SetError($this->Lang("provide_address"));
  305. return false;
  306. }
  307. // Set whether the message is multipart/alternative
  308. if(!empty($this->AltBody))
  309. $this->ContentType = "multipart/alternative";
  310. $this->error_count = 0; // reset errors
  311. $this->SetMessageType();
  312. $header .= $this->CreateHeader();
  313. $body = $this->CreateBody();
  314. if($body == "") { return false; }
  315. // Choose the mailer
  316. switch($this->Mailer)
  317. {
  318. case "sendmail":
  319. $result = $this->SendmailSend($header, $body);
  320. break;
  321. case "mail":
  322. $result = $this->MailSend($header, $body);
  323. break;
  324. case "smtp":
  325. $result = $this->SmtpSend($header, $body);
  326. break;
  327. default:
  328. $this->SetError($this->Mailer . $this->Lang("mailer_not_supported"));
  329. $result = false;
  330. break;
  331. }
  332. return $result;
  333. }
  334. /**
  335. * Sends mail using the $Sendmail program.
  336. * @access private
  337. * @return bool
  338. */
  339. function SendmailSend($header, $body) {
  340. if ($this->Sender != "")
  341. $sendmail = sprintf("%s -oi -f %s -t",
  342. escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  343. else
  344. $sendmail = sprintf("%s -oi -t",
  345. escapeshellcmd($this->Sendmail));
  346. if(!@$mail = popen($sendmail, "w"))
  347. {
  348. $this->SetError($this->Lang("execute") . $this->Sendmail);
  349. return false;
  350. }
  351. fputs($mail, $header);
  352. fputs($mail, $body);
  353. $result = pclose($mail) >> 8 & 0xFF;
  354. if($result != 0)
  355. {
  356. $this->SetError($this->Lang("execute") . $this->Sendmail);
  357. return false;
  358. }
  359. return true;
  360. }
  361. /**
  362. * Sends mail using the PHP mail() function.
  363. * @access private
  364. * @return bool
  365. */
  366. function MailSend($header, $body) {
  367. $to = "";
  368. for($i = 0; $i < count($this->to); $i++)
  369. {
  370. if($i != 0) { $to .= ", "; }
  371. $to .= $this->to[$i][0];
  372. }
  373. if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
  374. {
  375. $old_from = ini_get("sendmail_from");
  376. ini_set("sendmail_from", $this->Sender);
  377. $params = sprintf("-oi -f %s", $this->Sender);
  378. $rt = @mail($to, $this->EncodeHeader($this->Subject), $body,
  379. $header, $params);
  380. }
  381. else
  382. $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header);
  383. if (isset($old_from))
  384. ini_set("sendmail_from", $old_from);
  385. if(!$rt)
  386. {
  387. $this->SetError($this->Lang("instantiate"));
  388. return false;
  389. }
  390. return true;
  391. }
  392. /**
  393. * Sends mail via SMTP using PhpSMTP (Author:
  394. * Chris Ryan). Returns bool. Returns false if there is a
  395. * bad MAIL FROM, RCPT, or DATA input.
  396. * @access private
  397. * @return bool
  398. */
  399. function SmtpSend($header, $body) {
  400. include_once($this->PluginDir . "class.smtp.php");
  401. $error = "";
  402. $bad_rcpt = array();
  403. if(!$this->SmtpConnect())
  404. return false;
  405. $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender;
  406. if(!$this->smtp->Mail($smtp_from))
  407. {
  408. $error = $this->Lang("from_failed") . $smtp_from;
  409. $this->SetError($error);
  410. $this->smtp->Reset();
  411. return false;
  412. }
  413. // Attempt to send attach all recipients
  414. for($i = 0; $i < count($this->to); $i++)
  415. {
  416. if(!$this->smtp->Recipient($this->to[$i][0]))
  417. $bad_rcpt[] = $this->to[$i][0];
  418. }
  419. for($i = 0; $i < count($this->cc); $i++)
  420. {
  421. if(!$this->smtp->Recipient($this->cc[$i][0]))
  422. $bad_rcpt[] = $this->cc[$i][0];
  423. }
  424. for($i = 0; $i < count($this->bcc); $i++)
  425. {
  426. if(!$this->smtp->Recipient($this->bcc[$i][0]))
  427. $bad_rcpt[] = $this->bcc[$i][0];
  428. }
  429. if(count($bad_rcpt) > 0) // Create error message
  430. {
  431. for($i = 0; $i < count($bad_rcpt); $i++)
  432. {
  433. if($i != 0) { $error .= ", "; }
  434. $error .= $bad_rcpt[$i];
  435. }
  436. $error = $this->Lang("recipients_failed") . $error;
  437. $this->SetError($error);
  438. $this->smtp->Reset();
  439. return false;
  440. }
  441. if(!$this->smtp->Data($header . $body))
  442. {
  443. $this->SetError($this->Lang("data_not_accepted"));
  444. $this->smtp->Reset();
  445. return false;
  446. }
  447. if($this->SMTPKeepAlive == true)
  448. $this->smtp->Reset();
  449. else
  450. $this->SmtpClose();
  451. return true;
  452. }
  453. /**
  454. * Initiates a connection to an SMTP server. Returns false if the
  455. * operation failed.
  456. * @access private
  457. * @return bool
  458. */
  459. function SmtpConnect() {
  460. if($this->smtp == NULL) { $this->smtp = new SMTP(); }
  461. $this->smtp->do_debug = $this->SMTPDebug;
  462. $hosts = explode(";", $this->Host);
  463. $index = 0;
  464. $connection = ($this->smtp->Connected());
  465. // Retry while there is no connection
  466. while($index < count($hosts) && $connection == false)
  467. {
  468. if(strstr($hosts[$index], ":"))
  469. list($host, $port) = explode(":", $hosts[$index]);
  470. else
  471. {
  472. $host = $hosts[$index];
  473. $port = $this->Port;
  474. }
  475. if($this->smtp->Connect($host, $port, $this->Timeout))
  476. {
  477. if ($this->Helo != '')
  478. $this->smtp->Hello($this->Helo);
  479. else
  480. $this->smtp->Hello($this->ServerHostname());
  481. if($this->SMTPAuth)
  482. {
  483. if(!$this->smtp->Authenticate($this->Username,
  484. $this->Password))
  485. {
  486. $this->SetError($this->Lang("authenticate"));
  487. $this->smtp->Reset();
  488. $connection = false;
  489. }
  490. }
  491. $connection = true;
  492. }
  493. $index++;
  494. }
  495. if(!$connection)
  496. $this->SetError($this->Lang("connect_host"));
  497. return $connection;
  498. }
  499. /**
  500. * Closes the active SMTP session if one exists.
  501. * @return void
  502. */
  503. function SmtpClose() {
  504. if($this->smtp != NULL)
  505. {
  506. if($this->smtp->Connected())
  507. {
  508. $this->smtp->Quit();
  509. $this->smtp->Close();
  510. }
  511. }
  512. }
  513. /**
  514. * Sets the language for all class error messages. Returns false
  515. * if it cannot load the language file. The default language type
  516. * is English.
  517. * @param string $lang_type Type of language (e.g. Portuguese: "br")
  518. * @param string $lang_path Path to the language file directory
  519. * @access public
  520. * @return bool
  521. */
  522. function SetLanguage($lang_type, $lang_path = "language/") {
  523. if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php'))
  524. include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
  525. else if(file_exists($lang_path.'phpmailer.lang-en.php'))
  526. include($lang_path.'phpmailer.lang-en.php');
  527. else
  528. {
  529. $this->SetError("Could not load language file");
  530. return false;
  531. }
  532. $this->language = $PHPMAILER_LANG;
  533. return true;
  534. }
  535. /////////////////////////////////////////////////
  536. // MESSAGE CREATION METHODS
  537. /////////////////////////////////////////////////
  538. /**
  539. * Creates recipient headers.
  540. * @access private
  541. * @return string
  542. */
  543. function AddrAppend($type, $addr) {
  544. $addr_str = $type . ": ";
  545. $addr_str .= $this->AddrFormat($addr[0]);
  546. if(count($addr) > 1)
  547. {
  548. for($i = 1; $i < count($addr); $i++)
  549. $addr_str .= ", " . $this->AddrFormat($addr[$i]);
  550. }
  551. $addr_str .= $this->LE;
  552. return $addr_str;
  553. }
  554. /**
  555. * Formats an address correctly.
  556. * @access private
  557. * @return string
  558. */
  559. function AddrFormat($addr) {
  560. if(empty($addr[1]))
  561. $formatted = $addr[0];
  562. else
  563. {
  564. $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" .
  565. $addr[0] . ">";
  566. }
  567. return $formatted;
  568. }
  569. /**
  570. * Wraps message for use with mailers that do not
  571. * automatically perform wrapping and for quoted-printable.
  572. * Original written by philippe.
  573. * @access private
  574. * @return string
  575. */
  576. function WrapText($message, $length, $qp_mode = false) {
  577. $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  578. $message = $this->FixEOL($message);
  579. if (substr($message, -1) == $this->LE)
  580. $message = substr($message, 0, -1);
  581. $line = explode($this->LE, $message);
  582. $message = "";
  583. for ($i=0 ;$i < count($line); $i++)
  584. {
  585. $line_part = explode(" ", $line[$i]);
  586. $buf = "";
  587. for ($e = 0; $e<count($line_part); $e++)
  588. {
  589. $word = $line_part[$e];
  590. if ($qp_mode and (strlen($word) > $length))
  591. {
  592. $space_left = $length - strlen($buf) - 1;
  593. if ($e != 0)
  594. {
  595. if ($space_left > 20)
  596. {
  597. $len = $space_left;
  598. if (substr($word, $len - 1, 1) == "=")
  599. $len--;
  600. elseif (substr($word, $len - 2, 1) == "=")
  601. $len -= 2;
  602. $part = substr($word, 0, $len);
  603. $word = substr($word, $len);
  604. $buf .= " " . $part;
  605. $message .= $buf . sprintf("=%s", $this->LE);
  606. }
  607. else
  608. {
  609. $message .= $buf . $soft_break;
  610. }
  611. $buf = "";
  612. }
  613. while (strlen($word) > 0)
  614. {
  615. $len = $length;
  616. if (substr($word, $len - 1, 1) == "=")
  617. $len--;
  618. elseif (substr($word, $len - 2, 1) == "=")
  619. $len -= 2;
  620. $part = substr($word, 0, $len);
  621. $word = substr($word, $len);
  622. if (strlen($word) > 0)
  623. $message .= $part . sprintf("=%s", $this->LE);
  624. else
  625. $buf = $part;
  626. }
  627. }
  628. else
  629. {
  630. $buf_o = $buf;
  631. $buf .= ($e == 0) ? $word : (" " . $word);
  632. if (strlen($buf) > $length and $buf_o != "")
  633. {
  634. $message .= $buf_o . $soft_break;
  635. $buf = $word;
  636. }
  637. }
  638. }
  639. $message .= $buf . $this->LE;
  640. }
  641. return $message;
  642. }
  643. /**
  644. * Set the body wrapping.
  645. * @access private
  646. * @return void
  647. */
  648. function SetWordWrap() {
  649. if($this->WordWrap < 1)
  650. return;
  651. switch($this->message_type)
  652. {
  653. case "alt":
  654. // fall through
  655. case "alt_attachments":
  656. $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  657. break;
  658. default:
  659. $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  660. break;
  661. }
  662. }
  663. /**
  664. * Assembles message header.
  665. * @access private
  666. * @return string
  667. */
  668. function CreateHeader() {
  669. $result = "";
  670. // Set the boundaries
  671. $uniq_id = md5(uniqid(time()));
  672. $this->boundary[1] = "b1_" . $uniq_id;
  673. $this->boundary[2] = "b2_" . $uniq_id;
  674. $result .= $this->HeaderLine("Date", $this->RFCDate());
  675. if($this->Sender == "")
  676. $result .= $this->HeaderLine("Return-Path", trim($this->From));
  677. else
  678. $result .= $this->HeaderLine("Return-Path", trim($this->Sender));
  679. // To be created automatically by mail()
  680. if($this->Mailer != "mail")
  681. {
  682. if(count($this->to) > 0)
  683. $result .= $this->AddrAppend("To", $this->to);
  684. else if (count($this->cc) == 0)
  685. $result .= $this->HeaderLine("To", "undisclosed-recipients:;");
  686. if(count($this->cc) > 0)
  687. $result .= $this->AddrAppend("Cc", $this->cc);
  688. }
  689. $from = array();
  690. $from[0][0] = trim($this->From);
  691. $from[0][1] = $this->FromName;
  692. $result .= $this->AddrAppend("From", $from);
  693. // sendmail and mail() extract Bcc from the header before sending
  694. if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0))
  695. $result .= $this->AddrAppend("Bcc", $this->bcc);
  696. if(count($this->ReplyTo) > 0)
  697. $result .= $this->AddrAppend("Reply-to", $this->ReplyTo);
  698. // mail() sets the subject itself
  699. if($this->Mailer != "mail")
  700. $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject)));
  701. $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  702. $result .= $this->HeaderLine("X-Priority", $this->Priority);
  703. $result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]");
  704. if($this->ConfirmReadingTo != "")
  705. {
  706. $result .= $this->HeaderLine("Disposition-Notification-To",
  707. "<" . trim($this->ConfirmReadingTo) . ">");
  708. }
  709. // Add custom headers
  710. for($index = 0; $index < count($this->CustomHeader); $index++)
  711. {
  712. $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]),
  713. $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  714. }
  715. $result .= $this->HeaderLine("MIME-Version", "1.0");
  716. switch($this->message_type)
  717. {
  718. case "plain":
  719. $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
  720. $result .= sprintf("Content-Type: %s; charset=\"%s\"",
  721. $this->ContentType, $this->CharSet);
  722. break;
  723. case "attachments":
  724. // fall through
  725. case "alt_attachments":
  726. if($this->InlineImageExists())
  727. {
  728. $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
  729. "multipart/related", $this->LE, $this->LE,
  730. $this->boundary[1], $this->LE);
  731. }
  732. else
  733. {
  734. $result .= $this->HeaderLine("Content-Type", "multipart/mixed;");
  735. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  736. }
  737. break;
  738. case "alt":
  739. $result .= $this->HeaderLine("Content-Type", "multipart/alternative;");
  740. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  741. break;
  742. }
  743. if($this->Mailer != "mail")
  744. $result .= $this->LE.$this->LE;
  745. return $result;
  746. }
  747. /**
  748. * Assembles the message body. Returns an empty string on failure.
  749. * @access private
  750. * @return string
  751. */
  752. function CreateBody() {
  753. $result = "";
  754. $this->SetWordWrap();
  755. switch($this->message_type)
  756. {
  757. case "alt":
  758. $result .= $this->GetBoundary($this->boundary[1], "",
  759. "text/plain", "");
  760. $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  761. $result .= $this->LE.$this->LE;
  762. $result .= $this->GetBoundary($this->boundary[1], "",
  763. "text/html", "");
  764. $result .= $this->EncodeString($this->Body, $this->Encoding);
  765. $result .= $this->LE.$this->LE;
  766. $result .= $this->EndBoundary($this->boundary[1]);
  767. break;
  768. case "plain":
  769. $result .= $this->EncodeString($this->Body, $this->Encoding);
  770. break;
  771. case "attachments":
  772. $result .= $this->GetBoundary($this->boundary[1], "", "", "");
  773. $result .= $this->EncodeString($this->Body, $this->Encoding);
  774. $result .= $this->LE;
  775. $result .= $this->AttachAll();
  776. break;
  777. case "alt_attachments":
  778. $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
  779. $result .= sprintf("Content-Type: %s;%s" .
  780. "\tboundary=\"%s\"%s",
  781. "multipart/alternative", $this->LE,
  782. $this->boundary[2], $this->LE.$this->LE);
  783. // Create text body
  784. $result .= $this->GetBoundary($this->boundary[2], "",
  785. "text/plain", "") . $this->LE;
  786. $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  787. $result .= $this->LE.$this->LE;
  788. // Create the HTML body
  789. $result .= $this->GetBoundary($this->boundary[2], "",
  790. "text/html", "") . $this->LE;
  791. $result .= $this->EncodeString($this->Body, $this->Encoding);
  792. $result .= $this->LE.$this->LE;
  793. $result .= $this->EndBoundary($this->boundary[2]);
  794. $result .= $this->AttachAll();
  795. break;
  796. }
  797. if($this->IsError())
  798. $result = "";
  799. return $result;
  800. }
  801. /**
  802. * Returns the start of a message boundary.
  803. * @access private
  804. */
  805. function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  806. $result = "";
  807. if($charSet == "") { $charSet = $this->CharSet; }
  808. if($contentType == "") { $contentType = $this->ContentType; }
  809. if($encoding == "") { $encoding = $this->Encoding; }
  810. $result .= $this->TextLine("--" . $boundary);
  811. $result .= sprintf("Content-Type: %s; charset = \"%s\"",
  812. $contentType, $charSet);
  813. $result .= $this->LE;
  814. $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding);
  815. $result .= $this->LE;
  816. return $result;
  817. }
  818. /**
  819. * Returns the end of a message boundary.
  820. * @access private
  821. */
  822. function EndBoundary($boundary) {
  823. return $this->LE . "--" . $boundary . "--" . $this->LE;
  824. }
  825. /**
  826. * Sets the message type.
  827. * @access private
  828. * @return void
  829. */
  830. function SetMessageType() {
  831. if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)
  832. $this->message_type = "plain";
  833. else
  834. {
  835. if(count($this->attachment) > 0)
  836. $this->message_type = "attachments";
  837. if(strlen($this->AltBody) > 0 && count($this->attachment) < 1)
  838. $this->message_type = "alt";
  839. if(strlen($this->AltBody) > 0 && count($this->attachment) > 0)
  840. $this->message_type = "alt_attachments";
  841. }
  842. }
  843. /**
  844. * Returns a formatted header line.
  845. * @access private
  846. * @return string
  847. */
  848. function HeaderLine($name, $value) {
  849. return $name . ": " . $value . $this->LE;
  850. }
  851. /**
  852. * Returns a formatted mail line.
  853. * @access private
  854. * @return string
  855. */
  856. function TextLine($value) {
  857. return $value . $this->LE;
  858. }
  859. /////////////////////////////////////////////////
  860. // ATTACHMENT METHODS
  861. /////////////////////////////////////////////////
  862. /**
  863. * Adds an attachment from a path on the filesystem.
  864. * Returns false if the file could not be found
  865. * or accessed.
  866. * @param string $path Path to the attachment.
  867. * @param string $name Overrides the attachment name.
  868. * @param string $encoding File encoding (see $Encoding).
  869. * @param string $type File extension (MIME) type.
  870. * @return bool
  871. */
  872. function AddAttachment($path, $name = "", $encoding = "base64",
  873. $type = "application/octet-stream") {
  874. if(!@is_file($path))
  875. {
  876. $this->SetError($this->Lang("file_access") . $path);
  877. return false;
  878. }
  879. $filename = basename($path);
  880. if($name == "")
  881. $name = $filename;
  882. $cur = count($this->attachment);
  883. $this->attachment[$cur][0] = $path;
  884. $this->attachment[$cur][1] = $filename;
  885. $this->attachment[$cur][2] = $name;
  886. $this->attachment[$cur][3] = $encoding;
  887. $this->attachment[$cur][4] = $type;
  888. $this->attachment[$cur][5] = false; // isStringAttachment
  889. $this->attachment[$cur][6] = "attachment";
  890. $this->attachment[$cur][7] = 0;
  891. return true;
  892. }
  893. /**
  894. * Attaches all fs, string, and binary attachments to the message.
  895. * Returns an empty string on failure.
  896. * @access private
  897. * @return string
  898. */
  899. function AttachAll() {
  900. // Return text of body
  901. $mime = array();
  902. // Add all attachments
  903. for($i = 0; $i < count($this->attachment); $i++)
  904. {
  905. // Check for string attachment
  906. $bString = $this->attachment[$i][5];
  907. if ($bString)
  908. $string = $this->attachment[$i][0];
  909. else
  910. $path = $this->attachment[$i][0];
  911. $filename = $this->attachment[$i][1];
  912. $name = $this->attachment[$i][2];
  913. $encoding = $this->attachment[$i][3];
  914. $type = $this->attachment[$i][4];
  915. $disposition = $this->attachment[$i][6];
  916. $cid = $this->attachment[$i][7];
  917. $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
  918. $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
  919. $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  920. if($disposition == "inline")
  921. $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  922. $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s",
  923. $disposition, $name, $this->LE.$this->LE);
  924. // Encode as string attachment
  925. if($bString)
  926. {
  927. $mime[] = $this->EncodeString($string, $encoding);
  928. if($this->IsError()) { return ""; }
  929. $mime[] = $this->LE.$this->LE;
  930. }
  931. else
  932. {
  933. $mime[] = $this->EncodeFile($path, $encoding);
  934. if($this->IsError()) { return ""; }
  935. $mime[] = $this->LE.$this->LE;
  936. }
  937. }
  938. $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
  939. return join("", $mime);
  940. }
  941. /**
  942. * Encodes attachment in requested format. Returns an
  943. * empty string on failure.
  944. * @access private
  945. * @return string
  946. */
  947. function EncodeFile ($path, $encoding = "base64") {
  948. if(!@$fd = fopen($path, "rb"))
  949. {
  950. $this->SetError($this->Lang("file_open") . $path);
  951. return "";
  952. }
  953. $magic_quotes = get_magic_quotes_runtime();
  954. set_magic_quotes_runtime(0);
  955. $file_buffer = fread($fd, filesize($path));
  956. $file_buffer = $this->EncodeString($file_buffer, $encoding);
  957. fclose($fd);
  958. set_magic_quotes_runtime($magic_quotes);
  959. return $file_buffer;
  960. }
  961. /**
  962. * Encodes string to requested format. Returns an
  963. * empty string on failure.
  964. * @access private
  965. * @return string
  966. */
  967. function EncodeString ($str, $encoding = "base64") {
  968. $encoded = "";
  969. switch(strtolower($encoding)) {
  970. case "base64":
  971. // chunk_split is found in PHP >= 3.0.6
  972. $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  973. break;
  974. case "7bit":
  975. case "8bit":
  976. $encoded = $this->FixEOL($str);
  977. if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  978. $encoded .= $this->LE;
  979. break;
  980. case "binary":
  981. $encoded = $str;
  982. break;
  983. case "quoted-printable":
  984. $encoded = $this->EncodeQP($str);
  985. break;
  986. default:
  987. $this->SetError($this->Lang("encoding") . $encoding);
  988. break;
  989. }
  990. return $encoded;
  991. }
  992. /**
  993. * Encode a header string to best of Q, B, quoted or none.
  994. * @access private
  995. * @return string
  996. */
  997. function EncodeHeader ($str, $position = 'text') {
  998. $x = 0;
  999. switch (strtolower($position)) {
  1000. case 'phrase':
  1001. if (!preg_match('/[\200-\377]/', $str)) {
  1002. // Can't use addslashes as we don't know what value has magic_quotes_sybase.
  1003. $encoded = addcslashes($str, "\0..\37\177\\\"");
  1004. if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
  1005. return ($encoded);
  1006. else
  1007. return ("\"$encoded\"");
  1008. }
  1009. $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  1010. break;
  1011. case 'comment':
  1012. $x = preg_match_all('/[()"]/', $str, $matches);
  1013. // Fall-through
  1014. case 'text':
  1015. default:
  1016. $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  1017. break;
  1018. }
  1019. if ($x == 0)
  1020. return ($str);
  1021. $maxlen = 75 - 7 - strlen($this->CharSet);
  1022. // Try to select the encoding which should produce the shortest output
  1023. if (strlen($str)/3 < $x) {
  1024. $encoding = 'B';
  1025. $encoded = base64_encode($str);
  1026. $maxlen -= $maxlen % 4;
  1027. $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  1028. } else {
  1029. $encoding = 'Q';
  1030. $encoded = $this->EncodeQ($str, $position);
  1031. $encoded = $this->WrapText($encoded, $maxlen, true);
  1032. $encoded = str_replace("=".$this->LE, "\n", trim($encoded));
  1033. }
  1034. $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  1035. $encoded = trim(str_replace("\n", $this->LE, $encoded));
  1036. return $encoded;
  1037. }
  1038. /**
  1039. * Encode string to quoted-printable.
  1040. * @access private
  1041. * @return string
  1042. */
  1043. function EncodeQP ($str) {
  1044. $encoded = $this->FixEOL($str);
  1045. if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  1046. $encoded .= $this->LE;
  1047. // Replace every high ascii, control and = characters
  1048. $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
  1049. "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1050. // Replace every spaces and tabs when it's the last character on a line
  1051. $encoded = preg_replace("/([\011\040])".$this->LE."/e",
  1052. "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
  1053. // Maximum line length of 76 characters before CRLF (74 + space + '=')
  1054. $encoded = $this->WrapText($encoded, 74, true);
  1055. return $encoded;
  1056. }
  1057. /**
  1058. * Encode string to q encoding.
  1059. * @access private
  1060. * @return string
  1061. */
  1062. function EncodeQ ($str, $position = "text") {
  1063. // There should not be any EOL in the string
  1064. $encoded = preg_replace("[\r\n]", "", $str);
  1065. switch (strtolower($position)) {
  1066. case "phrase":
  1067. $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1068. break;
  1069. case "comment":
  1070. $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1071. case "text":
  1072. default:
  1073. // Replace every high ascii, control =, ? and _ characters
  1074. $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
  1075. "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1076. break;
  1077. }
  1078. // Replace every spaces to _ (more readable than =20)
  1079. $encoded = str_replace(" ", "_", $encoded);
  1080. return $encoded;
  1081. }
  1082. /**
  1083. * Adds a string or binary attachment (non-filesystem) to the list.
  1084. * This method can be used to attach ascii or binary data,
  1085. * such as a BLOB record from a database.
  1086. * @param string $string String attachment data.
  1087. * @param string $filename Name of the attachment.
  1088. * @param string $encoding File encoding (see $Encoding).
  1089. * @param string $type File extension (MIME) type.
  1090. * @return void
  1091. */
  1092. function AddStringAttachment($string, $filename, $encoding = "base64",
  1093. $type = "application/octet-stream") {
  1094. // Append to $attachment array
  1095. $cur = count($this->attachment);
  1096. $this->attachment[$cur][0] = $string;
  1097. $this->attachment[$cur][1] = $filename;
  1098. $this->attachment[$cur][2] = $filename;
  1099. $this->attachment[$cur][3] = $encoding;
  1100. $this->attachment[$cur][4] = $type;
  1101. $this->attachment[$cur][5] = true; // isString
  1102. $this->attachment[$cur][6] = "attachment";
  1103. $this->attachment[$cur][7] = 0;
  1104. }
  1105. /**
  1106. * Adds an embedded attachment. This can include images, sounds, and
  1107. * just about any other document. Make sure to set the $type to an
  1108. * image type. For JPEG images use "image/jpeg" and for GIF images
  1109. * use "image/gif".
  1110. * @param string $path Path to the attachment.
  1111. * @param string $cid Content ID of the attachment. Use this to identify
  1112. * the Id for accessing the image in an HTML form.
  1113. * @param string $name Overrides the attachment name.
  1114. * @param string $encoding File encoding (see $Encoding).
  1115. * @param string $type File extension (MIME) type.
  1116. * @return bool
  1117. */
  1118. function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64",
  1119. $type = "application/octet-stream") {
  1120. if(!@is_file($path))
  1121. {
  1122. $this->SetError($this->Lang("file_access") . $path);
  1123. return false;
  1124. }
  1125. $filename = basename($path);
  1126. if($name == "")
  1127. $name = $filename;
  1128. // Append to $attachment array
  1129. $cur = count($this->attachment);
  1130. $this->attachment[$cur][0] = $path;
  1131. $this->attachment[$cur][1] = $filename;
  1132. $this->attachment[$cur][2] = $name;
  1133. $this->attachment[$cur][3] = $encoding;
  1134. $this->attachment[$cur][4] = $type;
  1135. $this->attachment[$cur][5] = false; // isStringAttachment
  1136. $this->attachment[$cur][6] = "inline";
  1137. $this->attachment[$cur][7] = $cid;
  1138. return true;
  1139. }
  1140. /**
  1141. * Returns true if an inline attachment is present.
  1142. * @access private
  1143. * @return bool
  1144. */
  1145. function InlineImageExists() {
  1146. $result = false;
  1147. for($i = 0; $i < count($this->attachment); $i++)
  1148. {
  1149. if($this->attachment[$i][6] == "inline")
  1150. {
  1151. $result = true;
  1152. break;
  1153. }
  1154. }
  1155. return $result;
  1156. }
  1157. /////////////////////////////////////////////////
  1158. // MESSAGE RESET METHODS
  1159. /////////////////////////////////////////////////
  1160. /**
  1161. * Clears all recipients assigned in the TO array. Returns void.
  1162. * @return void
  1163. */
  1164. function ClearAddresses() {
  1165. $this->to = array();
  1166. }
  1167. /**
  1168. * Clears all recipients assigned in the CC array. Returns void.
  1169. * @return void
  1170. */
  1171. function ClearCCs() {
  1172. $this->cc = array();
  1173. }
  1174. /**
  1175. * Clears all recipients assigned in the BCC array. Returns void.
  1176. * @return void
  1177. */
  1178. function ClearBCCs() {
  1179. $this->bcc = array();
  1180. }
  1181. /**
  1182. * Clears all recipients assigned in the ReplyTo array. Returns void.
  1183. * @return void
  1184. */
  1185. function ClearReplyTos() {
  1186. $this->ReplyTo = array();
  1187. }
  1188. /**
  1189. * Clears all recipients assigned in the TO, CC and BCC
  1190. * array. Returns void.
  1191. * @return void
  1192. */
  1193. function ClearAllRecipients() {
  1194. $this->to = array();
  1195. $this->cc = array();
  1196. $this->bcc = array();
  1197. }
  1198. /**
  1199. * Clears all previously set filesystem, string, and binary
  1200. * attachments. Returns void.
  1201. * @return void
  1202. */
  1203. function ClearAttachments() {
  1204. $this->attachment = array();
  1205. }
  1206. /**
  1207. * Clears all custom headers. Returns void.
  1208. * @return void
  1209. */
  1210. function ClearCustomHeaders() {
  1211. $this->CustomHeader = array();
  1212. }
  1213. /////////////////////////////////////////////////
  1214. // MISCELLANEOUS METHODS
  1215. /////////////////////////////////////////////////
  1216. /**
  1217. * Adds the error message to the error container.
  1218. * Returns void.
  1219. * @access private
  1220. * @return void
  1221. */
  1222. function SetError($msg) {
  1223. $this->error_count++;
  1224. $this->ErrorInfo = $msg;
  1225. }
  1226. /**
  1227. * Returns the proper RFC 822 formatted date.
  1228. * @access private
  1229. * @return string
  1230. */
  1231. function RFCDate() {
  1232. $tz = date("Z");
  1233. $tzs = ($tz < 0) ? "-" : "+";
  1234. $tz = abs($tz);
  1235. $tz = ($tz/3600)*100 + ($tz%3600)/60;
  1236. $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
  1237. return $result;
  1238. }
  1239. /**
  1240. * Returns the appropriate server variable. Should work with both
  1241. * PHP 4.1.0+ as well as older versions. Returns an empty string
  1242. * if nothing is found.
  1243. * @access private
  1244. * @return mixed
  1245. */
  1246. function ServerVar($varName) {
  1247. global $HTTP_SERVER_VARS;
  1248. global $HTTP_ENV_VARS;
  1249. if(!isset($_SERVER))
  1250. {
  1251. $_SERVER = $HTTP_SERVER_VARS;
  1252. if(!isset($_SERVER["REMOTE_ADDR"]))
  1253. $_SERVER = $HTTP_ENV_VARS; // must be Apache
  1254. }
  1255. if(isset($_SERVER[$varName]))
  1256. return $_SERVER[$varName];
  1257. else
  1258. return "";
  1259. }
  1260. /**
  1261. * Returns the server hostname or 'localhost.localdomain' if unknown.
  1262. * @access private
  1263. * @return string
  1264. */
  1265. function ServerHostname() {
  1266. if ($this->Hostname != "")
  1267. $result = $this->Hostname;
  1268. elseif ($this->ServerVar('SERVER_NAME') != "")
  1269. $result = $this->ServerVar('SERVER_NAME');
  1270. else
  1271. $result = "localhost.localdomain";
  1272. return $result;
  1273. }
  1274. /**
  1275. * Returns a message in the appropriate language.
  1276. * @access private
  1277. * @return string
  1278. */
  1279. function Lang($key) {
  1280. if(count($this->language) < 1)
  1281. $this->SetLanguage("en"); // set the default language
  1282. if(isset($this->language[$key]))
  1283. return $this->language[$key];
  1284. else
  1285. return "Language string failed to load: " . $key;
  1286. }
  1287. /**
  1288. * Returns true if an error occurred.
  1289. * @return bool
  1290. */
  1291. function IsError() {
  1292. return ($this->error_count > 0);
  1293. }
  1294. /**
  1295. * Changes every end of line from CR or LF to CRLF.
  1296. * @access private
  1297. * @return string
  1298. */
  1299. function FixEOL($str) {
  1300. $str = str_replace("\r\n", "\n", $str);
  1301. $str = str_replace("\r", "\n", $str);
  1302. $str = str_replace("\n", $this->LE, $str);
  1303. return $str;
  1304. }
  1305. /**
  1306. * Adds a custom header.
  1307. * @return void
  1308. */
  1309. function AddCustomHeader($custom_header) {
  1310. $this->CustomHeader[] = explode(":", $custom_header, 2);
  1311. }
  1312. }
  1313. ?>