0

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.

2 Answers 2

1

You need some background about the mail infrastructure. Against common belief, an e-mail is not instantaneous. The error message above (deferred) is a good example: this is a temporary failure - and in such a case, any mailsystem will try again until the queue lifetime is up (which can be a matter of days!). One example where you would see such an error is greylisting.

This means that there is no way of getting a final result at that moment of time - if you want the final result, you need to watch your inbox for bounce messages. Whenever a final error is met (for example a non-existing domain inside the To field), a bounce message from the mailer-daemon is generated - and that is your result.

7
  • Thank you for your comment. It would be ok for me, if the php side always tells the web user that the mail has been sent. But after the gateway came up again, postfix didn't send the old messages and they were totally gone. that's what i want to avoid. At least I want to save the mail locally, when the mail can't be sent to the gateway. A kind of error handling with postfix if you want.... Commented May 13 at 7:25
  • That is a misconfiguration of your postfix - maybe a queue lifetime set to short. If configured correctly, postfix will try again, and should sent the message once the target is back online again...
    – Martin
    Commented May 13 at 7:32
  • The other way would be, to tell php to also save a local copy of the mail in form of a simple textfile and the attachement (which are only pdf). But if not neccessary I would first try other solutions Commented May 13 at 7:32
  • please review your postfix configuration... the scenario above should never happen!
    – Martin
    Commented May 13 at 7:33
  • Here is what happened exactly: Got a totally firewall crash and we needed to shut down multiple servers and services and boot them up again and reconfigure them. So the gateway changed, but we forgot to change the relayhost setting for postfix on the webserver. So the webserver couldn't send emails for about a whole month until we noticed that. So all generated mails from the PHP website were gone. Neither in the postfix main.cf nor in the master.cf I could find a parameter like "bounce_queue_lifetime". You want me to post the config? Commented May 13 at 7:42
0

The deferred status already means the message is queued and will be retried, by default it will attempt to deliver it for approx. 1 week. Then it will give up and send a non-delivery notification to the envelope sender.

You don't have to do anything.

You may view the queue with postqueue -p, and order it to schedule immediate delivery attempt with postqueue -i deferred.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .