[SOLVED] PHP mail() - Formatting date in body..

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
determinedmoth
Forum Commoner
Posts: 33
Joined: Wed Jul 07, 2004 9:13 am

PHP mail() - Formatting date in body..

Post 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 ;)
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

determinedmoth
Forum Commoner
Posts: 33
Joined: Wed Jul 07, 2004 9:13 am

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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";
determinedmoth
Forum Commoner
Posts: 33
Joined: Wed Jul 07, 2004 9:13 am

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
determinedmoth
Forum Commoner
Posts: 33
Joined: Wed Jul 07, 2004 9:13 am

Post by determinedmoth »

I could could kiss you ;)

That worked wonderfully. Thanks!
Post Reply