Page 1 of 1

PHP mail() - Formatting date in body..

Posted: Wed Jul 07, 2004 9:13 am
by determinedmoth
Hello.. I'm a little new to PHP and I've come a bit unstuck.

I've managed to create a form that submits it's data to a MySQL database and also sends an email to a set list. Within the email I want to print the date in a D, d, Y format... the form is providing the date as a TIMESTAMP which I need for the database, so I can't just reformat that.

My email code goes as such:

Code: Select all

//Begin Email
if ((isset($_POSTї"MM_insert"])) && ($_POSTї"MM_insert"] == "add_event"))
 {

$msg = "Event added for Date:\t$date\n" ;
$msg .= "Appointment:\t$text\n";

$recipient = "xxx@xxx.co.uk";
$subject = "Week Ahead Update";

$mailheaders = "From: xxx <> \n";
$mailheaders .= "Reply-To: $xxx@xxx.co.uk\n\n";

mail($recipient, $subject, $msg, $mailheaders);

&#125;
//End Email
This works (I'm aghast I got this far), but I need to get the date in a readable format rather just 20040808041217 (TIMESTAMP) value.

Hope I've make this clear.. Any pointers would be great ;)

Posted: Wed Jul 07, 2004 9:20 am
by wwwapu

Posted: Wed Jul 07, 2004 10:07 am
by determinedmoth
wwwapu wrote:Use date() on your TIMESTAMP. http://fi2.php.net/manual/fi/function.date.php
I know what function, I'm just unsure how to actually apply it.

Code: Select all

$msg = date ("Event added for Date:\t&#1111;,int $date]\n") ;
:?

Nothing I tried worked, or just returned dates like 1970 or 2038..!

If at all... sorry. A bit new at this. :oops:

Posted: Wed Jul 07, 2004 12:16 pm
by feyd
If you had read the documentation, you'd know what to send to date..

Code: Select all

$msg = "Event added for date:\t".date('M d, Y',$time)."\n";

Posted: Thu Jul 08, 2004 6:07 am
by determinedmoth
Thanks... I should point out that I have gone through the documenation (I've tried the various examples on php.net, as well 3 books I have sat here) and I still can't get it right...

I'm sorry if you think I've not bothered.. but that's not the case :)

Anyway - what you suggested returned "Jan 01, 1970" - as many other of my atempts. I think the root of the problem must lay elsewhere.

Posted: Thu Jul 08, 2004 6:19 am
by markl999

Code: Select all

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add_event"))
{
    $year = substr($date, 0, 4);
    $month = substr($date, 4, 2);
    $day = substr($date, 6, 2);
    $nicedate = date('M d, Y', mktime(0, 0, 0, $month, $day, $year));
    //rest of your email stuff below
Then just use $nicedate in your email.

Posted: Thu Jul 08, 2004 6:26 am
by determinedmoth
I could could kiss you ;)

That worked wonderfully. Thanks!