PDA

View Full Version : Posting the time stamp in the email


monraga
12-18-2007, 12:13 AM
I need to display a timestamp in an email.

Using sendmail to send out the email. Found a perl script to "supposedly" display the date and time. Only problem, all that displays in the email is a "1" rather than the date and time. Here's what I have so far.

Function to get the date and time

#function to print date and time
sub print_date_time
{
$date = time;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime ($date);
$mon++;
if ($min < 10) { $min = "0$min"; }
if ($sec < 10) { $sec = "0$sec"; }
if ($mday < 10) { $min = "0$mday"; }
printf "<dl><dd><i>Received: %d:%s:%s %d/%s/%d</i></dl>\n", $hour, $min, $sec, $mon, $mday, $year;
}


Capture the date and time with...
$date_time = &print_date_time ();

Display the results in an email...

open ( MAIL, "| /usr/lib/sendmail -t" );
print MAIL "From: $email_address\n";
print MAIL "To: corp-support\@oqo.com \n";
print MAIL "CC: $email_address \n";
print MAIL "REPLY-TO: $email_address \n";
print MAIL "Subject: RMA Form Submission\n\n";
print MAIL "Hi $firstname $lastname, \n \n";
print MAIL "Thank you for your RMA submission. The details of your submission are as follows. \n\n";
print MAIL "$date_time";
print MAIL "\n";


I can't get it to display in the email, all that displays is a 1, help anyone? :confused:

bazz
12-18-2007, 01:07 AM
can you show me a written example of what date or time data you want to put in the email eg 2007-12-29 23:30:59

I have got such data already ouotputting and I shall be inclding in an email tomorrow so i can send you the code then.

this might help in the meantime:

my $dateStamp = strftime("%Y-%m-%d %H:%M:%S", localtime));


bazz

KevinADC
12-18-2007, 04:52 AM
you have to load the POSIX module and import the strftime() function to use Bazz's suggestion:

use POSIX qw/strftime/;

KevinADC
12-18-2007, 04:58 AM
Change the last line of the sub routine to this:

return sprintf "<dl><dd><i>Received: %d:%s:%s %d/%s/%d</i></dl>\n", $hour, $min, $sec, $mon, $mday, $year;