Is the clock on your server correct?

If not, complain to the sysadmin.

All servers should have correct clocks. RFC822 dates have time zone information in, hence are fine regardless of what time zone you use, provided your clock is right.

I believe that all servers should use UTC as their system time zone (mainly because of scheduling of "cron" jobs etc is then easier, no daylight saving time like e.g. Europe/London), however your application is free to use whatever it wants (different on a per user basis, if you like).

Mark

    The clock is correct on the server, I administer the servers. The time zone is also correct, PHP produces the correct date with the date() function but not with the mail() function. I'm at a loss as to why it's doing this.

      Your MTA should be adding the "Date:" header. It should contain the correct time provided the server clock is correct.

      Are you sure the server clock is right and you don't have it with the right time in the wrong time zone? Is it synchronised with a NTP time source on the internet?

      If you send a message from the command line in the shell, does it have the right date/time on it?

      Mark

        The server clock is set correctly in the Date and Time control panel, to GMT +10:00. I just enabled the Windows Time Service in group policy, but that only means the PDC will sync the time with computers on the domain, I wasn't table to telnet time.windows.com on port 123 due to our firewall.

        How do you mean sending a message from the shell, do you mean opening a telnet session with the smtp server?

          boatmas wrote:

          do you mean opening a telnet session with the smtp server?

          That would be a good way to check what the SMTP server has for time. Telnet into the server on port 25 and you should see a greeting that may have the time included. Here's the greeting I get from my SMTP server:

          220 broadbandsupport.net ESMTP ecelerity 2.1.1.14.1 r(15310M) Wed, 20 Jun 2007 03:19:39 -0400

          EDIT: Funny... a minute or two ago my SMTP server's clock was off by a good 22 minutes. Didn't notice it until posting this, so I went back in and then it showed the correct time. Perplexed, I logged out and then opened another connection. Ype - 22 minutes behind. :glare:

            By "Your server", I meant your SMTP relay server.

            Log on to the shell of your SMTP relay, check its clock. Try sending a message locally from the shell (command line in Unix, on Win32, good luck!).

            The "Date" header is probably added by your MTA on the mail server, not PHP.

            Mark

              Opening a telnet connection only returned "220 <server> ESMTP Postfix."

              I connected to the SMTP in Python and here are the responses:

              headers = "From: <From>\r\n"
              headers += "To: <To>\r\n"
              headers += "Subject: SMTP Test\r\n\r\n"
              import smtplib
              server = smtplib.SMTP("smtp.server.com")
              server.set_debuglevel(True)
              server.sendmail('<From>', '<To>', headers+"Test")
              send: 'ehlo my-hostname.local\r\n'
              reply: '250-mail.other.server.com\r\n'
              reply: '250-PIPELINING\r\n'
              reply: '250-SIZE 10240000\r\n'
              reply: '250-ETRN\r\n'
              reply: '250-STARTTLS\r\n'
              reply: '250-ENHANCEDSTATUSCODES\r\n'
              reply: '250-8BITMIME\r\n'
              reply: '250 DSN\r\n'
              reply: retcode (250); Msg: mail.other.server.com
              PIPELINING
              SIZE 10240000
              ETRN
              STARTTLS
              ENHANCEDSTATUSCODES
              8BITMIME
              DSN
              send: 'mail FROM:<From> size=110\r\n'
              reply: '250 2.1.0 Ok\r\n'
              reply: retcode (250); Msg: 2.1.0 Ok
              send: 'rcpt TO:<To>\r\n'
              reply: '250 2.1.5 Ok\r\n'
              reply: retcode (250); Msg: 2.1.5 Ok
              send: 'data\r\n'
              reply: '354 End data with <CR><LF>.<CR><LF>\r\n'
              reply: retcode (354); Msg: End data with <CR><LF>.<CR><LF>
              data: (354, 'End data with <CR><LF>.<CR><LF>')
              send: 'From: <From>\r\nTo: <To>\r\nSubject: SMTP Test\r\n\r\nTest\r\n.\r\n'
              reply: '250 2.0.0 Ok: queued as 1EB2C3C003\r\n'
              reply: retcode (250); Msg: 2.0.0 Ok: queued as 1EB2C3C003
              data: (250, '2.0.0 Ok: queued as 1EB2C3C003')
              {}
              server.quit()
              send: 'quit\r\n'
              reply: '221 2.0.0 Bye\r\n'
              reply: retcode (221); Msg: 2.0.0 Bye

              It appears the MTA is adding the "Date" header, perhaps PHP is adding an incorrect Date header then? Is there any way to see debug output in PHP?

              Using PHP on my local OS X machine and Postfix, it seems as though PHP does add the Date header from the tcpdump. The correct Date header was also added.

                There are lots of ways to see the output.

                Consider using a traffic analyser (Wireshark, for instance) to intercept the message to the mail server.

                I assume you are sure that the clock on both your web server AND your mail server is correct (and has the right time zone)?

                Log on to your SMTP server to check the system time - ensure it's right (alternatively, maybe you don't have access - ask the sysadmin instead).

                Mark

                  I'm fairly sure the time on the mail server is correct, it's used tens of thousands of times a day.

                  PHP does actually apply the Date header itself, as below:

                  Message: Date: Mon, 25 Jun 2007 10:57:05 \3041000\r\n

                  I've identified the problem, instead of adding +1000, it adds \xc41000 (bytes: c4 31 30 30 30). When adding the Date header manually it works as +1000 (bytes: 2b 31 30 30 30).

                  This does seem like odd behaviour.

                    The time on the SMTP server is most likely correct, it's used tens of thousands of times a day.

                    PHP does in fact apply a Date header when using the mail() function:

                    Message: Date: Mon, 25 Jun 2007 10:57:05 \3041000\r\n

                    I've identified the probiem, instead of adding +1000, it adds \xc41000 (bytes: c4 31 30 30 30). When adding the Date header manually it works as +1000 (bytes: 2b 31 30 30 30) is used.

                    This is odd behaviour.

                      Upgrading from PHP 4.4.4 to 4.4.7 solved this issue. Thanks for the replies.

                        Write a Reply...