mail.php (2540B)
1 <?php 2 /** 3 * @package OpenCart 4 * @author Daniel Kerr 5 * @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/) 6 * @license https://opensource.org/licenses/GPL-3.0 7 * @link https://www.opencart.com 8 */ 9 10 /** 11 * Mail class 12 */ 13 class Mail { 14 protected $to; 15 protected $from; 16 protected $sender; 17 protected $reply_to; 18 protected $subject; 19 protected $text; 20 protected $html; 21 protected $attachments = array(); 22 public $parameter; 23 24 /** 25 * Constructor 26 * 27 * @param string $adaptor 28 * 29 */ 30 public function __construct($adaptor = 'mail') { 31 $class = 'Mail\\' . $adaptor; 32 33 if (class_exists($class)) { 34 $this->adaptor = new $class(); 35 } else { 36 trigger_error('Error: Could not load mail adaptor ' . $adaptor . '!'); 37 exit(); 38 } 39 } 40 41 /** 42 * 43 * 44 * @param mixed $to 45 */ 46 public function setTo($to) { 47 $this->to = $to; 48 } 49 50 /** 51 * 52 * 53 * @param string $from 54 */ 55 public function setFrom($from) { 56 $this->from = $from; 57 } 58 59 /** 60 * 61 * 62 * @param string $sender 63 */ 64 public function setSender($sender) { 65 $this->sender = $sender; 66 } 67 68 /** 69 * 70 * 71 * @param string $reply_to 72 */ 73 public function setReplyTo($reply_to) { 74 $this->reply_to = $reply_to; 75 } 76 77 /** 78 * 79 * 80 * @param string $subject 81 */ 82 public function setSubject($subject) { 83 $this->subject = $subject; 84 } 85 86 /** 87 * 88 * 89 * @param string $text 90 */ 91 public function setText($text) { 92 $this->text = $text; 93 } 94 95 /** 96 * 97 * 98 * @param string $html 99 */ 100 public function setHtml($html) { 101 $this->html = $html; 102 } 103 104 /** 105 * 106 * 107 * @param string $filename 108 */ 109 public function addAttachment($filename) { 110 $this->attachments[] = $filename; 111 } 112 113 /** 114 * 115 * 116 */ 117 public function send() { 118 if (!$this->to) { 119 throw new \Exception('Error: E-Mail to required!'); 120 } 121 122 if (!$this->from) { 123 throw new \Exception('Error: E-Mail from required!'); 124 } 125 126 if (!$this->sender) { 127 throw new \Exception('Error: E-Mail sender required!'); 128 } 129 130 if (!$this->subject) { 131 throw new \Exception('Error: E-Mail subject required!'); 132 } 133 134 if ((!$this->text) && (!$this->html)) { 135 throw new \Exception('Error: E-Mail message required!'); 136 } 137 138 foreach (get_object_vars($this) as $key => $value) { 139 $this->adaptor->$key = $value; 140 } 141 142 $this->adaptor->send(); 143 } 144 }