Mailing PHP time stamp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
comicrebel
Forum Newbie
Posts: 3
Joined: Thu Nov 01, 2007 1:31 pm

Mailing PHP time stamp

Post 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]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Arrives as a string?
I'm not sure what you mean.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
comicrebel
Forum Newbie
Posts: 3
Joined: Thu Nov 01, 2007 1:31 pm

Post 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]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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']}";
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
comicrebel
Forum Newbie
Posts: 3
Joined: Thu Nov 01, 2007 1:31 pm

Post 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]
Post Reply