88use PhpList \Core \Domain \Messaging \Service \EmailService ;
99use Symfony \Component \Messenger \Attribute \AsMessageHandler ;
1010use Symfony \Component \Mime \Email ;
11+ use Symfony \Contracts \Translation \TranslatorInterface ;
1112
1213#[AsMessageHandler]
1314class PasswordResetMessageHandler
1415{
1516 private EmailService $ emailService ;
17+ private TranslatorInterface $ translator ;
1618 private string $ passwordResetUrl ;
1719
18- public function __construct (EmailService $ emailService , string $ passwordResetUrl )
20+ public function __construct (EmailService $ emailService , TranslatorInterface $ translator , string $ passwordResetUrl )
1921 {
2022 $ this ->emailService = $ emailService ;
23+ $ this ->translator = $ translator ;
2124 $ this ->passwordResetUrl = $ passwordResetUrl ;
2225 }
2326
@@ -28,19 +31,37 @@ public function __invoke(PasswordResetMessage $message): void
2831 {
2932 $ confirmationLink = $ this ->generateLink ($ message ->getToken ());
3033
31- $ subject = 'Password Reset Request ' ;
32- $ textContent = "Hello, \n\n"
33- . "A password reset has been requested for your account. \n"
34- . "Please use the following token to reset your password: \n\n"
35- . $ message ->getToken ()
36- . "\n\nIf you did not request this password reset, please ignore this email. \n\nThank you. " ;
37-
38- $ htmlContent = '<p>Password Reset Request!</p> '
39- . '<p>Hello! A password reset has been requested for your account.</p> '
40- . '<p>Please use the following token to reset your password:</p> '
41- . '<p><a href=" ' . $ confirmationLink . '">Reset Password</a></p> '
42- . '<p>If you did not request this password reset, please ignore this email.</p> '
43- . '<p>Thank you.</p> ' ;
34+ $ subject = $ this ->translator ->trans ('Password Reset Request ' );
35+ $ textContent = $ this ->translator ->trans (
36+ <<<TXT
37+ Hello,
38+
39+ A password reset has been requested for your account.
40+ Please use the following token to reset your password:
41+
42+ %token%
43+
44+ If you did not request this password reset, please ignore this email.
45+
46+ Thank you.
47+ TXT ,
48+ ['%token% ' => $ message ->getToken ()]
49+ );
50+
51+ $ htmlContent = $ this ->translator ->trans (
52+ <<<HTML
53+ <p>Password Reset Request!</p>
54+ <p>Hello! A password reset has been requested for your account.</p>
55+ <p>Please use the following token to reset your password:</p>
56+ <p><a href="%confirmationLink%">Reset Password</a></p>
57+ <p>If you did not request this password reset, please ignore this email.</p>
58+ <p>Thank you.</p>
59+ HTML ,
60+ [
61+ '%token% ' => $ message ->getToken (),
62+ '%confirmationLink% ' => $ confirmationLink ,
63+ ]
64+ );
4465
4566 $ email = (new Email ())
4667 ->to ($ message ->getEmail ())
0 commit comments