shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

mail.php (3128B)


      1 <?php
      2 namespace Mail;
      3 class Mail {
      4 	public function send() {
      5 		if (is_array($this->to)) {
      6 			$to = implode(',', $this->to);
      7 		} else {
      8 			$to = $this->to;
      9 		}
     10 
     11 		$boundary = '----=_NextPart_' . md5(time());
     12 
     13 		$header  = 'MIME-Version: 1.0' . PHP_EOL;
     14 		$header .= 'Date: ' . date('D, d M Y H:i:s O') . PHP_EOL;
     15 		$header .= 'From: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;
     16 		
     17 		if (!$this->reply_to) {
     18 			$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;
     19 		} else {
     20 			$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->reply_to) . '?= <' . $this->reply_to . '>' . PHP_EOL;
     21 		}
     22 		
     23 		$header .= 'Return-Path: ' . $this->from . PHP_EOL;
     24 		$header .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;
     25 		$header .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . PHP_EOL . PHP_EOL;
     26 
     27 		if (!$this->html) {
     28 			$message  = '--' . $boundary . PHP_EOL;
     29 			$message .= 'Content-Type: text/plain; charset="utf-8"' . PHP_EOL;
     30 			$message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
     31 			$message .= $this->text . PHP_EOL;
     32 		} else {
     33 			$message  = '--' . $boundary . PHP_EOL;
     34 			$message .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '_alt"' . PHP_EOL . PHP_EOL;
     35 			$message .= '--' . $boundary . '_alt' . PHP_EOL;
     36 			$message .= 'Content-Type: text/plain; charset="utf-8"' . PHP_EOL;
     37 			$message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
     38 
     39 			if ($this->text) {
     40 				$message .= $this->text . PHP_EOL;
     41 			} else {
     42 				$message .= 'This is a HTML email and your email client software does not support HTML email!' . PHP_EOL;
     43 			}
     44 
     45 			$message .= '--' . $boundary . '_alt' . PHP_EOL;
     46 			$message .= 'Content-Type: text/html; charset="utf-8"' . PHP_EOL;
     47 			$message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
     48 			$message .= $this->html . PHP_EOL;
     49 			$message .= '--' . $boundary . '_alt--' . PHP_EOL;
     50 		}
     51 
     52 		foreach ($this->attachments as $attachment) {
     53 			if (file_exists($attachment)) {
     54 				$handle = fopen($attachment, 'r');
     55 
     56 				$content = fread($handle, filesize($attachment));
     57 
     58 				fclose($handle);
     59 
     60 				$message .= '--' . $boundary . PHP_EOL;
     61 				$message .= 'Content-Type: application/octet-stream; name="' . basename($attachment) . '"' . PHP_EOL;
     62 				$message .= 'Content-Transfer-Encoding: base64' . PHP_EOL;
     63 				$message .= 'Content-Disposition: attachment; filename="' . basename($attachment) . '"' . PHP_EOL;
     64 				$message .= 'Content-ID: <' . urlencode(basename($attachment)) . '>' . PHP_EOL;
     65 				$message .= 'X-Attachment-Id: ' . urlencode(basename($attachment)) . PHP_EOL . PHP_EOL;
     66 				$message .= chunk_split(base64_encode($content));
     67 			}
     68 		}
     69 
     70 		$message .= '--' . $boundary . '--' . PHP_EOL;
     71 
     72 		ini_set('sendmail_from', $this->from);
     73 
     74 		if ($this->parameter) {
     75 			mail($to, '=?UTF-8?B?' . base64_encode($this->subject) . '?=', $message, $header, $this->parameter);
     76 		} else {
     77 			mail($to, '=?UTF-8?B?' . base64_encode($this->subject) . '?=', $message, $header);
     78 		}
     79 	}
     80 }