/** * Send an email message. * * @access public * @param string $to Recipient email address * @param string $from Sender email address * @param string $subject Subject line for message * @param string $body Message body * @param string $replyTo Someone to reply to * * @return mixed PEAR error on error, boolean true otherwise */ public function send($to, $from, $subject, $body, $replyTo = null) { global $logger; // Validate sender and recipient $validator = new Mail_RFC822(); //Allow the to address to be split $validator->_splitAddresses($to); foreach ($validator->addresses as $tmpAddress) { if (!$validator->isValidInetAddress($tmpAddress['address'])) { return new PEAR_Error('Invalid Recipient Email Address ' . $tmpAddress); } } if (!$validator->isValidInetAddress($from)) { return new PEAR_Error('Invalid Sender Email Address'); } $headers = array('To' => $to, 'Subject' => $subject, 'Date' => date('D, d M Y H:i:s O'), 'Content-Type' => 'text/plain; charset="UTF-8"'); if (isset($this->settings['fromAddress'])) { $logger->log("Overriding From address, using " . $this->settings['fromAddress'], PEAR_LOG_INFO); $headers['From'] = $this->settings['fromAddress']; $headers['Reply-To'] = $from; } else { $headers['From'] = $from; } if ($replyTo != null) { $headers['Reply-To'] = $replyTo; } // Get mail object if ($this->settings['host'] != false) { $mailFactory = new Mail(); $mail =& $mailFactory->factory('smtp', $this->settings); if (PEAR_Singleton::isError($mail)) { return $mail; } // Send message return $mail->send($to, $headers, $body); } else { //Mail to false just emits the information to screen $formattedMail = ''; foreach ($headers as $key => $header) { $formattedMail .= $key . ': ' . $header . '<br />'; } $formattedMail .= $body; $logger->log("Sending e-mail", PEAR_LOG_INFO); $logger->log("From = {$from}", PEAR_LOG_INFO); $logger->log("To = {$to}", PEAR_LOG_INFO); $logger->log($subject, PEAR_LOG_INFO); $logger->log($formattedMail, PEAR_LOG_INFO); return true; } }