I’m encountering an issue with a shop website using Merx, but I don’t believe this is an error related to the Merx plugin, hence I’m posting it in the general forum. The site is running on localhost but should be going live soon.
There’s a function in my config.php
to send automated e-mails whenever the ww.merx.completePayment:after
hook is fired:
// config.php
$dotenv = new \Dotenv\Dotenv(__DIR__ . '/../..');
$dotenv->load();
// Login credentials etc saved at root in an .env file => i.e $_ENV['EMAIL_HOST'],
if (!function_exists('sendConfirmationMail')) {
function sendConfirmationMail($orderPage, $urlWithHash) {
try {
kirby()->email([
'from' => 'test@example.com',
'to' => (string)$orderPage->email(),
'subject' => 'Thanks for your order!',
'body'=> 'Dear ' . $orderPage->name() . ', you paid ' . formatPrice($orderPage->cart()->getSum()) . '. Order summary: ' . $urlWithHash,
]);
kirby()->email([
'from' => 'test@example.com',
'to' => 'notifications@example.com',
'subject' => 'New Order',
'body' => 'You have outstanding orders. Please check the panel: ' . kirby()->site()->url() . '/panel'
]);
} catch(Exception $error) {
echo $error;
}
}
};
return [
// other stuff
'hooks' => [
'ww.merx.completePayment:after' => function ($orderPage) {
$hash = bin2hex(random_bytes(16));
$urlWithHash = url($orderPage->url(), ['params' => ['q' => $hash]]);
$orderPage->update([
'hash' => $hash,
]);
sendConfirmationMail($orderPage, $urlWithHash);
go($urlWithHash);
},
],
'email' => [
'transport' => [
'type' => 'smtp',
'host' => $_ENV['EMAIL_HOST'],
'port' => $_ENV['EMAIL_PORT'],
'security' => true,
'auth' => true,
'username' => $_ENV['EMAIL_USER'],
'password' => $_ENV['EMAIL_PASS'],
]
],
]
Whenever I complete a payment now (whenever the hook is called), the server gets stuck in an endless loading, resulting in a 504 gateway timeout.
The weird thing is that everything has already been tested and working correctly up until the day before yesterday, and I don’t think I’ve made any substantial changes to the file.
Without specifying email transport configuration, everything runs correctly, but emails never arrive, which leads me to believe that there must be something wrong in that part – but I have no clue where to start debugging. If the mail server is down, for example, shouldn’t there be some sort of error message thrown? Appreciate any hints or ideas…