wip
This commit is contained in:
1 parent
9e1bc40d9f
commit
3806df2a00
4 files changed
+43
-23
No files matched your search
@@ -6,6 +6,7 @@ use App\Jobs\SendNewsletterJob;
|
|||||||
use App\Models\MailAdressen;
|
use App\Models\MailAdressen;
|
||||||
use App\Models\MailGruppen;
|
use App\Models\MailGruppen;
|
||||||
use App\Models\MailVorlage;
|
use App\Models\MailVorlage;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
|
||||||
class SendNewsletter
|
class SendNewsletter
|
||||||
{
|
{
|
||||||
@@ -57,27 +58,46 @@ class SendNewsletter
|
|||||||
// "first_name" => "Hermann"
|
// "first_name" => "Hermann"
|
||||||
// "last_name" => "Telser"
|
// "last_name" => "Telser"
|
||||||
|
|
||||||
foreach ($adressen as $mail_data) {
|
$mails_send = 0;
|
||||||
|
|
||||||
$mail_data->subjekt = $template->subjekt;
|
foreach ($adressen as $adresse) {
|
||||||
$mail_data->email = $template->email;
|
|
||||||
$mail_data->absender_name = $gruppe->absender_name;
|
|
||||||
$mail_data->absender_mail = $gruppe->absender_mail;
|
|
||||||
|
|
||||||
if ($mail_data->anrede == 'Höflich') {
|
$data = [];
|
||||||
if ($mail_data->gender) {
|
$data['subjekt'] = $template->subjekt;
|
||||||
$anrede = 'Sehr geehrte Frau '.$mail_data->last_name;
|
$data['email'] = $adresse->email;
|
||||||
|
$data['absender_name'] = $gruppe->absender_name;
|
||||||
|
$data['absender_email'] = $gruppe->absender_mail;
|
||||||
|
|
||||||
|
if ($adresse->anrede == 'Höflich') {
|
||||||
|
if ($adresse->gender) {
|
||||||
|
$anrede = 'Sehr geehrte Frau '.$adresse->last_name;
|
||||||
} else {
|
} else {
|
||||||
$anrede = 'Sehr geehrter Herr '.$mail_data->last_name;
|
$anrede = 'Sehr geehrter Herr '.$adresse->last_name;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$anrede = 'Hallo '.$mail_data->first_name;
|
$anrede = 'Hallo '.$adresse->first_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mail_data->inhalt = str_replace('###anrede###', $anrede, $template->inhalt);
|
$data['inhalt'] = str_replace('###anrede###', $anrede, $template->inhalt);
|
||||||
|
|
||||||
SendNewsletterJob::dispatch($mail_data);
|
SendNewsletterJob::dispatch($data);
|
||||||
|
|
||||||
|
$mails_send++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($mails_send == 1) {
|
||||||
|
$text = 'Der Newsletter wurde an einem Empfänger versandt';
|
||||||
|
} elseif ($mails_send > 1) {
|
||||||
|
$text = 'Der Newsletter wurde an '.$mails_send.' Empfänger versandt';
|
||||||
|
} else {
|
||||||
|
$text = 'Der Newsletter wurde nicht verschickt';
|
||||||
|
}
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title('Newsletter')
|
||||||
|
->success()
|
||||||
|
->icon('heroicon-o-exclamation-triangle')
|
||||||
|
->body($text)
|
||||||
|
->send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,14 +11,14 @@ class SendNewsletterJob implements ShouldQueue
|
|||||||
{
|
{
|
||||||
use Queueable;
|
use Queueable;
|
||||||
|
|
||||||
public $mail_data;
|
public $data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*/
|
*/
|
||||||
public function __construct($mail_data)
|
public function __construct($data)
|
||||||
{
|
{
|
||||||
$this->mail_data = $mail_data;
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,6 +26,6 @@ class SendNewsletterJob implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
Mail::to($this->mail_data->email)->send(new Newsletter($this->mail_data));
|
Mail::to($this->data['email'])->send(new Newsletter($this->data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,14 +13,14 @@ class Newsletter extends Mailable
|
|||||||
{
|
{
|
||||||
use Queueable, SerializesModels;
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
public $mail_data;
|
public $data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new message instance.
|
* Create a new message instance.
|
||||||
*/
|
*/
|
||||||
public function __construct($mail_data)
|
public function __construct($data)
|
||||||
{
|
{
|
||||||
$this->mail_data = $mail_data;
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,8 +29,8 @@ class Newsletter extends Mailable
|
|||||||
public function envelope(): Envelope
|
public function envelope(): Envelope
|
||||||
{
|
{
|
||||||
return new Envelope(
|
return new Envelope(
|
||||||
from: new Address($this->mail_data->absender_email, $this->mail_data->absender_name),
|
from: new Address($this->data['absender_email'], $this->data['absender_name']),
|
||||||
subject: $this->mail_data->subjekt,
|
subject: $this->data['subjekt'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>{{ $this->mail_data->subjekt }}</title>
|
<title>{{ $data['subjekt'] }}</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="message">
|
<div class="message">
|
||||||
{{ $this->mail_data->inhalt }}
|
{{ $data['inhalt'] }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in new issue
Block a user