469,287 Members | 2,705 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,287 developers. It's quick & easy.

Problem with Date in Email Header

Hello,

when I send an email using the mail() function, I get a Runtime Notice:

date() [function.date]: It is not safe to rely on the system's timezone
settings. Please use the date.timezone setting, the TZ environment variable
or the date_default_timezone_set() function. In case you used any of those
methods and you are still getting this warning, you most likely misspelled
the timezone identifier. We selected 'Europe/Paris' for '2.0/DST' instead.

I found out that this is caused by the date-part in the header. But I can't
find what's wrong with it.

I hope you can help me out!

Thanks,
Ramon.
This is a snippet of my script:

$sBoundary = md5(mt_rand());
$sHeaders = "Date: $sTimestamp\n" .
"From: $sMailFrom\r\n" .
"Reply-To: " . $GLOBALS ["Email"]["ReplyToAddress"]
.. "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/alternative; ".
"boundary=$sBoundary\r\n\r\n" .
"This is a multi-part message in MIME
format.\r\n\r\n";

$sBody = "--$sBoundary\n" .
"Content-Type: text/plain;
charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$this->m_sTextBody . "\n\n" .
"--$sBoundary\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n"
..
"Content-Transfer-Encoding: 7bit\n\n" .
$this->m_sHTMLBody . "\n\n" .
"--$sBoundary--";

$this->m_bSendResult = mail($this->m_sToMail, $this->m_sSubject,
$sBody, $sHeaders);
And this is the ouput:

Date: Fri, 18 Aug 2006 19:06:00 +0200
From: John Doe <jo**@doe.com>
Reply-To: jo**@doe.com
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary=4ecaa221dc319a2ce4905365efe5e550

This is a multi-part message in MIME format.

--4ecaa221dc319a2ce4905365efe5e550
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

This is some plain text.

--4ecaa221dc319a2ce4905365efe5e550
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<html><body><b>This is some <i>HTML</itext.</b></body></html>

--4ecaa221dc319a2ce4905365efe5e550--
Aug 18 '06 #1
7 13627
*** Ramon escribió/wrote (Fri, 18 Aug 2006 19:20:38 +0200):
date() [function.date]: It is not safe to rely on the system's timezone
settings. Please use the date.timezone setting, the TZ environment variable
or the date_default_timezone_set() function. In case you used any of those
methods and you are still getting this warning, you most likely misspelled
the timezone identifier. We selected 'Europe/Paris' for '2.0/DST' instead.

I found out that this is caused by the date-part in the header. But I can't
find what's wrong with it.
Where do you call date()? I can't find it in your code :-? The $sTimestamp
variable is already there...

Also, I'm curious about why you need to specify a "Date" header.

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Aug 18 '06 #2
Hello Alvaro,

The variable was outside the piece of code:
$sTimestamp = date("r");

I do this because otherwise I get the error message I wrote. I tested it by
copying a date from an email I sent with Outlook Express. Using that (hard
coded) date, it worked fine. But when I use the Timestamp variable (which
uses the same notation), it doesn't work. So I think I'm missing something
here, but I can't find out what...
Ramon.

"Alvaro G. Vicario" <we*******@NOSPAMdemogracia.comwrote in message
news:4o*****************************@40tude.net...
*** Ramon escribió/wrote (Fri, 18 Aug 2006 19:20:38 +0200):
>date() [function.date]: It is not safe to rely on the system's timezone
settings. Please use the date.timezone setting, the TZ environment
variable
or the date_default_timezone_set() function. In case you used any of
those
methods and you are still getting this warning, you most likely
misspelled
the timezone identifier. We selected 'Europe/Paris' for '2.0/DST'
instead.

I found out that this is caused by the date-part in the header. But I
can't
find what's wrong with it.

Where do you call date()? I can't find it in your code :-? The $sTimestamp
variable is already there...

Also, I'm curious about why you need to specify a "Date" header.

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--

Aug 18 '06 #3
*** Ramon escribió/wrote (Fri, 18 Aug 2006 20:36:33 +0200):
The variable was outside the piece of code:
$sTimestamp = date("r");

I do this because otherwise I get the error message I wrote.
You don't need to specify date headers, sendmail or whatever software
performs the actual delivery takes care about such details.

Do you get the same error message with, let's say, a one-liner sample code?
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Aug 18 '06 #4
By sending a mail just with: mail(xx*@yyy.zzz, "test mail"), it goes fine.
But I need to send a html-mail, and then you have to specify the headers.
I have to use the php "mail()" function because I can't install additional
software on the server.

"Alvaro G. Vicario" <we*******@NOSPAMdemogracia.comwrote in message
news:18*****************************@40tude.net...
*** Ramon escribió/wrote (Fri, 18 Aug 2006 20:36:33 +0200):
>The variable was outside the piece of code:
$sTimestamp = date("r");

I do this because otherwise I get the error message I wrote.

You don't need to specify date headers, sendmail or whatever software
performs the actual delivery takes care about such details.

Do you get the same error message with, let's say, a one-liner sample
code?
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--

Aug 18 '06 #5
*** Ramon escribió/wrote (Fri, 18 Aug 2006 21:02:18 +0200):
By sending a mail just with: mail(xx*@yyy.zzz, "test mail"), it goes fine.
But I need to send a html-mail, and then you have to specify the headers.
Yes, but not *all* headers, only additional ones.

Sorry, I'm lost. I can't figure our where that error message comes from. It
doesn't have the typical format of PHP messages... BTW, I presume you
followed its instructions and didn't work, didn't your?
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Aug 18 '06 #6
Guess what,
I found the problem in the PHP documentation:

"Since PHP 5.1.0 (when the date/time functions were rewritten), every call
to a date/time function will generate a E_NOTICE if the timezone isn't
valid, and/or a E_STRICT message if using the system settings or the TZ
environment variable."

So, I added the function: date_default_timezone_set ("Europe/Amsterdam");
and the problems were gone...

Thanks Alvaro,
for your efforts!

"Alvaro G. Vicario" <we*******@NOSPAMdemogracia.comwrote in message
news:jq****************************@40tude.net...
*** Ramon escribió/wrote (Fri, 18 Aug 2006 21:02:18 +0200):
>By sending a mail just with: mail(xx*@yyy.zzz, "test mail"), it goes
fine.
But I need to send a html-mail, and then you have to specify the headers.

Yes, but not *all* headers, only additional ones.

Sorry, I'm lost. I can't figure our where that error message comes from.
It
doesn't have the typical format of PHP messages... BTW, I presume you
followed its instructions and didn't work, didn't your?
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--

Aug 18 '06 #7
You don't have to set the date to send an HTML email. Just specify the
headers that you want to change, and let sendmail handle the others(like
Date).

-Steven

Ramon wrote:
Guess what,
I found the problem in the PHP documentation:

"Since PHP 5.1.0 (when the date/time functions were rewritten), every call
to a date/time function will generate a E_NOTICE if the timezone isn't
valid, and/or a E_STRICT message if using the system settings or the TZ
environment variable."

So, I added the function: date_default_timezone_set ("Europe/Amsterdam");
and the problems were gone...

Thanks Alvaro,
for your efforts!

"Alvaro G. Vicario" <we*******@NOSPAMdemogracia.comwrote in message
news:jq****************************@40tude.net...
>*** Ramon escribió/wrote (Fri, 18 Aug 2006 21:02:18 +0200):
>>By sending a mail just with: mail(xx*@yyy.zzz, "test mail"), it goes
fine.
But I need to send a html-mail, and then you have to specify the headers.
Yes, but not *all* headers, only additional ones.

Sorry, I'm lost. I can't figure our where that error message comes from.
It
doesn't have the typical format of PHP messages... BTW, I presume you
followed its instructions and didn't work, didn't your?
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--

Aug 19 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Marauderz | last post: by
reply views Thread by Rafal Zawadzki | last post: by
7 posts views Thread by Kamal | last post: by
2 posts views Thread by swethak | last post: by
11 posts views Thread by jessy | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.