/** * Send the email. * @return boolean */ function send() { $recipients = $this->getRecipientString(); $from = $this->getFromString(); $subject = String::encode_mime_header($this->getSubject()); $body = $this->getBody(); // FIXME Some *nix mailers won't work with CRLFs if (Core::isWindows()) { // Convert LFs to CRLFs for Windows $body = String::regexp_replace("/([^\r]|^)\n/", "\$1\r\n", $body); } else { // Convert CRLFs to LFs for *nix $body = String::regexp_replace("/\r\n/", "\n", $body); } if ($this->getContentType() != null) { $this->addHeader('Content-Type', $this->getContentType()); } elseif ($this->hasAttachments()) { // Only add MIME headers if sending an attachment $mimeBoundary = '==boundary_' . md5(microtime()); /* Add MIME-Version and Content-Type as headers. */ $this->addHeader('MIME-Version', '1.0'); $this->addHeader('Content-Type', 'multipart/mixed; boundary="' . $mimeBoundary . '"'); } else { $this->addHeader('Content-Type', 'text/plain; charset="' . Config::getVar('i18n', 'client_charset') . '"'); } $this->addHeader('X-Mailer', 'Public Knowledge Project Suite v2'); $remoteAddr = Request::getRemoteAddr(); if ($remoteAddr != '') { $this->addHeader('X-Originating-IP', $remoteAddr); } $this->addHeader('Date', date('D, d M Y H:i:s O')); /* Add $from, $ccs, and $bccs as headers. */ if ($from != null) { $this->addHeader('From', $from); } $ccs = $this->getCcString(); if ($ccs != null) { $this->addHeader('Cc', $ccs); } $bccs = $this->getBccString(); if ($bccs != null) { $this->addHeader('Bcc', $bccs); } $headers = ''; foreach ($this->getHeaders() as $header) { if (!empty($headers)) { $headers .= MAIL_EOL; } $headers .= $header['name'] . ': ' . str_replace(array("\r", "\n"), '', $header['content']); } if ($this->hasAttachments()) { // Add the body $mailBody = 'This message is in MIME format and requires a MIME-capable mail client to view.' . MAIL_EOL . MAIL_EOL; $mailBody .= '--' . $mimeBoundary . MAIL_EOL; $mailBody .= sprintf('Content-Type: text/plain; charset=%s', Config::getVar('i18n', 'client_charset')) . MAIL_EOL . MAIL_EOL; $mailBody .= wordwrap($body, MAIL_WRAP, MAIL_EOL) . MAIL_EOL . MAIL_EOL; // Add the attachments $attachments = $this->getAttachments(); foreach ($attachments as $attachment) { $mailBody .= '--' . $mimeBoundary . MAIL_EOL; $mailBody .= 'Content-Type: ' . str_replace('"', '', $attachment['filename']) . '; name="' . $attachment['filename'] . '"' . MAIL_EOL; $mailBody .= 'Content-transfer-encoding: base64' . MAIL_EOL; $mailBody .= 'Content-disposition: ' . $attachment['disposition'] . MAIL_EOL . MAIL_EOL; $mailBody .= $attachment['content'] . MAIL_EOL . MAIL_EOL; } $mailBody .= '--' . $mimeBoundary . '--'; } else { // Just add the body $mailBody = wordwrap($body, MAIL_WRAP, MAIL_EOL); } if ($this->getEnvelopeSender() != null) { $additionalParameters = '-f ' . $this->getEnvelopeSender(); } else { $additionalParameters = null; } if (HookRegistry::call('Mail::send', array(&$this, &$recipients, &$subject, &$mailBody, &$headers, &$additionalParameters))) { return; } // Replace all the private parameters for this message. if (is_array($this->privateParams)) { foreach ($this->privateParams as $name => $value) { $mailBody = str_replace($name, $value, $mailBody); } } if (Config::getVar('email', 'smtp')) { $smtp =& Registry::get('smtpMailer', true, null); if ($smtp === null) { import('lib.pkp.classes.mail.SMTPMailer'); $smtp = new SMTPMailer(); } $sent = $smtp->mail($this, $recipients, $subject, $mailBody, $headers); } else { $sent = String::mail($recipients, $subject, $mailBody, $headers, $additionalParameters); } if (!$sent) { if (Config::getVar('debug', 'display_errors')) { if (Config::getVar('email', 'smtp')) { fatalError("There was an error sending this email. Please check your PHP error log for more information."); return false; } else { fatalError("There was an error sending this email. Please check your mail log (/var/log/maillog)."); return false; } } else { return false; } } else { return true; } }