@@ -442,36 +442,23 @@ public function register(){
442442 // Create verification request
443443 $ verification_request = $ user ->newEventVerificationRequest ();
444444
445- // TODO: pass into template
446-
447- // Create and send activation email
448- $ mail = new \PHPMailer ;
449-
450- $ mail ->From = $ this ->_app ->site ->admin_email ;
451- $ mail ->FromName = $ this ->_app ->site ->site_title ;
452- $ mail ->addAddress ($ user ->email ); // Add a recipient
453- $ mail ->addReplyTo ($ this ->_app ->site ->admin_email , $ this ->_app ->site ->site_title );
454-
445+ // Create and send verification email
455446 $ twig = $ this ->_app ->view ()->getEnvironment ();
456- $ template = $ twig ->loadTemplate ("mail/activate-new.twig " );
457- $ params = [
447+ $ template = $ twig ->loadTemplate ("mail/activate-new.twig " );
448+ $ notification = new Notification ($ template );
449+ $ notification ->fromWebsite (); // Automatically sets sender and reply-to
450+ $ notification ->addEmailRecipient ($ user ->email , $ user ->display_name , [
458451 "user " => $ user
459- ];
460-
461- // Must manually merge in global variables for block rendering
462- $ params = array_merge ($ twig ->getGlobals (), $ params );
463- $ mail ->Subject = $ template ->renderBlock ('subject ' , $ params );
464- $ mail ->Body = $ template ->renderBlock ('body ' , $ params );
465-
466- $ mail ->isHTML (true ); // Set email format to HTML
452+ ]);
467453
468- if (!$ mail ->send ()) {
454+ try {
455+ $ notification ->send ();
456+ } catch (\Exception \phpmailerException $ e ){
469457 $ ms ->addMessageTranslated ("danger " , "MAIL_ERROR " );
470- error_log ('Mailer Error: ' . $ mail -> ErrorInfo );
458+ error_log ('Mailer Error: ' . $ e -> errorMessage () );
471459 $ this ->_app ->halt (500 );
472460 }
473-
474- // Activation required
461+
475462 $ ms ->addMessageTranslated ("success " , "ACCOUNT_REGISTRATION_COMPLETE_TYPE2 " );
476463 $ verification_request ->save ();
477464 } else
@@ -578,33 +565,23 @@ public function forgotPassword(){
578565 $ event = $ user ->newEventPasswordReset ();
579566
580567 // Email the user asking to confirm this change password request
581- $ mail = new \PHPMailer ;
582-
583- $ mail ->From = $ this ->_app ->site ->admin_email ;
584- $ mail ->FromName = $ this ->_app ->site ->site_title ;
585- $ mail ->addAddress ($ user ->email ); // Add a recipient
586- $ mail ->addReplyTo ($ this ->_app ->site ->admin_email , $ this ->_app ->site ->site_title );
587-
588568 $ twig = $ this ->_app ->view ()->getEnvironment ();
589- $ template = $ twig ->loadTemplate ("mail/password-reset.twig " );
590- $ params = [
569+ $ template = $ twig ->loadTemplate ("mail/password-reset.twig " );
570+ $ notification = new Notification ($ template );
571+ $ notification ->fromWebsite (); // Automatically sets sender and reply-to
572+ $ notification ->addEmailRecipient ($ user ->email , $ user ->display_name , [
591573 "user " => $ user ,
592574 "request_date " => date ("Y-m-d H:i:s " )
593- ];
594-
595- // Must manually merge in global variables for block rendering
596- $ params = array_merge ($ twig ->getGlobals (), $ params );
597- $ mail ->Subject = $ template ->renderBlock ('subject ' , $ params );
598- $ mail ->Body = $ template ->renderBlock ('body ' , $ params );
599-
600- $ mail ->isHTML (true ); // Set email format to HTML
575+ ]);
601576
602- if (!$ mail ->send ()) {
577+ try {
578+ $ notification ->send ();
579+ } catch (\Exception \phpmailerException $ e ){
603580 $ ms ->addMessageTranslated ("danger " , "MAIL_ERROR " );
604- error_log ('Mailer Error: ' . $ mail -> ErrorInfo );
581+ error_log ('Mailer Error: ' . $ e -> errorMessage () );
605582 $ this ->_app ->halt (500 );
606583 }
607-
584+
608585 $ user ->store ();
609586 $ event ->save ();
610587 $ ms ->addMessageTranslated ("success " , "FORGOTPASS_REQUEST_SUCCESS " );
@@ -803,30 +780,20 @@ public function resendActivation(){
803780 $ event = $ user ->newEventVerificationRequest ();
804781
805782 // Email the user
806- $ mail = new \PHPMailer ;
807-
808- $ mail ->From = $ this ->_app ->site ->admin_email ;
809- $ mail ->FromName = $ this ->_app ->site ->site_title ;
810- $ mail ->addAddress ($ user ->email ); // Add a recipient
811- $ mail ->addReplyTo ($ this ->_app ->site ->admin_email , $ this ->_app ->site ->site_title );
812-
813783 $ twig = $ this ->_app ->view ()->getEnvironment ();
814- $ template = $ twig ->loadTemplate ("mail/resend-activation.twig " );
815- $ params = [
784+ $ template = $ twig ->loadTemplate ("mail/resend-activation.twig " );
785+ $ notification = new Notification ($ template );
786+ $ notification ->fromWebsite (); // Automatically sets sender and reply-to
787+ $ notification ->addEmailRecipient ($ user ->email , $ user ->display_name , [
816788 "user " => $ user ,
817789 "secret_token " => $ user ->secret_token
818- ];
819-
820- // Must manually merge in global variables for block rendering
821- $ params = array_merge ($ twig ->getGlobals (), $ params );
822- $ mail ->Subject = $ template ->renderBlock ('subject ' , $ params );
823- $ mail ->Body = $ template ->renderBlock ('body ' , $ params );
824-
825- $ mail ->isHTML (true ); // Set email format to HTML
790+ ]);
826791
827- if (!$ mail ->send ()) {
792+ try {
793+ $ notification ->send ();
794+ } catch (\Exception \phpmailerException $ e ){
828795 $ ms ->addMessageTranslated ("danger " , "MAIL_ERROR " );
829- error_log ('Mailer Error: ' . $ mail -> ErrorInfo );
796+ error_log ('Mailer Error: ' . $ e -> errorMessage () );
830797 $ this ->_app ->halt (500 );
831798 }
832799
0 commit comments