headers = [ 'X-Mailer' => MFAPPNAME.' Mailer', ]; $this->email_from = TT_OUTGOING_EMAIL; $this->from_name = TT_OUTGOING_EMAIL_NAME; } public function addAttachment($file = null, $content = null, $name = false, $c_type = "application/octet-stream", $disposition = "attachment", $encoding = "base64" , $charset = "utf-8") { $attachment = [ "file" => $file, "content" => $content, "name" => $name, "c_type" => $c_type, "disposition" => $disposition, "encoding" => $encoding, "charset" => $charset ]; $attachment["isfile"] = false; if($file) { $attachment['isfile'] = true; } $this->attachments[] = $attachment; } public function setHeader($name, $value) { $this->headers[$name] = $value; } public function setSubject($subject) { $this->subject = $subject; } public function setBody($body) { $this->body = $body; } public function setHtmlBody($html) { $this->html = $html; } public function setFrom($email, $name = false) { $this->email_from = $email; $this->from_name = $name; } public function setTo($email) { $this->email_to = $email; } public function send() { if(!$this->email_to) { return false; } if(!$this->body && !$this->html) { return false; } if(!is_array($this->headers) || !count($this->headers)) { return false; } if(!$this->subject) { return false; } if(!array_key_exists("Subject", $this->headers) || !$this->headers['Subject']) { $this->setHeader("Subject", $this->subject); } if((!array_key_exists("From", $this->headers) || !$this->headers['From']) && $this->from_name) { $this->headers['From'] = '"'.$this->from_name.'" <'.$this->email_from.'>'; } $log = mfLoghandler::singleton(); //var_dump($this);exit; $mimeparams['text_encoding']="8bit"; $mimeparams['text_charset']="utf-8"; $mimeparams['html_charset']="utf-8"; $mimeparams['head_charset']="utf-8"; $mime = new Mail_mime(); if($this->body) { $mime->setTXTBody($this->body); } if($this->html) { $mime->setHTMLBody($this->html); } //var_dump($this->attachments);exit; if(count($this->attachments)) { foreach($this->attachments as $att) { if($att['isfile']) { $mime->addAttachment($att["file"], $att["c_type"], $att["name"], true, $att['encoding'], $att['disposition'], $att['charset']); } else { $mime->addAttachment($att["content"], $att["c_type"], $att["name"], false, $att['encoding'], $att['disposition'], $att['charset']); } } } $body = $mime->get($mimeparams); $headers = $mime->headers($this->headers); //$log->debug(print_r($headers, true)); $mail =& Mail::factory('mail', ["-f ".$this->email_from]); /* * PHP 8's mail() function now outputs proper line endings in headers (CRLF instead of LF). * Mail_mail < 2.0 would detect a unix system and change the headers line ending to LF. * On Mail submission to Exim (via sendmail), mail() adds its own headers first with CRLF line ending, * making Exim treat every subsequent header's LF as an invalid line ending, adding a whitespace after the LF, * making all our custom headers into one long header. * * See: https://www.exim.org/exim-html-current/doc/html/spec_html/ch-message_processing.html#SECTlineendings * * So we force CRLF line endings for headers here. */ $mail->sep = "\r\n"; $mail->send($this->email_to, $headers, $body); } }