send email v1
This commit is contained in:
parent
fe4df9cbd3
commit
afd3df123f
9 changed files with 258 additions and 63 deletions
|
|
@ -1,35 +1,43 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'pattern' => '/send-newsletter.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$jsonRequest = file_get_contents("php://input");
|
||||
$data = json_decode($jsonRequest);
|
||||
'pattern' => '/send-newsletter.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$jsonRequest = file_get_contents("php://input");
|
||||
$data = json_decode($jsonRequest);
|
||||
|
||||
$kirby = kirby();
|
||||
$kirby = kirby();
|
||||
$emailPage = page("inscription")->childrenAndDrafts()->find($data->pageUri);
|
||||
|
||||
$emailPage = page($data->uri);
|
||||
$content = $emailPage->content()->kt();
|
||||
|
||||
try {
|
||||
$to = $data->isTest ? $kirby->users() : page("inscription")->subscribers()->toStructure()->pluck("email", true, true);
|
||||
$subject = $data->isTest ? "[TEST] - " . (string) $emailPage->title() : (string) $emailPage->title();
|
||||
|
||||
try {
|
||||
if ($kirby->email([
|
||||
'from' => "info@actuel-inactuel.fr",
|
||||
'to' => page("inscription")->toStructure()->pluck("email"),
|
||||
'subject' => $data->subject,
|
||||
'body' => [
|
||||
"html" => $emailPage->content()
|
||||
],
|
||||
'to' => $to,
|
||||
'cc' => 'contact@adrien-payet.fr',
|
||||
'subject' => $subject,
|
||||
'template' => 'newsletter',
|
||||
'data' => [
|
||||
"body" => $emailPage->body()
|
||||
]
|
||||
])->isSent()) {
|
||||
return json_encode(['status' => 'success', 'message' => 'Email envoyé avec succès.']);
|
||||
$emailPage->changeStatus("listed");
|
||||
return json_encode([
|
||||
'status' => 'success',
|
||||
'message' =>
|
||||
'Email envoyé avec succès.'
|
||||
]);
|
||||
} else {
|
||||
return json_encode([
|
||||
"status" => "error",
|
||||
"message" => "Erreur lors de l'envoi de l'email.",
|
||||
]);
|
||||
}
|
||||
} catch (Exception $error) {
|
||||
return json_encode(['status' => 'error', 'message' => $error->getMessage()]);
|
||||
}
|
||||
}
|
||||
} catch (Exception $error) {
|
||||
return json_encode(['status' => 'error', 'message' => $error->getMessage()]);
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue