ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Mail.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
27{
28 public function __construct(
29 private readonly \ilObjUser $user,
30 private readonly URI $uri,
31 private readonly Language $lng,
32 private \ilLogger $logger
33 ) {
34 $lng->loadLanguageModule('mail');
36 }
37
38 public function send(string $new_email, int $validity): void
39 {
40 $this->sendEmailToNewEmailAddress($new_email, $validity);
41 $this->sendEmailToExistingAddress($new_email, $validity);
42 }
43
44 private function sendEmailToNewEmailAddress(string $new_email, int $validity): void
45 {
46 $this->initMimeMail();
47 $this->initLanguageByIso2Code($this->user->getLanguage());
48 $this->setSubject($this->lng->txt('change_email_email_confirmation_subject'));
49 $this->setBody($this->lng->txt('mail_salutation_n') . ' ' . $this->user->getFullname() . ',');
50 $this->appendBody("\n\n");
51 $this->appendBody(
52 sprintf(
53 $this->lng->txt('change_email_email_confirmation_body'),
54 $this->user->getLogin(),
55 $this->uri->__toString(),
56 floor($validity / 60)
57 )
58 );
60
61 $this->sendMimeMail($new_email);
62 $this->logger->debug(
63 sprintf(
64 'Email to confirm email change sent to user %s (id: %s|language: %s).',
65 $this->user->getLogin(),
66 $this->user->getId(),
67 $this->user->getLanguage()
68 )
69 );
70 }
71
72 private function sendEmailToExistingAddress(string $new_email, int $validity): void
73 {
74 if (!$this->user->getEmail()) {
75 $this->logger->debug(
76 sprintf(
77 'Missing email address, did not send email to inform about email change to user %s (id: %s)',
78 $this->user->getLogin(),
79 $this->user->getId()
80 )
81 );
82 return;
83 }
84
85 $this->initMimeMail();
86 $this->initLanguageByIso2Code($this->user->getLanguage());
87 $this->setSubject($this->lng->txt('change_email_email_information_subject'));
88 $this->setBody($this->lng->txt('mail_salutation_n') . ' ' . $this->user->getFullname() . ',');
89 $this->appendBody("\n\n");
90 $this->appendBody(
91 sprintf(
92 $this->lng->txt('change_email_email_information_body'),
93 $this->user->getLogin(),
94 $new_email,
95 floor($validity / 60)
96 )
97 );
99
100 $this->sendMimeMail($this->user->getEmail());
101 $this->logger->debug(
102 sprintf(
103 'Email to inform about email change sent to user %s (id: %s|language: %s).',
104 $this->user->getLogin(),
105 $this->user->getId(),
106 $this->user->getLanguage()
107 )
108 );
109
110 }
111}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
__construct(private readonly \ilObjUser $user, private readonly URI $uri, private readonly Language $lng, private \ilLogger $logger)
Definition: Mail.php:28
sendEmailToNewEmailAddress(string $new_email, int $validity)
Definition: Mail.php:44
send(string $new_email, int $validity)
Definition: Mail.php:38
sendEmailToExistingAddress(string $new_email, int $validity)
Definition: Mail.php:72
Component logger with individual log levels by component id.
static _getInstallationSignature()
User class.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
RFC 822 Email address list validation Utility.
global $lng
Definition: privfeed.php:31