Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
610 florian 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.1 2005-11-24 16:15:46 florian Exp $
20
 
21
/**
22
 * internal PHP-mail() implementation of the PEAR Mail:: interface.
23
 * @package Mail
24
 * @version $Revision: 1.1 $
25
 */
26
class 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
        $this->sep = (strpos(PHP_OS, 'WIN') === false) ? "\n" : "\r\n";
58
    }
59
 
60
	/**
61
     * Implements Mail_mail::send() function using php's built-in mail()
62
     * command.
63
     *
64
     * @param mixed $recipients Either a comma-seperated list of recipients
65
     *              (RFC822 compliant), or an array of recipients,
66
     *              each RFC822 valid. This may contain recipients not
67
     *              specified in the headers, for Bcc:, resending
68
     *              messages, etc.
69
     *
70
     * @param array $headers The array of headers to send with the mail, in an
71
     *              associative array, where the array key is the
72
     *              header name (ie, 'Subject'), and the array value
73
     *              is the header value (ie, 'test'). The header
74
     *              produced from those values would be 'Subject:
75
     *              test'.
76
     *
77
     * @param string $body The full text of the message body, including any
78
     *               Mime parts, etc.
79
     *
80
     * @return mixed Returns true on success, or a PEAR_Error
81
     *               containing a descriptive error message on
82
     *               failure.
83
     *
84
     * @access public
85
     */
86
    function send($recipients, $headers, $body)
87
    {
88
        // If we're passed an array of recipients, implode it.
89
        if (is_array($recipients)) {
90
            $recipients = implode(', ', $recipients);
91
        }
92
 
93
        // Get the Subject out of the headers array so that we can
94
        // pass it as a seperate argument to mail().
95
        $subject = '';
96
        if (isset($headers['Subject'])) {
97
            $subject = $headers['Subject'];
98
            unset($headers['Subject']);
99
        }
100
 
101
        // Flatten the headers out.
102
        $headerElements = $this->prepareHeaders($headers);
103
        if (PEAR::isError($headerElements)) {
104
            return $headerElements;
105
        }
106
        list(, $text_headers) = $headerElements;
107
 
108
        /*
109
         * We only use mail()'s optional fifth parameter if the additional
110
         * parameters have been provided and we're not running in safe mode.
111
         */
112
        if (empty($this->_params) || ini_get('safe_mode')) {
113
            $result = mail($recipients, $subject, $body, $text_headers);
114
        } else {
115
            $result = mail($recipients, $subject, $body, $text_headers,
116
                           $this->_params);
117
        }
118
 
119
        /*
120
         * If the mail() function returned failure, we need to create a
121
         * PEAR_Error object and return it instead of the boolean result.
122
         */
123
        if ($result === false) {
124
            $result = PEAR::raiseError('mail() returned failure');
125
        }
126
 
127
        return $result;
128
    }
129
 
130
}