mail.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Chuck Hagenbuch <chuck@horde.org> |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: mail.php,v 1.5 2003/07/10 07:04:54 jon Exp $
  20. require_once 'Mail.php';
  21. /**
  22. * internal PHP-mail() implementation of the PEAR Mail:: interface.
  23. * @access public
  24. * @package Mail
  25. * @version $Revision: 1.5 $
  26. */
  27. class Mail_mail extends Mail
  28. {
  29. /**
  30. * Any arguments to pass to the mail() function.
  31. * @var string
  32. */
  33. var $_params = '';
  34. /**
  35. * Constructor.
  36. *
  37. * Instantiates a new Mail_mail:: object based on the parameters
  38. * passed in.
  39. *
  40. * @param string $params Extra arguments for the mail() function.
  41. *
  42. * @access public
  43. */
  44. function Mail_mail($params = '')
  45. {
  46. /*
  47. * The other mail implementations accept parameters as arrays. In the
  48. * interest of being consistent, explode an array into a string of
  49. * parameter arguments.
  50. */
  51. if (is_array($params)) {
  52. $this->_params = join(' ', $params);
  53. } else {
  54. $this->_params = $params;
  55. }
  56. /*
  57. * Because the mail() function may pass headers as command line
  58. * arguments, we can't guarantee the use of the standard "\r\n"
  59. * separator. Instead, we use the system's native line separator.
  60. */
  61. $this->sep = (strstr(PHP_OS, 'WIN')) ? "\r\n" : "\n";
  62. }
  63. /**
  64. * Implements Mail_mail::send() function using php's built-in mail()
  65. * command.
  66. *
  67. * @param mixed $recipients Either a comma-seperated list of recipients
  68. * (RFC822 compliant), or an array of recipients,
  69. * each RFC822 valid. This may contain recipients not
  70. * specified in the headers, for Bcc:, resending
  71. * messages, etc.
  72. *
  73. * @param array $headers The array of headers to send with the mail, in an
  74. * associative array, where the array key is the
  75. * header name (ie, 'Subject'), and the array value
  76. * is the header value (ie, 'test'). The header
  77. * produced from those values would be 'Subject:
  78. * test'.
  79. *
  80. * @param string $body The full text of the message body, including any
  81. * Mime parts, etc.
  82. *
  83. * @return mixed Returns true on success, or a PEAR_Error
  84. * containing a descriptive error message on
  85. * failure.
  86. * @access public
  87. */
  88. function send($recipients, $headers, $body)
  89. {
  90. // if we're passed an array of recipients, implode it.
  91. if (is_array($recipients)) {
  92. $recipients = implode(', ', $recipients);
  93. }
  94. // get the Subject out of the headers array so that we can
  95. // pass it as a seperate argument to mail().
  96. $subject = '';
  97. if (isset($headers['Subject'])) {
  98. $subject = $headers['Subject'];
  99. unset($headers['Subject']);
  100. }
  101. // flatten the headers out.
  102. list(,$text_headers) = Mail::prepareHeaders($headers);
  103. return mail($recipients, $subject, $body, $text_headers, $this->_params);
  104. }
  105. }