8 use Elgg\Traits\Loggable;
10 use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
11 use Symfony\Component\Mailer\MailerInterface;
12 use Symfony\Component\Mime\Email as SymfonyEmail;
37 protected MailerInterface $mailer,
53 $email = $this->events->triggerResults(
'prepare',
'system:email', [],
$email);
55 $msg =
"'prepare','system:email' event handlers should return an instance of " . Email::class;
59 $is_valid =
$email->getFrom() && !empty(
$email->getTo());
60 if (!$this->events->triggerResults(
'validate',
'system:email', [
'email' =>
$email], $is_valid)) {
64 return $this->transport(
$email);
75 if ($this->events->triggerResults(
'transport',
'system:email', [
'email' =>
$email], false)) {
89 'MIME-Version' =>
'1.0',
90 'Content-Transfer-Encoding' =>
'8bit',
108 }
catch (TransportExceptionInterface $e) {
109 $this->
getLogger()->error($e->getMessage());
142 $plain_text =
$email->getBody();
144 $plain_text = html_entity_decode($plain_text, ENT_QUOTES,
'UTF-8');
145 $plain_text = wordwrap($plain_text);
165 if (!$this->config->email_html_part) {
169 $mail_params =
$email->getParams();
171 $html_text =
elgg_extract(
'html_message', $mail_params);
172 if (is_string($html_text)) {
177 $html_text = $this->html_formatter->inlineCss($html_text, $css);
180 $html_text = $this->makeHtmlBody([
181 'subject' =>
$email->getSubject(),
188 $html_text = $this->html_formatter->normalizeUrls($html_text);
189 if (empty($html_text)) {
193 $email_html_part_images = $this->config->email_html_part_images;
194 if ($email_html_part_images !==
'base64' && $email_html_part_images !==
'attach') {
199 $images = $this->findImages($html_text);
200 if (empty($images)) {
205 if ($email_html_part_images ===
'base64') {
206 foreach ($images as
$url) {
208 $image_url = substr(
$url, 1, -1);
211 $image = $this->image_fetcher->getImage($image_url);
218 $base64image =
$image[
'content-type'] .
';charset=UTF-8;base64,' . base64_encode(
$image[
'data']);
221 $replacement = str_replace($image_url,
"data:{$base64image}",
$url);
224 $html_text = str_replace(
$url, $replacement, $html_text);
233 foreach ($images as
$url) {
235 $image_url = substr(
$url, 1, -1);
238 $image = $this->image_fetcher->getImage($image_url);
244 $uid = uniqid() .
'@elgg-image';
249 $replacement = str_replace($image_url,
"cid:{$uid}",
$url);
251 $html_text = str_replace(
$url, $replacement, $html_text);
256 $inline_image = Attachment::factory([
257 'content' => $image_data[
'data'],
258 'type' => $image_data[
'content-type'],
259 'filename' => $image_data[
'name'],
263 $message->addPart($inline_image->asInline());
288 $options[
'body'] = $this->views->renderView(
'email/elements/body',
$options);
290 $css_views = $this->views->renderView(
'elements/variables.css',
$options);
291 $css_views .= $this->views->renderView(
'email/email.css',
$options);
293 $minifier = new \MatthiasMullie\Minify\CSS($css_views);
294 $css = $minifier->minify();
298 $html = $this->views->renderView(
'email/elements/html',
$options);
300 return $this->html_formatter->inlineCss(
$html, $css);
317 $pattern =
'/\ssrc=([\'"]\S+[\'"])/i';
319 preg_match_all($pattern,
$text, $matches);
321 if (empty($matches) || !isset($matches[1])) {
326 return array_unique($matches[1]);
getLogger()
Returns logger.
if(! $user||! $user->canDelete()) $name
$attachments
Outputs attachments.
Fetch external images server side.
prepareSubject(string $subject)
Prepare the subject string.
setMessageBody(SymfonyEmail $message, Email $email)
Build the body part of the e-mail message.
makeHtmlBody(array $options=[])
Create the HTML content for use in a HTML email part.
findImages(string $text)
Find img src's in text.
__construct(protected Config $config, protected EventsService $events, protected MailerInterface $mailer, protected HtmlFormatter $html_formatter, protected ViewsService $views, protected ImageFetcherService $image_fetcher)
Constructor.
send(Email $email)
Sends an email.
addHtmlPart(SymfonyEmail $message, \Elgg\Email $email)
Add the HTML part to the e-mail message.
transport(Email $email)
Transports an email.
Exception thrown if an error which can only be found on runtime occurs.
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
$config
Advanced site settings, debugging section.
$subject
HTML body of an email.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
elgg_get_current_language()
Get the current system/user language or 'en'.
elgg_strip_tags(string $string, ?string $allowable_tags=null)
Strip tags and offer plugins the chance.
$html
A wrapper to render a section of the page shell.
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.