Skip to content

Commit

Permalink
fix: Fix email send
Browse files Browse the repository at this point in the history
  • Loading branch information
famoser committed Dec 1, 2024
1 parent c516167 commit 18dae34
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 29 deletions.
14 changes: 2 additions & 12 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused services; this also means
bind:
$contactEmail: '%env(CONTACT_EMAIL)%'
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.

Expand All @@ -24,18 +26,6 @@ services:
resource: '../src/Controller'
tags: ['controller.service_arguments']

App\Service\ExchangeService:
arguments: ["@translator", "@session.flash_bag", "@validator", "@doctrine"]

App\Service\EventPastEvaluationService:
arguments: ["@doctrine"]

App\Service\EventGenerationService:
arguments: ["@doctrine","@translator","@session"]

App\Service\EmailService:
arguments: ["@mailer", "@doctrine", "@logger","@twig","%env(CONTACT_EMAIL)%"]

App\Normalizer\EntityNormalizer:
public: false
autowire: true
Expand Down
12 changes: 3 additions & 9 deletions src/Service/EmailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,13 @@ class EmailService implements EmailServiceInterface
*/
private $doctrine;

/**
* @var Environment
*/
private $twig;

/**
* EmailService constructor.
*/
public function __construct(MailerInterface $mailer, ManagerRegistry $registry, Environment $twig, string $contactEmail)
public function __construct(MailerInterface $mailer, ManagerRegistry $registry, string $contactEmail)
{
$this->mailer = $mailer;
$this->doctrine = $registry;
$this->twig = $twig;
$this->contactEmail = $contactEmail;
}

Expand All @@ -64,7 +58,7 @@ private function processEmail(Email $email)

$message = (new TemplatedEmail())
->subject($email->getSubject())
->replyTo($this->contactEmail)
->from($this->contactEmail)
->to($email->getReceiver());

$body = $email->getBody();
Expand All @@ -75,7 +69,7 @@ private function processEmail(Email $email)

if (EmailType::PLAIN_EMAIL !== $email->getEmailType()) {
$message->htmlTemplate('email/view.html.twig')
->context(['email' => $email]);
->context(['content' => $email]);
}

foreach ($email->getCarbonCopyArray() as $item) {
Expand Down
16 changes: 8 additions & 8 deletions templates/email/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta name="viewport" content="width=device-width"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>{{ email.subject }}</title>
<title>{{ content.subject }}</title>
<style>
/* -------------------------------------
GLOBAL RESETS
Expand Down Expand Up @@ -350,7 +350,7 @@
<div class="content">

<!-- START CENTERED WHITE CONTAINER -->
<span class="preheader">{{ email.subject }}</span>
<span class="preheader">{{ content.subject }}</span>
<table class="main">

<!-- START MAIN CONTENT AREA -->
Expand All @@ -359,8 +359,8 @@
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<p>{{ email.body|nl2br }}</p>
{% if email.actionLink != null %}
<p>{{ content.body|nl2br }}</p>
{% if content.actionLink != null %}
<table border="0" cellpadding="0" cellspacing="0" class="btn btn-primary">
<tbody>
<tr>
Expand All @@ -369,8 +369,8 @@
<tbody>
<tr>
<td>
<a href="{{ email.actionLink }}" target="_blank">
{{ email.actionText }}
<a href="{{ content.actionLink }}" target="_blank">
{{ content.actionText }}
</a>
</td>
</tr>
Expand All @@ -396,7 +396,7 @@
<tr>

<td class="content-block">
<a href="{{ absolute_url(path("email_view", {"identifier" : email.identifier })) }}">
<a href="{{ absolute_url(path("email_view", {"identifier" : content.identifier })) }}">
{{ "mail_wrong_displayed"|trans }}
</a> <br/>
{{ "generated"|trans }} <br/>
Expand All @@ -414,4 +414,4 @@
</tr>
</table>
</body>
</html>
</html>

0 comments on commit 18dae34

Please sign in to comment.