ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
mail.php
Go to the documentation of this file.
1<?php
51class Mail_mail extends Mail {
52
57 var $_params = '';
58
67 function Mail_mail($params = null)
68 {
69 // The other mail implementations accept parameters as arrays.
70 // In the interest of being consistent, explode an array into
71 // a string of parameter arguments.
72 if (is_array($params)) {
73 $this->_params = join(' ', $params);
74 } else {
75 $this->_params = $params;
76 }
77
78 /* Because the mail() function may pass headers as command
79 * line arguments, we can't guarantee the use of the standard
80 * "\r\n" separator. Instead, we use the system's native line
81 * separator. */
82 if (defined('PHP_EOL')) {
83 $this->sep = PHP_EOL;
84 } else {
85 $this->sep = (strpos(PHP_OS, 'WIN') === false) ? "\n" : "\r\n";
86 }
87 }
88
115 function send($recipients, $headers, $body)
116 {
117 if (!is_array($headers)) {
118 return PEAR::raiseError('$headers must be an array');
119 }
120
121 $result = $this->_sanitizeHeaders($headers);
122 if (is_a($result, 'PEAR_Error')) {
123 return $result;
124 }
125
126 // If we're passed an array of recipients, implode it.
127 if (is_array($recipients)) {
128 $recipients = implode(', ', $recipients);
129 }
130
131 // Get the Subject out of the headers array so that we can
132 // pass it as a seperate argument to mail().
133 $subject = '';
134 if (isset($headers['Subject'])) {
135 $subject = $headers['Subject'];
136 unset($headers['Subject']);
137 }
138
139 // Also remove the To: header. The mail() function will add its own
140 // To: header based on the contents of $recipients.
141 unset($headers['To']);
142
143 // Flatten the headers out.
144 $headerElements = $this->prepareHeaders($headers);
145 if (is_a($headerElements, 'PEAR_Error')) {
146 return $headerElements;
147 }
148 list(, $text_headers) = $headerElements;
149
150 // We only use mail()'s optional fifth parameter if the additional
151 // parameters have been provided and we're not running in safe mode.
152 if (empty($this->_params) || ini_get('safe_mode')) {
153 $result = mail($recipients, $subject, $body, $text_headers);
154 } else {
155 $result = mail($recipients, $subject, $body, $text_headers,
156 $this->_params);
157 }
158
159 // If the mail() function returned failure, we need to create a
160 // PEAR_Error object and return it instead of the boolean result.
161 if ($result === false) {
162 $result = PEAR::raiseError('mail() returned failure');
163 }
164
165 return $result;
166 }
167
168}
$result
send($recipients, $headers, $body)
Implements Mail_mail::send() function using php's built-in mail() command.
Definition: mail.php:115
$_params
Definition: mail.php:57
Mail_mail($params=null)
Constructor.
Definition: mail.php:67
_sanitizeHeaders(&$headers)
Sanitize an array of mail headers by removing any additional header strings present in a legitimate h...
Definition: Mail.php:153
prepareHeaders($headers)
Take an array of mail headers and return a string containing text usable in sending a message.
Definition: Mail.php:178
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object's de...
Definition: PEAR.php:524
$params
Definition: example_049.php:96
PEAR's Mail:: interface.