/** * Build a nice email from the submitted data and send it */ function run($fields, $thanks, $argv) { global $ID; $this->prepareLanguagePlaceholder(); // get recipient address(es) $to = join(',', $argv); $replyto = array(); $headers = null; $subject = sprintf($this->getLang('mailsubject'), $ID); $txt = sprintf($this->getLang('mailintro') . "\n\n\n", dformat()); foreach ($fields as $opt) { /** @var syntax_plugin_bureaucracy_field $opt */ $value = $opt->getParam('value'); $label = $opt->getParam('label'); switch ($opt->getFieldType()) { case 'fieldset': $txt .= "\n====== " . hsc($label) . " ======\n\n"; break; case 'subject': $subject = $label; break; case 'email': if (!is_null($opt->getParam('replyto'))) { $replyto[] = $value; } /** fall through */ /** fall through */ default: if ($value === null || $label === null) { break; } $txt .= $label . "\n"; $txt .= "\t\t{$value}\n"; } $this->prepareFieldReplacements($label, $value); } $subject = $this->replaceDefault($subject); if (!empty($replyto)) { $headers = mail_encode_address(join(',', $replyto), 'Reply-To'); } global $conf; if (!mail_send($to, $subject, $txt, $conf['mailfrom'], '', '', $headers)) { throw new Exception($this->getLang('e_mail')); } return $thanks; }
function _mail_send_action($data) { // retrieve parameters from event data, $to, $subject, $body, $from, $cc, $bcc, $headers, $params $to = $data['to']; $subject = $data['subject']; $body = $data['body']; // add robustness in case plugin removes any of these optional values $from = isset($data['from']) ? $data['from'] : ''; $cc = isset($data['cc']) ? $data['cc'] : ''; $bcc = isset($data['bcc']) ? $data['bcc'] : ''; $headers = isset($data['headers']) ? $data['headers'] : null; $params = isset($data['params']) ? $data['params'] : null; // end additional code to support event ... original mail_send() code from here if (defined('MAILHEADER_ASCIIONLY')) { $subject = utf8_deaccent($subject); $subject = utf8_strip($subject); } if (!utf8_isASCII($subject)) { $subject = '=?UTF-8?Q?' . mail_quotedprintable_encode($subject, 0) . '?='; // Spaces must be encoded according to rfc2047. Use the "_" shorthand $subject = preg_replace('/ /', '_', $subject); } $header = ''; // No named recipients for To: in Windows (see FS#652) $usenames = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? false : true; $to = mail_encode_address($to, '', $usenames); $header .= mail_encode_address($from, 'From'); $header .= mail_encode_address($cc, 'Cc'); $header .= mail_encode_address($bcc, 'Bcc'); $header .= 'MIME-Version: 1.0' . MAILHEADER_EOL; $header .= 'Content-Type: text/plain; charset=UTF-8' . MAILHEADER_EOL; $header .= 'Content-Transfer-Encoding: quoted-printable' . MAILHEADER_EOL; $header .= $headers; $header = trim($header); $body = mail_quotedprintable_encode($body); if ($params == null) { return @mail($to, $subject, $body, $header); } else { return @mail($to, $subject, $body, $header, $params); } }