Mark V
1: <?php
2: namespace MOC\V\Component\Mail\Component\Bridge\Repository;
3:
4: use Eden\Mail\Smtp;
5: use MOC\V\Component\Mail\Component\Bridge\Bridge;
6: use MOC\V\Component\Mail\Component\IBridgeInterface;
7: use MOC\V\Component\Mail\Component\Parameter\Repository\FileParameter;
8: use MOC\V\Component\Mail\Exception\MailException;
9: use MOC\V\Core\AutoLoader\AutoLoader;
10:
11: /**
12: * Class EdenPhpSmtp
13: *
14: * @package MOC\V\Component\Mail\Component\Bridge\Repository
15: */
16: class EdenPhpSmtp extends Bridge implements IBridgeInterface
17: {
18:
19: /** @var null|Smtp $Instance */
20: private $Instance = null;
21: /** @var array $Header */
22: private $Header = array();
23:
24: /**
25: *
26: */
27: public function __construct()
28: {
29:
30: AutoLoader::getNamespaceAutoLoader('Eden\Mail',
31: __DIR__.'/../../../Vendor/EdenPhpMail/1.0.3-Master',
32: 'Eden\Mail'
33: );
34: AutoLoader::getNamespaceAutoLoader('Eden\Core',
35: __DIR__.'/../../../Vendor/EdenPhpMail/1.0.3-Master/vendor/eden/core/Eden/Core',
36: 'Eden\Core'
37: );
38: AutoLoader::getNamespaceAutoLoader('Eden\System',
39: __DIR__.'/../../../Vendor/EdenPhpMail/1.0.3-Master/vendor/eden/system/Eden/System',
40: 'Eden\System'
41: );
42: AutoLoader::getNamespaceAutoLoader('Eden\Type',
43: __DIR__.'/../../../Vendor/EdenPhpMail/1.0.3-Master/vendor/eden/type/Eden/Type',
44: 'Eden\Type'
45: );
46: }
47:
48: /**
49: * @param string $Host
50: * @param string $Username
51: * @param string $Password
52: * @param null|int $Port
53: * @param bool $useSSL
54: * @param bool $useTLS
55: *
56: * @return EdenPhpSmtp
57: * @throws MailException
58: */
59: public function connectServer($Host, $Username, $Password, $Port = null, $useSSL = false, $useTLS = false)
60: {
61:
62: try {
63: $this->Instance = new Smtp($Host, $Username, $Password, $Port, $useSSL, $useTLS);
64: $this->Instance->connect();
65: } catch (\Exception $Exception) {
66: throw new MailException($Exception->getMessage(), $Exception->getCode(), $Exception);
67: }
68: return $this;
69: }
70:
71: /**
72: * @return EdenPhpSmtp
73: * @throws MailException
74: */
75: public function disconnectServer()
76: {
77:
78: try {
79: $this->Instance->disconnect();
80: $this->Instance->reset();
81: } catch (\Exception $Exception) {
82: throw new MailException($Exception->getMessage(), $Exception->getCode(), $Exception);
83: }
84: return $this;
85: }
86:
87: /**
88: * @param $Address
89: *
90: * @return EdenPhpSmtp
91: */
92: public function setFromHeader($Address)
93: {
94:
95: $this->Header['From'] = $Address;
96: return $this;
97: }
98:
99: /**
100: * @param $Address
101: *
102: * @return EdenPhpSmtp
103: */
104: public function setReplyHeader($Address)
105: {
106:
107: $this->Header['Reply-To'] = $Address;
108: return $this;
109: }
110:
111: /**
112: * @return EdenPhpSmtp
113: * @throws MailException
114: */
115: public function sendMail()
116: {
117:
118: try {
119: $this->Instance->send($this->Header);
120: } catch (\Exception $Exception) {
121: throw new MailException($Exception->getMessage(), $Exception->getCode(), $Exception);
122: }
123: return $this;
124: }
125:
126: /**
127: * @param string $Content
128: *
129: * @return EdenPhpSmtp
130: * @throws MailException
131: */
132: public function setMailSubject($Content)
133: {
134:
135: try {
136: $this->Instance->setSubject($Content);
137: } catch (\Exception $Exception) {
138: throw new MailException($Exception->getMessage(), $Exception->getCode(), $Exception);
139: }
140: return $this;
141: }
142:
143: /**
144: * @param string $Content
145: * @param bool $useHtml
146: *
147: * @return EdenPhpSmtp
148: * @throws MailException
149: */
150: public function setMailBody($Content, $useHtml = true)
151: {
152:
153: try {
154: $this->Instance->setBody($Content, $useHtml);
155: } catch (\Exception $Exception) {
156: throw new MailException($Exception->getMessage(), $Exception->getCode(), $Exception);
157: }
158: return $this;
159: }
160:
161: /**
162: * @param string $Address
163: * @param null|string $Name
164: *
165: * @return EdenPhpSmtp
166: * @throws MailException
167: */
168: public function addRecipientTO($Address, $Name = null)
169: {
170:
171: try {
172: $this->Instance->addTo($Address, $Name);
173: } catch (\Exception $Exception) {
174: throw new MailException($Exception->getMessage(), $Exception->getCode(), $Exception);
175: }
176: return $this;
177: }
178:
179: /**
180: * @param string $Address
181: * @param null|string $Name
182: *
183: * @return EdenPhpSmtp
184: * @throws MailException
185: */
186: public function addRecipientCC($Address, $Name = null)
187: {
188:
189: try {
190: $this->Instance->addCC($Address, $Name);
191: } catch (\Exception $Exception) {
192: throw new MailException($Exception->getMessage(), $Exception->getCode(), $Exception);
193: }
194: return $this;
195: }
196:
197: /**
198: * @param string $Address
199: * @param null|string $Name
200: *
201: * @return EdenPhpSmtp
202: * @throws MailException
203: */
204: public function addRecipientBCC($Address, $Name = null)
205: {
206:
207: try {
208: $this->Instance->addBCC($Address, $Name);
209: } catch (\Exception $Exception) {
210: throw new MailException($Exception->getMessage(), $Exception->getCode(), $Exception);
211: }
212: return $this;
213: }
214:
215: /**
216: * @param FileParameter $File
217: *
218: * @return EdenPhpSmtp
219: * @throws MailException
220: */
221: public function addAttachment(FileParameter $File)
222: {
223:
224: try {
225: $this->Instance->addAttachment($File->getFileInfo()->getRealPath(),
226: file_get_contents($File->getFileInfo()->getRealPath()));
227: } catch (\Exception $Exception) {
228: throw new MailException($Exception->getMessage(), $Exception->getCode(), $Exception);
229: }
230: return $this;
231: }
232: }
233: