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/**
1314 * Handler for processing asynchronous subscriber confirmation email messages
1617class SubscriberConfirmationMessageHandler
1718{
1819 private EmailService $ emailService ;
20+ private TranslatorInterface $ translator ;
1921 private string $ confirmationUrl ;
2022
21- public function __construct (EmailService $ emailService , string $ confirmationUrl )
23+ public function __construct (EmailService $ emailService , TranslatorInterface $ translator , string $ confirmationUrl )
2224 {
2325 $ this ->emailService = $ emailService ;
26+ $ this ->translator = $ translator ;
2427 $ this ->confirmationUrl = $ confirmationUrl ;
2528 }
2629
@@ -31,18 +34,36 @@ public function __invoke(SubscriberConfirmationMessage $message): void
3134 {
3235 $ confirmationLink = $ this ->generateConfirmationLink ($ message ->getUniqueId ());
3336
34- $ subject = 'Please confirm your subscription ' ;
35- $ textContent = "Thank you for subscribing! \n\n"
36- . "Please confirm your subscription by clicking the link below: \n"
37- . $ confirmationLink . "\n\n"
38- . 'If you did not request this subscription, please ignore this email. ' ;
37+ $ subject = $ this ->translator ->trans ('Please confirm your subscription ' );
38+
39+ $ textContent = $ this ->translator ->trans (
40+ <<<TXT
41+ Thank you for subscribing!
42+
43+ Please confirm your subscription by clicking the link below:
44+
45+ %confirmationLink%
46+
47+ If you did not request this subscription, please ignore this email.
48+ TXT ,
49+ [
50+ '%confirmationLink% ' => $ confirmationLink
51+ ]
52+ );
3953
4054 $ htmlContent = '' ;
4155 if ($ message ->hasHtmlEmail ()) {
42- $ htmlContent = '<p>Thank you for subscribing!</p> '
43- . '<p>Please confirm your subscription by clicking the link below:</p> '
44- . '<p><a href=" ' . $ confirmationLink . '">Confirm Subscription</a></p> '
45- . '<p>If you did not request this subscription, please ignore this email.</p> ' ;
56+ $ htmlContent = $ this ->translator ->trans (
57+ <<<HTML
58+ <p>Thank you for subscribing!</p>
59+ <p>Please confirm your subscription by clicking the link below:</p>
60+ <p><a href="%confirmationLink%">Confirm Subscription</a></p>
61+ <p>If you did not request this subscription, please ignore this email.</p>
62+ HTML ,
63+ [
64+ '%confirmationLink% ' => $ confirmationLink ,
65+ ]
66+ );
4667 }
4768
4869 $ email = (new Email ())
0 commit comments