Much faster email sending with the new Message Broker

This commit is contained in:
Pinga 2024-02-23 02:14:41 +02:00
parent 23d50a0b0c
commit 43e7b3250d
7 changed files with 286 additions and 174 deletions

View file

@ -60,6 +60,32 @@ class Mail
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
return false;
}
} else if (envi('MAIL_DRIVER') == 'msg') {
$url = 'http://127.0.0.1:8250';
$data = ['type' => 'sendmail', 'mailer' => 'phpmailer', 'toEmail' => $to['email'], 'subject' => $subject, 'body' => $body];
$options = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($data))
],
];
$curl = curl_init($url);
curl_setopt_array($curl, $options);
$response = curl_exec($curl);
if ($response === false) {
throw new Exception(curl_error($curl), curl_errno($curl));
}
curl_close($curl);
return true;
} else {
return true;
}

View file

@ -11,7 +11,7 @@ DB_USERNAME=root
DB_PASSWORD=
DB_PORT=3306
#mailer settings (Driver = smtp or utopia, Api Provder = sendgrid or mailgun)
#mailer settings (Driver = smtp, utopia or msg [for local message broker]; Api Provder = sendgrid or mailgun)
MAIL_DRIVER=none
MAIL_HOST=smtp.mailtrap.io