Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with Date in Email Header

Ramon
Guest
 
Posts: n/a
#1: Aug 18 '06
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 <john@doe.com>
Reply-To: john@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--



Alvaro G. Vicario
Guest
 
Posts: n/a
#2: Aug 18 '06

re: Problem with Date in Email Header


*** Ramon escribió/wrote (Fri, 18 Aug 2006 19:20:38 +0200):
Quote:
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
--
Ramon
Guest
 
Posts: n/a
#3: Aug 18 '06

re: Problem with Date in Email Header


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" <webmaster@NOSPAMdemogracia.comwrote in message
news:4oxvx6x6es39$.1t1l45xsw5chj.dlg@40tude.net...
Quote:
*** Ramon escribió/wrote (Fri, 18 Aug 2006 19:20:38 +0200):
Quote:
>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
--

Alvaro G. Vicario
Guest
 
Posts: n/a
#4: Aug 18 '06

re: Problem with Date in Email Header


*** Ramon escribió/wrote (Fri, 18 Aug 2006 20:36:33 +0200):
Quote:
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
--
Ramon
Guest
 
Posts: n/a
#5: Aug 18 '06

re: Problem with Date in Email Header


By sending a mail just with: mail(xxx@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" <webmaster@NOSPAMdemogracia.comwrote in message
news:18dlyab03gdg8$.5ec8b0qk27j2.dlg@40tude.net...
Quote:
*** Ramon escribió/wrote (Fri, 18 Aug 2006 20:36:33 +0200):
Quote:
>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
--

Alvaro G. Vicario
Guest
 
Posts: n/a
#6: Aug 18 '06

re: Problem with Date in Email Header


*** Ramon escribió/wrote (Fri, 18 Aug 2006 21:02:18 +0200):
Quote:
By sending a mail just with: mail(xxx@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
--
Ramon
Guest
 
Posts: n/a
#7: Aug 18 '06

re: Problem with Date in Email Header


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" <webmaster@NOSPAMdemogracia.comwrote in message
news:jqmono3yoc8j.1r47xyv0a2dv5.dlg@40tude.net...
Quote:
*** Ramon escribió/wrote (Fri, 18 Aug 2006 21:02:18 +0200):
Quote:
>By sending a mail just with: mail(xxx@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
--

Steven Musumeche
Guest
 
Posts: n/a
#8: Aug 19 '06

re: Problem with Date in Email Header


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:
Quote:
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" <webmaster@NOSPAMdemogracia.comwrote in message
news:jqmono3yoc8j.1r47xyv0a2dv5.dlg@40tude.net...
Quote:
>*** Ramon escribió/wrote (Fri, 18 Aug 2006 21:02:18 +0200):
Quote:
>>By sending a mail just with: mail(xxx@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
>--
>
>
Closed Thread