ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ChangeMailMail.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\User\Profile;
22 
24 use ILIAS\Data\URI;
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');
35  parent::__construct(false);
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 }
__construct(private readonly \ilObjUser $user, private readonly URI $uri, private readonly Language $lng, private \ilLogger $logger)
sendEmailToExistingAddress(string $new_email, int $validity)
send(string $new_email, int $validity)
sendEmailToNewEmailAddress(string $new_email, int $validity)
Base class for mime mail notifications.
__construct(Container $dic, ilPlugin $plugin)
global $lng
Definition: privfeed.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getInstallationSignature()