Source for file mail-defs.php

Documentation is available at mail-defs.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: mail-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Various mail definitions. */
  24. /* */
  25. /* ******************************************************************** */
  26. /** @package email *//**
  27. * Limit to the number of e-mails to send in one sitting.
  28. * This is used in LIMIT statements to queries which return
  29. * individuals to be e-mailed with one thing or another..
  30. * NOTE: A value of 0 means "no limit".
  31. */
  32. define("EMAIL_BULK_LIMIT", 0);
  33.  
  34. // MIME Encodings
  35. /** 7-bit Encoding */
  36. ("ENC_BIT7", "7bit");
  37. /** Base-64 Encoding */
  38. ("ENC_BASE64", "base64");
  39. /** Quoted-Printable Encoding */
  40. ("ENC_QUOTP", "quoted-printable");
  41.  
  42. // MIME Message Content Types
  43. /** Mixture of content: text/html/etc. */
  44. ("MIXED", "multipart/mixed");
  45. /** Alternative formats of same content */
  46. ("ALTERNATIVE", "multipart/alternative");
  47. /** Parts intended to be viewed all at once */
  48. ("PARALLEL", "multipart/parallel");
  49. /** A digest of multiple attachments */
  50. ("DIGEST", "multipart/digest");
  51.  
  52. // Misc internal constants
  53. /** No email subject string
  54. * @access private */
  55. define('NOSUBJECT', "(No Subject)");
  56. /** MIME warning message
  57. * @access private */
  58. define('MIME_WARNING', "This is a multi-part message in MIME format.");
  59. /** The default character set
  60. * @access private */
  61. define("DEFAULT_CHARSET", "us-ascii");
  62. /** MIME content is in-line
  63. * @access private */
  64. define("INLINE", "inline");
  65. /** MIME content is an attachment
  66. * @access private */
  67. define("ATTACH", "attachment");
  68. /** Carriage-return Linefeed sequence
  69. * @access private */
  70. define('CRLF', "\r\n");
  71. /** The body of the e-mail
  72. * @access private */
  73. define("BODY", CRLF . "BODY" . CRLF);
  74.  
  75. // -------------------------------------------------------------------------
  76. /**
  77. * email class
  78. * A class which encapsulates all the functions required to compose
  79. * and send an e-mail message. Also caters for MIME attachments.
  80. * @package email
  81. */
  82. class email {
  83. // Public
  84. /** e-mail From address */
  85.  
  86. var $from = "";
  87. /** Address to send e-mail */
  88.  
  89. var $to = array();
  90. /** Cc: (copies to) header */
  91.  
  92. var $cc = array();
  93. /** Bcc: (blind copies to) header */
  94.  
  95. var $bcc = array();
  96. /** e-mail ReplyTo address */
  97.  
  98. var $replyto = "";
  99. /** Subject of the e-mail */
  100.  
  101. var $subject = "";
  102. /** e-mail body text */
  103.  
  104. var $body = "";
  105.  
  106. // Private
  107. /** Accumulated errors
  108. @access private */
  109. var $errors = array();
  110. /** Extra ad-hoc e-mail headers added from external
  111. calls. Use this if you need to add a header not
  112. covered by To(), From(), ReplyTo() etc. methods
  113. @access private */
  114. var $extra_headers = array();
  115. /** All e-mail headers end up here, apart from To: This
  116. array is a transient place to build all headers
  117. prior to sending the email
  118. @access private */
  119. var $email_headers = array();
  120. /** If !specified use PHP's base64
  121. @access private */
  122. var $base64_func = "";
  123. /** None at this time
  124. @access private */
  125. var $qp_func = "";
  126. /** E-mail body + headers minus From: and Subject:
  127. @access private */
  128. var $content = "";
  129. /** MIME content type for the e-mail
  130. @access private */
  131. var $mimecontenttype = CONTENT_TEXT;
  132. /** MIME boundary marker to use
  133. @access private */
  134. var $mimeboundary = "";
  135. /** character set to use for the e-mail
  136. @access private */
  137. var $charset = DEFAULT_CHARSET;
  138. /** Assembled mime attachments
  139. @access private */
  140. var $mimeparts = array();
  141. //.....................................................................
  142. /**
  143. * Constructor
  144. * Creates the basic email object.
  145. * @param string $from From: email address
  146. * @param string $to To: email address
  147. * @param string $subject Subject line of the e-mail
  148. * @param string $body Body text of the e-mail
  149. * @param string $headers Extra headers to include for this e-mail
  150. * @param string $mimecontenttype Mime content type
  151. * @param string $mimeboundary Pattern designating mime boundary
  152. */
  153. function email(
  154. $from="",
  155. $to="",
  156. $subject="",
  157. $body="",
  158. $headers="",
  159. $mimecontenttype=CONTENT_TEXT,
  160. $mimeboundary=""
  161. ) {
  162. debug_trace($this);
  163. $this->From($from);
  164. $this->To($to);
  165. $this->Subject($subject);
  166. $this->Body($body);
  167.  
  168. // The headers can be passed as an array, or as a
  169. // string of comma-delimited headers..
  170. if (is_array($headers)) {
  171. $this->extra_headers = $headers;
  172. }
  173. elseif ($headers != "") {
  174. $this->extra_headers = explode(",", $headers);
  175. }
  176.  
  177. // MIME settings..
  178. $this->mimeparts[] = "";
  179. $this->mimecontenttype = $mimecontenttype;
  180. if (empty($mimeboundary)) {
  181. $this->mimeboundary = "catit_" . chr(rand(65, 91)) . '------' . md5(uniqid(rand()));
  182. }
  183. else {
  184. $this->mimeboundary = $mimeboundary;
  185. }
  186. debug_trace();
  187. return;
  188. } // email
  189. // .........................................................................
  190. /** Set subject
  191. * Set the e-mail Subject: header
  192. * @param string $subject Subject for this email
  193. */
  194. function Subject($subject) {
  195. $this->subject = $subject;
  196. } // Subject
  197. // .........................................................................
  198. /** Set body
  199. * Set the e-mail body content
  200. * @param string $body Body content for this email
  201. */
  202. function Body($body) {
  203. $this->body = $body;
  204. } // Body
  205. // .........................................................................
  206. /** Set from
  207. * Set the e-mail From: e-mail addresses.
  208. * @param string $from e-mail address e-mail comes from
  209. */
  210. function From($from) {
  211. $this->from = $from;
  212. } // From
  213. // .........................................................................
  214. /** Set replyto
  215. * Set the e-mail ReplyTo: e-mail address.
  216. * @param string $replyto e-mail address recipient replies to
  217. */
  218. function ReplyTo($replyto) {
  219. $this->replyto = $replyto;
  220. } // ReplyTo
  221. // .........................................................................
  222. /** Set to
  223. * Set the e-mail To: e-mail addresses.
  224. * The supplied e-mail addresses can be a comma-delimited list.
  225. * NB: Every time this method is called, addresses are appended.
  226. * @param string $to List of e-mail addresses to send e-mail to
  227. */
  228. function To($to) {
  229. $this->add_array_or_list($to, $this->to);
  230. } // To
  231. // .........................................................................
  232. /** Set copies-to
  233. * Set the e-mail Cc: e-mail addresses for copies to.
  234. * The supplied e-mail addresses can be a comma-delimited list.
  235. * NB: Every time this method is called, addresses are appended.
  236. * @param string $cc List of e-mail addresses to copy e-mail to
  237. */
  238. function Cc($cc) {
  239. $this->add_array_or_list($cc, $this->cc);
  240. } // Cc
  241. // .........................................................................
  242. /** Set blind copies-to
  243. * Set the e-mail Bcc: e-mail addresses for blind copies to.
  244. * The supplied e-mail addresses can be a comma-delimited list.
  245. * NB: Every time this method is called, addresses are appended.
  246. * @param string $bcc List of e-mail addresses to blind copy e-mail to
  247. */
  248. function Bcc($bcc) {
  249. $this->add_array_or_list($bcc, $this->bcc);
  250. } // Bcc
  251. // .........................................................................
  252. /** Add an array or list of email addresses to the given variable
  253. * passed in by reference.
  254. * @param mixed $addrs Array or comma-delimited list of addresses to add
  255. * @param mixed $addrvar Reference to address var to assign addresses
  256. * @access private
  257. */
  258. function add_array_or_list($addrs, &$addrvar) {
  259. if (is_array($addrs)) {
  260. $newads = $addrs;
  261. }
  262. else {
  263. $newads = explode(",", $addrs);
  264. }
  265. if (is_array($newads)) {
  266. foreach ($newads as $newad) {
  267. if ($newad != "") {
  268. $addrvar[] = $newad;
  269. }
  270. }
  271. }
  272. } // add_array_or_list
  273. // .........................................................................
  274. /**
  275. * Append new content to the body of the email.
  276. * @param string $content New content to add to the existing email body.
  277. */
  278. function add_content($content) {
  279. $this->body .= $content;
  280. } // add_content
  281. // .........................................................................
  282. /** Set the character set encoding for the email.
  283. * @param string $charset_code Code of the characterset to use for the email
  284. */
  285. function charset($charset_code) {
  286. debug_trace($this);
  287. $this->charset = $charset_code;
  288. debug_trace();
  289. } // charset
  290. // .........................................................................
  291. /**
  292. * Generic function to add a header. We store our headers in an associative
  293. * array, keyed on the proper-cased header name, so we avoid duplicates.
  294. * @param string $header Header to add to e-mail in 'Headername: value' format
  295. * @deprecated the new function extra_header() is now preferred
  296. */
  297. function add_header($header) {
  298. debug_trace($this);
  299. $bits = explode(":", $header);
  300. $header_name = ucfirst(strtolower(trim($bits[0])));
  301. $header_value = trim(trim($bits[1]));
  302. $this->extra_headers[$header_name] = $header_value;
  303. debug_trace();
  304. } // add_header
  305. // .........................................................................
  306. /**
  307. * Generic method to add an extra header. This method is now preferred over
  308. * the depreceted 'add_header()' method above. We store our headers in an
  309. * associative array, keyed on the proper-cased header name.
  310. * @param string $headername Name of the Header to add in this build
  311. * @param string $headervalue Value of the Header to add in this build
  312. */
  313. function extra_header($headername, $headervalue) {
  314. debug_trace($this);
  315. if (trim($headervalue) != "") {
  316. $headername = ucfirst(strtolower($headername));
  317. $this->extra_headers[$headername] = $headervalue;
  318. }
  319. debug_trace();
  320. } // extra_header
  321. // .........................................................................
  322. /**
  323. * Method to build the header array when building the e-mail to send it. We
  324. * store our headers in an associative array, keyed on the header name.
  325. * This method is generally for internal use, and is called every time
  326. * the email is built for sending.
  327. * @param string $headername Name of the Header to add in this build
  328. * @param string $headervalue Value of the Header to add in this build
  329. * @access private
  330. */
  331. function build_header($headername, $headervalue) {
  332. debug_trace($this);
  333. if (trim($headervalue) != "") {
  334. $headername = ucfirst(strtolower($headername));
  335. $this->email_headers[$headername] = $headervalue;
  336. }
  337. debug_trace();
  338. } // build_header
  339. // .........................................................................
  340. /**
  341. * Attaches a 'file' to the e-mail message. Pass a file pathname to attach.
  342. * This function returns a success/failure code/key of current
  343. * attachment in array (+1). @see attach()
  344. * @param string $path Path to the file to attach
  345. * @param string $contenttype Mime content type of this attachment
  346. * @param string $encoding Encoding type for this attachment
  347. * @param string $disp Content disposition
  348. */
  349. function attach_file($path, $description="", $contenttype=CONTENT_OCTET, $encoding=ENC_BASE64, $disp="") {
  350. debug_trace($this);
  351. $this->mimecontenttype = MIXED;
  352. if (!file_exists($path)) {
  353. $this->errors[] = "attach_file: file '$path' does not exist";
  354. return false;
  355. }
  356. // Read in file
  357. $fp = fopen($path, "rb"); # (b)inary for Win compatability
  358. if (!$fp) {
  359. $this->errors[] = "attach_file: could not open '$path' for reading";
  360. return false;
  361. }
  362. $contenttype .= ";\r\n\tname=" . basename($path);
  363. $data = fread($fp, filesize($path));
  364. debug_trace();
  365. return $this->attach($data,
  366. $description,
  367. $contenttype,
  368. $encoding,
  369. $disp
  370. );
  371. } // attach_file
  372. // .........................................................................
  373. /**
  374. * Just a convenient wrapper for adding HTML attachments. Note that with
  375. * this call we are assuming that we are going to be sending an e-mail
  376. * with a plain text and an HTML equivalent. This is why we set the
  377. * MIME content type to "multipart/alternative" here. This can be
  378. * over-ridden using the parameter in the send(0 function.
  379. * @param string $data The HTML data to attach
  380. * @param string $encoding Encoding type for this attachment
  381. */
  382. function attach_html($data, $encoding=ENC_BASE64) {
  383. $this->mimecontenttype = ALTERNATIVE;
  384. return $this->attach_raw(
  385. $data,
  386. "",
  387. CONTENT_HTML,
  388. $encoding
  389. );
  390. } // attach_html
  391. // .........................................................................
  392. /**
  393. * Wrapper for general binary attachments. We assume a MIME content
  394. * type of multipart/mixed for these..
  395. * @param string $data The binary data to attach
  396. * @param string $contenttype Mime content type of this attachment
  397. * @param string $encoding Encoding type for this attachment
  398. * @param string $disp Content disposition
  399. */
  400. function attach($data, $description="", $contenttype=CONTENT_OCTET, $encoding=ENC_BASE64, $disp="") {
  401. $this->mimecontenttype = MIXED;
  402. return $this->attach_raw(
  403. $data,
  404. $description,
  405. $contenttype,
  406. $encoding,
  407. $disp
  408. );
  409. } // attach
  410. // .........................................................................
  411. /** Attach raw
  412. * The raw routine for attaching content to the e-mail. This method is
  413. * used by the other 'friendlier' attachment methods.
  414. * @param string $data The binary data to attach
  415. * @param string $description Forms the content-description header
  416. * @param string $contenttype Mime content type of this attachment
  417. * @param string $encoding Encoding type for this attachment
  418. * @param string $disp Content disposition
  419. * @access private
  420. */
  421. function attach_raw($data, $description="", $contenttype=CONTENT_OCTET, $encoding=ENC_BASE64, $disp="") {
  422. if (empty($data)) {
  423. $this->errors[] = "attach_raw: no data to be attached";
  424. return false;
  425. }
  426. // Handle default encodings..
  427. if (trim($contenttype) == "") $contenttype = OCTET;
  428. if (trim($encoding) == "") $encoding = ENC_BASE64;
  429.  
  430. // Ascii text 7-Bit standard..
  431. if ($encoding == ENC_BIT7) {
  432. $emsg = $data;
  433. }
  434. // User-defined function..
  435. elseif ($encoding == ENC_QUOTP) {
  436. $emsg = $$this->qp_func($data);
  437. }
  438. // Good ol' Base-64..
  439. elseif ($encoding == ENC_BASE64) {
  440. // Check if there is user-defined function..
  441. if (!$this->base64_func) {
  442. $emsg = base64_encode($data);
  443. }
  444. else {
  445. $emsg = $$this->base64_func($data);
  446. }
  447. // Splits data stream into 76 char lines
  448. // to fit RFC2045 semantics..
  449. $emsg = chunk_split($emsg);
  450. }
  451.  
  452. //Check if content-type is text/plain and if charset is not specified append default CHARSET
  453. if (strstr($contenttype, CONTENT_TEXT) && !strstr(contenttype, "/;charset=/i")) {
  454. $contenttype .= ";\r\n\tcharset=" . $this->charset;
  455. }
  456. $msg = "";
  457. $msg .= "Content-Type: $contenttype" . CRLF;
  458. $msg .= "Content-Transfer-Encoding: $encoding" . CRLF;
  459. if ($disp != "") {
  460. $msg .= "Content-Disposition: $disp";
  461. if ($description != "") {
  462. $msg .= "; filename=\"$description\"";
  463. }
  464. $msg .= CRLF;
  465. }
  466. elseif ($description != "" && BODY != $description) {
  467. $msg .= "Content-Description: $description" . CRLF;
  468. }
  469. $msg .= CRLF . $emsg . CRLF;
  470. BODY == $description ? $this->mimeparts[0] = $msg : $this->mimeparts[] = $msg;
  471.  
  472. return count($this->mimeparts);
  473. } // attach_raw
  474. // .........................................................................
  475. /**
  476. * Build the message body.
  477. * Construct mail message body and any MIME attachments. This also includes
  478. * assignment of the relevant headers, depending on the attachments which
  479. * have been defined (or not).
  480. * @access private
  481. */
  482. function build_body() {
  483. debug_trace($this);
  484. $msg = "";
  485. $nparts = count($this->mimeparts);
  486.  
  487. // Case 1: Attachment list is there. Therefore MIME Message header must have multipart/mixed
  488. if (is_array($this->mimeparts) && ($nparts > 1)) {
  489. $this->build_header("MIME-Version", "1.0");
  490. $this->build_header("Content-Type", "$this->mimecontenttype;" . CRLF . "\tboundary=\"$this->mimeboundary\"");
  491. $this->build_header("Content-Transfer-Encoding", ENC_BIT7);
  492. $msg .= CRLF . MIME_WARNING . CRLF . CRLF ;
  493.  
  494. // Since we are here, it means we do have attachments and
  495. // the body must become an attachment too..
  496. if (!empty($this->body)) {
  497. $this->attach($this->body, BODY, CONTENT_TEXT, ENC_BIT7);
  498. }
  499. // Now create the MIME parts of the email
  500. foreach ($this->mimeparts as $mimepart) {
  501. if (!empty($mimepart)) {
  502. $msg .= CRLF . '--' . $this->mimeboundary . CRLF . $mimepart . CRLF;
  503. }
  504. }
  505. $msg .= "--" . $this->mimeboundary . "--" . CRLF;
  506. }
  507. else {
  508. $this->build_header("Content-Type", "$this->mimecontenttype;" . CRLF . "\tcharset=" . $this->charset);
  509. if (!empty($this->body)) {
  510. $msg .= CRLF . $this->body . CRLF . CRLF;
  511. }
  512. }
  513. debug_trace();
  514. return $msg;
  515. } // build_body
  516. // .........................................................................
  517. /**
  518. * Generate message content
  519. * Now Generate the entire Mail Message, header and body et al.
  520. * Note that this leaves out the To: and Subject: which are passed
  521. * as separate parameters when mailing the e-mail with 'mail()'.
  522. * @return string The full email content including headers and body
  523. * @access private
  524. */
  525. function generate_content() {
  526. $this->email_headers = $this->extra_headers;
  527. if (empty($this->subject)) {
  528. $this->subject = NOSUBJECT;
  529. }
  530. if (!empty($this->from)) {
  531. $this->build_header("From", $this->from);
  532. }
  533. if (!empty($this->replyto)) {
  534. $this->build_header("ReplyTo", $this->replyto);
  535. }
  536. if (is_array($this->cc) && count($this->cc) > 0) {
  537. $this->build_header("Cc", implode(",", $this->cc));
  538. }
  539. if (is_array($this->bcc) && count($this->bcc) > 0) {
  540. $this->build_header("Bcc", implode(",", $this->bcc));
  541. }
  542. $this->build_header("X-Mailer", "Catalyst-IT/AXYL");
  543. $this->content = $this->build_body();
  544. return $this->content;
  545. } // generate_content
  546. // .........................................................................
  547. /**
  548. * Return Printable Content
  549. * Returns a printable version of the e-mail. Just returns the content
  550. * as well as all the headers, and if for HTML, then it wraps it all in
  551. * some (pre) tags. Useful for debugging.
  552. * @param string $format Format of output, either 'text' (default) or 'html'
  553. */
  554. function printable($format="text") {
  555. $email = $this->generate_content();
  556. $eol = "\n";
  557. $email = "";
  558. $email .= "Subject: $this->subject" . $eol;
  559. $email .= "To: " . implode(",", $this->to) . $eol;
  560. $headers = array();
  561. foreach ($this->email_headers as $headername => $headervalue) {
  562. $headers[] = "$headername: $headervalue";
  563. }
  564. $email .= implode($eol, $headers);
  565. $email .= $this->content;
  566. if ($format == "html") {
  567. $email = "<pre>$email</pre>";
  568. }
  569. return $email;
  570. } // printable
  571. // .........................................................................
  572. /**
  573. * Return error messages. These may have accumulated during the email
  574. * assembly or during the send process.
  575. * @return string Error message(s) which have accumulated.
  576. */
  577. function error_message() {
  578. $errmsg = "";
  579. if (count($this->errors) > 0) {
  580. foreach ($this->errors as $err) {
  581. $errmsg .= "$err\n";
  582. }
  583. }
  584. return $errmsg;
  585. } // error_message
  586. // .........................................................................
  587. /**
  588. * Send the email
  589. * Send mail via local mailer. This is usually the end-result of
  590. * an e-mail sequence and results in the e-mail being sent.
  591. * @param string $mimecontenttype Override for the email MIME content type
  592. * @param string $charset Override for the email character set
  593. * @return boolean True if email was sent successfully
  594. */
  595. function send($mimecontenttype="", $charset="") {
  596. debug_trace($this);
  597. $sentok = false;
  598.  
  599. // Allow them to set MIME content type late..
  600. if ($mimecontenttype != "") {
  601. $this->mimecontenttype = $mimecontenttype;
  602. }
  603. $this->generate_content();
  604. // Must have a To address..
  605. if (count($this->to) == 0) {
  606. $this->errors[] = "send: To: header was not specified";
  607. return false;
  608. }
  609. // Unfurl all the headers..
  610. $headers = array();
  611. foreach ($this->email_headers as $headername => $headervalue) {
  612. $headers[] = "$headername: $headervalue";
  613. }
  614.  
  615. // Send the e-mail on its way..
  616. if (!empty($this->from)) {
  617. // The -f parameter sets who the mail is from, by setting the email
  618. // address on the 'envelope' of the mail. This can only be done by a
  619. // user 'trusted' by sendmail, so make sure the user the webserver
  620. // runs as (eg. www-data) is marked as trusted in this way.
  621. $sentok = mail(
  622. implode(",", $this->to),
  623. $this->subject,
  624. $this->content,
  625. implode(CRLF, $headers),
  626. "-f$this->from"
  627. );
  628. }
  629. else {
  630. $sentok = mail(
  631. implode(",", $this->to),
  632. $this->subject,
  633. $this->content,
  634. implode(CRLF, $headers)
  635. );
  636. }
  637. // Debug output..
  638. if (debugging()) {
  639. debugbr( $this->printable("html"), DBG_DUMP );
  640. }
  641. debug_trace();
  642. if (!$sentok) {
  643. $this->errors[] = "send: mail() function returned fail status";
  644. }
  645. return $sentok;
  646. } // send
  647.  
  648. } // Class email
  649. // -------------------------------------------------------------------------
  650.  
  651. /**
  652. * Function to send an email using the simple Php mail() call. This is a
  653. * very simplistic wrapper which is kept for its cuteness, but for no
  654. * other reason than that.
  655. * @param string $eto The To: email address
  656. * @param string $efrom The From: email address
  657. * @param string $esubject The Subject: line
  658. * @param string $ebody The email body content
  659. * @param string $emailformat Format of e-mail 'plain', 'html' or 'mixed'
  660. * @param string $mime_boundary The mime boundary pattern
  661. */
  662. function emailthem($eto, $eCc, $efrom, $esubject, $ebody, $emailformat="plain", $mime_boundary="") {
  663. $headers = "From: $efrom\n";
  664. if ($eCc != "") $headers .= "Cc: $eCc\n";
  665. $headers .= "Reply-To: $efrom\n";
  666. $headers .= "Errors-To: $efrom\n";
  667. $headers .= "Return-Path: $efrom\n";
  668.  
  669. switch ($emailformat) {
  670. case "html":
  671. $headers .= "Content-Type: text/html\n";
  672. break;
  673. case "plain":
  674. $headers .= "Content-Type: text/plain\n";
  675. break;
  676. case "mixed":
  677. $headers .= "MIME-Version: 1.0\n";
  678. $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
  679. break;
  680. default:
  681. $headers .= "Content-Type: text/plain\n";
  682. } // switch
  683.  
  684. $headers .= "X-Mailer: PHP/" . phpversion();
  685. mail($eto, $esubject, $ebody, $headers);
  686. } // emailthem
  687. // -------------------------------------------------------------------------
  688.  
  689. /**
  690. * Make a 'friendly' name from a full one. Good for "Dear... ,"
  691. * @param string $fullname The full name to make a friendly version of
  692. * @return string The friendly name
  693. */
  694. function friendlyName($fullname) {
  695. $splitname = explode(" ", $fullname);
  696. $mate = trim($splitname[0]);
  697. if ($mate == "") $mate = $fullname;
  698. return $mate;
  699. } // friendlyName
  700. // -------------------------------------------------------------------------
  701.  
  702. ?>

Documentation generated by phpDocumentor 1.3.0RC3