2 namespace Utility\Comms;
6 * Zend email wrapper class
7 * @author Tjaart Viljoen
8 * @copyright 2012 Nirph Online
19 * Body tag to be compatible with ZF2 mail message
22 protected $_body = array();
27 * @return \Utility\Comms\Email
29 public function __construct()
31 $this->_service = new \Zend\Mail\Message();
35 * Set message context.
36 * @param array $aContext
37 * @return \Utility\Comms\Email
39 public function setContext(array $aContext = array())
41 foreach ($aContext as $sParam => $mValue)
49 $this->_service->setFrom($mValue);
53 if (IS_DEV_ENV || IS_STAGE_ENV)
55 #-> Environmental override.
56 \Utility\Debug::errorLog(
57 'Email.send Override: ' . $mValue,
58 isset($aContext['Subject'])
59 ? $aContext['Subject']
61 . ' to ' . 'nirph@webmail.co.za'
63 $this->_service->addTo('testnirph@bonsaihut.co.za');
64 // $this->_service->addBcc('gerard@nirph.com');
68 $this->_service->addTo($mValue);
72 if (!IS_DEV_ENV && !IS_STAGE_ENV)
74 $this->_service->addCc($mValue);
78 if (!IS_DEV_ENV && !IS_STAGE_ENV)
80 $this->_service->addBcc($mValue);
84 $this->_service->setSubject($mValue);
87 $tmpBody = new \Zend\Mime\Part($mValue);
88 $tmpBody->type = 'text/plain';
89 $this->_body[] = $tmpBody;
90 //$this->_service->setBodyText($mValue);
93 $tmpBody = new \Zend\Mime\Part($mValue);
94 $tmpBody->type = 'text/html';
95 $this->_body[] = $tmpBody;
96 //$this->_service->setBodyHtml($mValue);
98 case 'ComplexAttachment':
99 foreach ($mValue as $cid => $meta)
101 if(isset($meta['data']) && !empty($meta['data']))
103 $file = new \Zend\Mime\Part($meta['data']);
104 $file->disposition = \Zend\Mime\Mime::DISPOSITION_INLINE;
105 $file->encoding = \Zend\Mime\Mime::ENCODING_BASE64;
106 $file->description = 'Attached file';
108 && $file->type = $meta['type'];
109 isset($meta['filename'])
110 && $file->filename = $meta['filename'];
112 $this->_body[] = $file;
113 //$this->_service->addAttachment($file);
118 foreach ($mValue as $fileName => $fileData)
120 if(!empty($fileData))
122 $file = new \Zend\Mime\Part($fileData);
123 $file->disposition = \Zend\Mime\Mime::DISPOSITION_INLINE;
124 $file->encoding = \Zend\Mime\Mime::ENCODING_BASE64;
125 $file->description = 'Attached file';
126 $file->filename = $fileName;
128 $this->_body[] = $file;
129 //$this->_service->addAttachment($file);
140 * @param array $aContext
141 * @return \Utility\Comms\Email
143 public function send(array $aContext = array())
146 || $this->setContext($aContext);
147 $transport = new \Zend\Mail\Transport\Sendmail();
150 * Alteration to include message body as a \Zend\Mime\Message() as per ZF2 specification
152 $body = new \Zend\Mime\Message();
153 $body->setParts($this->_body);
154 $this->_service->setBody($body);
156 $transport->send($this->_service);