From 8454b9d281decfced62754a88f9fd708acfa0231 Mon Sep 17 00:00:00 2001 From: Pavel Belyaev Date: Wed, 25 Aug 2021 00:05:48 +0500 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D0=BA=D0=B0?= =?UTF-8?q?=D0=BA,=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B9=20=D0=BC?= =?UTF-8?q?=D0=B5=D0=B9=D0=BB=D0=B5=D1=80=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D0=B8=D0=BB=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLASSES/core/LE_MAIL.php | 85 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 CLASSES/core/LE_MAIL.php diff --git a/CLASSES/core/LE_MAIL.php b/CLASSES/core/LE_MAIL.php new file mode 100644 index 0000000..e8d3d84 --- /dev/null +++ b/CLASSES/core/LE_MAIL.php @@ -0,0 +1,85 @@ +charset.'//TRANSLIT', $body); + } + + protected function base_encode($text) + { + $subject = base64_encode($this->encode($text)); + return '=?'.$this->charset.'?B?'.$text.'?='; + } + + protected function headers($from,$type) + { + $eol = $this->eol; + $sep = $this->separator; + $headers ="MIME-Version: 1.0".$eol; + $headers .='Content-Type: multipart/mixed; boundary="'.$sep.'"'.$eol; + $headers .="From: ".$from.$eol; + return $headers; + } + + protected function attach_info($path) + { + $file = pathinfo($path)['basename']; + $mime = mime_content_type($path); + if ($mime===false) $mime="application/octet-stream"; + return [$file,$mime]; + } + + protected function attachment($path=null) + { + if ($path===null || $path===false || !is_file($path)) return false; + $eol = $this->eol; + list ($filename,$mime) = $this->attach_info($path); + $content = file_get_contents($path); + $body = $this->sep.'Content-Type: '.$mime.'; name="'.$filename.'"'.$eol; + $body .= "Content-Transfer-Encoding: base64" . $eol; + $body .= "Content-Disposition: attachment" . $eol; + $body .= chunk_split(base64_encode($content)) . $eol; + return $body; + } + + protected function html_wrapper($text) + { + $html =''; + $html .=''.$this->encode($text).''; + return $html; + } + + protected function html_message($text) + { + $text = $this->html_wrapper($text); + $eol = $this->eol; + $body = $this->sep.'Content-Type: text/html; charset="'.$this->charset.'"'.$eol; + $body .= "Content-Transfer-Encoding: Quot-Printed\n".$eol; + $body .= $text . $eol; + return $body; + } + + public function send($from,$to,$message,$subject,$files=false) + { + $eol = $this->eol; + $this->separator = md5(time()); + $this->sep = "--" . $this->separator . $eol; + + $headers = $this->headers($from,($files!==null)); + $body = $this->html_message($message); + if ($files!==false && is_string($files)) $files = [$files]; + if (is_array($files)) + foreach($files as $k=>$path) $body.=$this->attachment($path); + + $body .= "--" . $this->separator . "--"; + return mail($to, $subject, $body, $headers); + } +} \ No newline at end of file