Page 1 of 1

Mailing PHP time stamp

Posted: Thu Nov 01, 2007 1:58 pm
by comicrebel
scottayy | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[color=red]***** PLEASE ENABLE BBCODE AND USE IT WHEN POSTING CODE *****[/color]

I am trying to send date and time stamp info from server, but it arrives as a string. I have tried different syntax but can't figure this out. The $_SERVER['REMOTE_ADDR' does send the IP address. What am I missing?

Code: Select all

//Send email to email address
$to = "email@email.com";
$subject = "SUBJECT";
$message = "Date: date('l, F jS, Y') \nTime: Web Server Time: date('g:i:s A')\nIP address: {$_SERVER['REMOTE_ADDR']}";
	$from = "email@email.com";
	$headers = "From: $from";
	mail($to,$subject,$message,$headers);

scottayy | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Nov 01, 2007 4:43 pm
by s.dot
Arrives as a string?
I'm not sure what you mean.

Posted: Thu Nov 01, 2007 6:18 pm
by comicrebel
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Sorry I was not more clear...

This is a script that sends an email with date info from the server and IP address. The script does send the IP address of the remote host, but not the data and time. There is some syntax problem in the $message line.

Test it at: http://www.tim-richardson.com/technical/win-test.php This page sends me an email with your IP address and (trying to get it to send) server date and time. This is for a weekly contest.

Code: Select all

//Send email to tim to address
$to = "tim@tim-richardson.com";
$subject = "Tech Tip of the Week CONTEST!";
$message = "Date: date('l, F jS, Y') \nTime: Web Server Time: date('g:i:s A')\nIP address: {$_SERVER['REMOTE_ADDR']}";
	$from = "tim@tim-richardson.com";
	$headers = "From: $from";
	mail($to,$subject,$message,$headers);
What I actually receive is this:

Date: date('l, F jS, Y')
Time: Web Server Time: date('g:i:s A')
IP address: 209.188.123.53

What I want to receive is this:

Date: Thursday, November 1st, 2007
Time: Web Server Time = 4:14:29 PM
IP address: 209.188.123.53


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Nov 01, 2007 6:30 pm
by s.dot
You should concatenate it in.

Code: Select all

$message = "Date: " . date('l, F jS, Y') . "\nTime: Web Server Time: " . date('g:i:s A') . "\nIP address: {$_SERVER['REMOTE_ADDR']}";

Posted: Thu Nov 01, 2007 7:36 pm
by comicrebel
Great! Thank you for your help. I tried everything combination of concatenation and quoting I thought! That works. ..and of course I have another question. Why is this sending two duplicate messages?

***** PLEASE USE THE PHP TAG WHEN POSTING CODE *****
(highlight the code and click the PHP button above the textarea)

Code: Select all

/Send email to tim to address
$to = "tim@tim-richardson.com";
$subject = "Tech Tip of the Week CONTEST!";
$message = "Date: " . date('l, F jS, Y') . "\nTime: Web Server Time: " . date('g:i:s A') . "\nIP address: {$_SERVER['REMOTE_ADDR']}";
	$from = "tim@tim-richardson.com";
	$headers = "From: $from";
	mail($to,$subject,$message,$headers);
Thank you for your help!
Tim R[/syntax]