19declare(strict_types=1);
60 $factory =
$DIC->mail()->mime()->transportFactory();
70 self::$default_transport = $transport;
78 public function Subject(
string $subject,
bool $add_prefix =
false,
string $context_prefix =
''): void
80 $this->subject = $this->subject_builder->subject(
$subject, $add_prefix, $context_prefix);
96 public function To($to): void
101 $this->sendto[] = $to;
108 public function Cc($cc): void
120 public function Bcc($bcc): void
122 if (is_array($bcc)) {
125 $this->abcc[] = $bcc;
182 string $file_type =
'',
183 string $disposition =
'inline',
184 ?
string $display_name =
null
186 if ($file_type ===
'') {
187 $file_type =
'application/octet-stream';
191 $this->actype[] = $file_type;
192 $this->adispo[] = $disposition;
193 $this->adisplay[] = $display_name;
204 foreach ($this->aattach as $attachment) {
206 if (isset($this->adisplay[$i]) && is_string($this->adisplay[$i]) && $this->adisplay[$i] !==
'') {
207 $name = $this->adisplay[$i];
211 'path' => $attachment,
226 return array_values($this->images);
233 $this->final_body_alt =
'';
234 $this->final_body =
'';
237 if (
$DIC->settings()->get(
'mail_send_html',
'0')) {
238 $skin =
$DIC[
'ilClientIniFile']->readVariable(
'layout',
'skin');
239 $style =
$DIC[
'ilClientIniFile']->readVariable(
'layout',
'style');
241 $this->buildBodyMultiParts($skin, $style);
242 $this->buildHtmlInlineImages($skin, $style);
244 $this->final_body = $this->removeHTMLTags($this->body);
250 $maybe_html = str_ireplace([
'<br />',
'<br>',
'<br/>'],
"\n", $maybe_html);
252 return strip_tags($maybe_html);
257 if ($this->body ===
'') {
261 if (strip_tags($this->body,
'<b><u><i><a>') === $this->body) {
265 $this->final_body_alt = strip_tags($this->body);
266 $this->body = $this->
refinery->string()->makeClickable()->transform(nl2br($this->body));
269 $this->final_body_alt = strip_tags(str_ireplace([
"<br />",
"<br>",
"<br/>"],
"\n", $this->body));
272 $this->final_body = str_replace(
'{PLACEHOLDER}', $this->body, $this->getHtmlEnvelope($skin, $style));
277 return realpath(dirname(__DIR__, 4) .
'/');
282 $bracket_path = $this->getPathToRootDirectory() .
'/components/ILIAS/Mail/templates/default/tpl.html_mail_template.html';
283 if ($skin !==
'default') {
290 $custom_path = $this->getPathToRootDirectory(
291 ) .
'/public/Customizing/skin/' .
$location .
'/components/ILIAS/Mail/tpl.html_mail_template.html';
292 if (is_file($custom_path)) {
293 $bracket_path = $custom_path;
299 return file_get_contents($bracket_path);
304 $this->gatherImagesFromDirectory(
305 $this->getPathToRootDirectory() .
'/components/ILIAS/Mail/templates/default/img'
308 if ($skin !==
'default') {
315 $custom_directory = $this->getPathToRootDirectory(
316 ) .
'/public/Customizing/skin/' .
$location .
'/components/ILIAS/Mail/img';
317 if (is_dir($custom_directory) && is_readable($custom_directory)) {
318 $this->gatherImagesFromDirectory($custom_directory,
true);
325 protected function gatherImagesFromDirectory(
string $directory,
bool $clear_previous =
false): void
327 if ($clear_previous) {
331 foreach (
new RegexIterator(
332 new DirectoryIterator($directory),
333 '/\.(jpg|jpeg|gif|svg|png)$/i'
336 $cid =
'img/' . $file->getFilename();
338 $this->images[$cid] = [
339 'path' => $file->getPathname(),
341 'name' => $file->getFilename()
349 $transport = self::getDefaultTransport();
354 return $transport->send($this);
Attach(string $filename, string $file_type='', string $disposition='inline', ?string $display_name=null)
final const string MAIL_SUBJECT_PREFIX
removeHTMLTags(string $maybe_html)
Send(?ilMailMimeTransport $transport=null)
buildBodyMultiParts(string $skin, string $style)
static ilMailMimeTransport $default_transport
static getDefaultTransport()
static setDefaultTransport(?ilMailMimeTransport $transport)
Subject(string $subject, bool $add_prefix=false, string $context_prefix='')
ilMailMimeSubjectBuilder $subject_builder
readonly Refinery $refinery
From(ilMailMimeSender $sender)
getHtmlEnvelope(string $skin, string $style)
buildHtmlInlineImages(string $skin, string $style)
if(!file_exists('../ilias.ini.php'))