source: branches/comu-ver2/data/module/Mail/mail.php @ 16503

Revision 16503, 5.1 KB checked in by nanasess, 16 years ago (diff)

Pear::Mail のメールバックエンド(mail|sendmail|smtp) に対応

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to text/x-httpd-php
Line 
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$
20
21/**
22 * internal PHP-mail() implementation of the PEAR Mail:: interface.
23 * @package Mail
24 * @version $Revision$
25 */
26class Mail_mail extends Mail {
27
28    /**
29     * Any arguments to pass to the mail() function.
30     * @var string
31     */
32    var $_params = '';
33
34    /**
35     * Constructor.
36     *
37     * Instantiates a new Mail_mail:: object based on the parameters
38     * passed in.
39     *
40     * @param array $params Extra arguments for the mail() function.
41     */
42    function Mail_mail($params = null)
43    {
44        /* The other mail implementations accept parameters as arrays.
45         * In the interest of being consistent, explode an array into
46         * a string of parameter arguments. */
47        if (is_array($params)) {
48            $this->_params = join(' ', $params);
49        } else {
50            $this->_params = $params;
51        }
52
53        /* Because the mail() function may pass headers as command
54         * line arguments, we can't guarantee the use of the standard
55         * "\r\n" separator.  Instead, we use the system's native line
56         * separator. */
57        if (defined('PHP_EOL')) {
58            $this->sep = PHP_EOL;
59        } else {
60            $this->sep = (strpos(PHP_OS, 'WIN') === false) ? "\n" : "\r\n";
61        }
62    }
63
64    /**
65     * Implements Mail_mail::send() function using php's built-in mail()
66     * command.
67     *
68     * @param mixed $recipients Either a comma-seperated list of recipients
69     *              (RFC822 compliant), or an array of recipients,
70     *              each RFC822 valid. This may contain recipients not
71     *              specified in the headers, for Bcc:, resending
72     *              messages, etc.
73     *
74     * @param array $headers The array of headers to send with the mail, in an
75     *              associative array, where the array key is the
76     *              header name (ie, 'Subject'), and the array value
77     *              is the header value (ie, 'test'). The header
78     *              produced from those values would be 'Subject:
79     *              test'.
80     *
81     * @param string $body The full text of the message body, including any
82     *               Mime parts, etc.
83     *
84     * @return mixed Returns true on success, or a PEAR_Error
85     *               containing a descriptive error message on
86     *               failure.
87     *
88     * @access public
89     */
90    function send($recipients, $headers, $body)
91    {
92        $this->_sanitizeHeaders($headers);
93
94        // If we're passed an array of recipients, implode it.
95        if (is_array($recipients)) {
96            $recipients = implode(', ', $recipients);
97        }
98
99        // Get the Subject out of the headers array so that we can
100        // pass it as a seperate argument to mail().
101        $subject = '';
102        if (isset($headers['Subject'])) {
103            $subject = $headers['Subject'];
104            unset($headers['Subject']);
105        }
106
107        /*
108         * Also remove the To: header.  The mail() function will add its own
109         * To: header based on the contents of $recipients.
110         */
111        unset($headers['To']);
112
113        // Flatten the headers out.
114        $headerElements = $this->prepareHeaders($headers);
115        if (PEAR::isError($headerElements)) {
116            return $headerElements;
117        }
118        list(, $text_headers) = $headerElements;
119
120        /*
121         * We only use mail()'s optional fifth parameter if the additional
122         * parameters have been provided and we're not running in safe mode.
123         */
124        if (empty($this->_params) || ini_get('safe_mode')) {
125            $result = mail($recipients, $subject, $body, $text_headers);
126        } else {
127            $result = mail($recipients, $subject, $body, $text_headers,
128                           $this->_params);
129        }
130
131        /*
132         * If the mail() function returned failure, we need to create a
133         * PEAR_Error object and return it instead of the boolean result.
134         */
135        if ($result === false) {
136            $result = PEAR::raiseError('mail() returned failure');
137        }
138
139        return $result;
140    }
141
142}
Note: See TracBrowser for help on using the repository browser.