16
16
use \CarlBennett \MVC \Libraries \Common ;
17
17
use \CarlBennett \MVC \Libraries \Controller ;
18
18
use \CarlBennett \MVC \Libraries \Router ;
19
+ use \CarlBennett \MVC \Libraries \Template ;
19
20
use \CarlBennett \MVC \Libraries \View ;
20
21
22
+ use \PHPMailer \PHPMailer \Exception ;
23
+ use \PHPMailer \PHPMailer \PHPMailer ;
24
+
21
25
class Register extends Controller {
22
26
23
27
public function &run (Router &$ router , View &$ view , array &$ args ) {
@@ -136,7 +140,7 @@ protected function tryRegister(Router &$router, UserRegisterModel &$model) {
136
140
return ;
137
141
}
138
142
} catch (UserNotFoundException $ e ) {}
139
-
143
+
140
144
try {
141
145
if (User::findIdByUsername ($ username )) {
142
146
$ model ->error = "USERNAME_TAKEN " ;
@@ -158,6 +162,68 @@ protected function tryRegister(Router &$router, UserRegisterModel &$model) {
158
162
159
163
}
160
164
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
+
161
227
if (!$ success ) {
162
228
$ model ->error = "INTERNAL_ERROR " ;
163
229
} else {
0 commit comments