I have a website with a form. When submit the form php sends a mail to a local gateway.
php code looks like this:
$ok = @mail($emailData['to'], $emailData['subject'], $message, $emailData['headers']);
if ($ok) {
echo "<p>Message has been sent.</p>";
} else {
echo "<p>Message could not be sent!</p>";
}
So when a mail has been successfully sent, the mail.log looks like:
May 11 06:15:01 webserver postfix/qmgr[2280345]: 7B6B0600EF: from=<www-data@webserver>, size=803, nrcpt=1 (queue active)
May 11 06:15:01 webserver postfix/smtp[2573042]: 7B6B0600EF: to=<[email protected]>, relay=192.168.1.250[192.168.1.250]:26, delay=0.06, delays=0.03/0.01/0.02/0.01, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 8478AE11B4)
May 11 06:15:01 webserver postfix/qmgr[2280345]: 7B6B0600EF: removed
However, due to a technical problem, the gateway wasn't reachable and the mail.log looked like:
May 8 06:40:12 webserver postfix/qmgr[1521]: 33890607E6: from=<www-data@webserver>, size=67769, nrcpt=2 (queue active)
May 8 06:40:42 webserver postfix/smtp[1493379]: connect to 192.168.1.250[192.168.1.250]:26: Connection timed out
May 8 06:41:12 webserver postfix/smtp[1493379]: 33890607E6: to=<[email protected]>, relay=none, delay=399463, delays=399402/0.04/60/0, dsn=4.4.1, status=deferred (connect to 192.168.1.250[192.168.1.250]:26: Connection timed out)
PHP can only say if a mail has been accepted for delivery, but not say if the mail has been successfully sent. So in both cases i got the "Message has been sent"....
So I try to find a way, to let postfix at least save the mail content (with attachments) locally on its own machine (webserver) in case the gateway isn't reachable. Because otherwise the mail, respectively the form content is gone forever.
On the other hand i already furnished a way to get an info, when the gateway is not reachable from the webserver (with the help on cronjobs). But that only helps me to notice problems faster.
Any ideas?
Thanks for helping me.