1616use \CarlBennett \MVC \Libraries \Common ;
1717use \CarlBennett \MVC \Libraries \Controller ;
1818use \CarlBennett \MVC \Libraries \Router ;
19+ use \CarlBennett \MVC \Libraries \Template ;
1920use \CarlBennett \MVC \Libraries \View ;
2021
22+ use \PHPMailer \PHPMailer \Exception ;
23+ use \PHPMailer \PHPMailer \PHPMailer ;
24+
2125class Register extends Controller {
2226
2327 public function &run (Router &$ router , View &$ view , array &$ args ) {
@@ -136,7 +140,7 @@ protected function tryRegister(Router &$router, UserRegisterModel &$model) {
136140 return ;
137141 }
138142 } catch (UserNotFoundException $ e ) {}
139-
143+
140144 try {
141145 if (User::findIdByUsername ($ username )) {
142146 $ model ->error = "USERNAME_TAKEN " ;
@@ -158,6 +162,68 @@ protected function tryRegister(Router &$router, UserRegisterModel &$model) {
158162
159163 }
160164
165+ if ($ success ) {
166+ $ mail = new PHPMailer ( true ); // true enables exceptions
167+ $ mail_config = Common::$ config ->email ;
168+
169+ try {
170+ //Server settings
171+ $ mail ->Timeout = 10 ; // default is 300 per RFC2821 $ 4.5.3.2
172+ $ mail ->SMTPDebug = 0 ;
173+ $ mail ->isSMTP ();
174+ $ mail ->Host = $ mail_config ->smtp_host ;
175+ $ mail ->SMTPAuth = !empty ($ mail_config ->smtp_user );
176+ $ mail ->Username = $ mail_config ->smtp_user ;
177+ $ mail ->Password = $ mail_config ->smtp_password ;
178+ $ mail ->SMTPSecure = $ mail_config ->smtp_tls ? 'tls ' : '' ;
179+ $ mail ->Port = $ mail_config ->smtp_port ;
180+
181+ //Recipients
182+ if (!empty ($ mail_config ->recipient_from )) {
183+ $ mail ->setFrom ($ mail_config ->recipient_from , 'BNETDocs ' );
184+ }
185+
186+ $ mail ->addAddress ($ email );
187+
188+ if (!empty ($ mail_config ->recipient_reply_to )) {
189+ $ mail ->addReplyTo ($ mail_config ->recipient_reply_to );
190+ }
191+
192+ // Content
193+ $ mail ->isHTML (true );
194+ $ mail ->Subject = 'Account Activation ' ;
195+ $ mail ->CharSet = PHPMailer::CHARSET_UTF8 ;
196+
197+ ob_start ();
198+ (new Template ($ mail , 'Email/User/Register.rich ' ))->render ();
199+ $ mail ->Body = ob_get_clean ();
200+
201+ ob_start ();
202+ (new Template ($ mail , 'Email/User/Register.plain ' ))->render ();
203+ $ mail ->AltBody = ob_get_clean ();
204+
205+ $ mail ->send ();
206+
207+ Logger::logEvent (
208+ EventTypes::EMAIL_SENT ,
209+ null ,
210+ getenv ('REMOTE_ADDR ' ),
211+ json_encode ([
212+ 'from ' => $ mail ->From ,
213+ 'to ' => $ mail ->getToAddresses (),
214+ 'reply_to ' => $ mail ->getReplyToAddresses (),
215+ 'subject ' => $ mail ->Subject ,
216+ 'content_type ' => $ mail ->ContentType ,
217+ 'body ' => $ mail ->Body ,
218+ 'alt_body ' => $ mail ->AltBody ,
219+ ])
220+ );
221+
222+ } catch (\Exception $ e ) {
223+ $ model ->error = "EMAIL_FAILURE " ;
224+ }
225+ }
226+
161227 if (!$ success ) {
162228 $ model ->error = "INTERNAL_ERROR " ;
163229 } else {
0 commit comments