ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
mail.php
Go to the documentation of this file.
1 <?php
51 class 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 }