19 declare(strict_types=1);
52 $this->
http = $DIC->http();
56 $this->senderFactory = $DIC[
'mail.mime.sender.factory'];
61 $this->lang_variables_as_fallback = $a_status;
81 $this->u_password = $a_pwd;
95 $this->attachments = [];
98 $this->
user = $a_user;
114 $this->u_password =
'';
124 foreach ([
'lang',
'subject',
'body',
'sal_f',
'sal_g',
'sal_m',
'type'] as
$key) {
125 if (!isset($mailData[$key])) {
126 $mailData[
$key] =
'';
130 $mailData[
'subject'] = trim($mailData[
'subject']);
131 $mailData[
'body'] = trim($mailData[
'body']);
141 if (!isset($this->amail[$a_lang]) || !is_array($this->amail[$a_lang])) {
147 return $this->amail[$a_lang];
161 $pathToFile =
'/' . implode(
'/', array_map(
static function (
string $pathPart):
string {
162 return trim($pathPart,
'/');
164 $fs->getAbsolutePath(),
183 if (null === $user) {
184 throw new RuntimeException(
'A user instance must be passed when sending emails');
195 if ($amail[
'body'] ===
'' || $amail[
'subject'] ===
'') {
196 $fallback_language =
'en';
198 $lang = $this->
settings->get(
'language', $fallback_language);
206 $mail_subject = $tmp_lang->txt(
'reg_mail_subject');
210 $tmp_lang->loadLanguageModule(
"registration");
216 $timelimit =
"\n" . sprintf($tmp_lang->txt(
'reg_mail_body_timelimit'), $timelimit) .
"\n\n";
220 $mail_body = $tmp_lang->txt(
'reg_mail_body_salutation') .
' ' . $user->
getFullname() .
",\n\n" .
221 $tmp_lang->txt(
'reg_mail_body_text1') .
"\n\n" .
222 $tmp_lang->txt(
'reg_mail_body_text2') .
"\n" .
223 ILIAS_HTTP_PATH .
'/login.php?client_id=' .
CLIENT_ID .
"\n";
224 $mail_body .= $tmp_lang->txt(
'login') .
': ' . $user->
getLogin() .
"\n";
225 $mail_body .= $tmp_lang->txt(
'passwd') .
': ' . $this->u_password .
"\n";
226 $mail_body .=
"\n" . $timelimit;
227 $mail_body .= $tmp_lang->txt(
'reg_mail_body_text3') .
"\n\r";
228 $mail_body .= $user->getProfileAsString($tmp_lang);
238 $mmail->From($this->senderFactory->system());
239 $mmail->Subject($mail_subject,
true);
241 $mmail->Body($mail_body);
243 foreach ($this->attachments as
$filename => $display_name) {
244 $mmail->Attach(
$filename,
'',
'attachment', $display_name);
256 $gender_salut = $a_amail[
'sal_f'];
259 $gender_salut = $a_amail[
'sal_m'];
262 $gender_salut = $a_amail[
'sal_g'];
264 $gender_salut = trim($gender_salut);
266 $a_string = str_replace(
275 '[INSTALLATION_NAME]',
285 ILIAS_HTTP_PATH .
'/login.php?client_id=' .
CLIENT_ID,
287 $this->
settings->get(
'admin_email',
''),
295 $a_string = preg_replace(
296 "/\[IF_PASSWORD\].*\[\/IF_PASSWORD\]/imsU",
300 $a_string = preg_replace(
301 "/\[IF_NO_PASSWORD\](.*)\[\/IF_NO_PASSWORD\]/imsU",
306 $a_string = preg_replace(
307 "/\[IF_NO_PASSWORD\].*\[\/IF_NO_PASSWORD\]/imsU",
311 $a_string = preg_replace(
312 "/\[IF_PASSWORD\](.*)\[\/IF_PASSWORD\]/imsU",
321 $a_string = preg_replace(
322 "/\[IF_TIMELIMIT\](.*)\[\/IF_TIMELIMIT\]/imsU",
329 $a_string = str_replace(
"[TIMELIMIT]", $timelimit, $a_string);
331 $a_string = preg_replace(
332 "/\[IF_TIMELIMIT\](.*)\[\/IF_TIMELIMIT\]/imsU",
340 if ($this->
http->wrapper()->query()->has(
'target') &&
341 $this->
http->wrapper()->query()->retrieve(
'target', $this->
refinery->kindlyTo()->string()) !==
'' 343 $target = $this->
http->wrapper()->query()->retrieve(
'target', $this->
refinery->kindlyTo()->string());
344 $tarr = explode(
'_', $target);
348 if (
$type === $tarr[0]) {
349 $a_string = str_replace(
350 [
'[TARGET_TITLE]',
'[TARGET]'],
353 ILIAS_HTTP_PATH .
'/goto.php?client_id=' .
CLIENT_ID .
'&target=' . $target
360 $a_string = str_replace(
373 $a_string = preg_replace(
"/\[IF_TARGET\].*\[\/IF_TARGET\]/imsU",
'', $a_string);
375 $a_string = preg_replace(
"/\[IF_TARGET\](.*)\[\/IF_TARGET\]/imsU",
"$1", $a_string);
381 public function addAttachment(
string $a_filename,
string $a_display_name): void
383 $this->attachments[$a_filename] = $a_display_name;
Interface GlobalHttpState.
send()
Sends the mail with its object properties as MimeMail It first tries to read the mail body...
shouldAttachConfiguredFiles()
bool $lang_variables_as_fallback
Class ilMailMimeSenderFactory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readAccountMail(string $a_lang)
setAttachConfiguredFiles(bool $attachConfiguredFiles)
getFullname(int $a_max_strlen=0)
ensureValidMailDataShape(array $mailData)
addAttachments(array $mailData)
areLangVariablesUsedAsFallback()
ilMailMimeSenderFactory $senderFactory
static _lookupObjId(int $ref_id)
replacePlaceholders(string $a_string, ilObjUser $a_user, array $a_amail, string $a_lang)
static http()
Fetches the global http state from ILIAS.
setUserPassword(string $a_pwd)
static _lookupTitle(int $obj_id)
static _lookupNewAccountMail(string $a_lang)
useLangVariablesAsFallback(bool $a_status)
addAttachment(string $a_filename, string $a_display_name)
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false)
Format a period of two dates Shows: 14.
setUser(ilObjUser $a_user)
bool $attachConfiguredFiles
static _lookupEntry(string $a_lang_key, string $a_mod, string $a_id)
static _lookupType(int $id, bool $reference=false)