0

Here is my problem. I have a php form that is sent to an email address. Everything works great however the format of the date is yyyy-mm-dd. I would like to have the date be, Month DD, YYYY. What do I need to change in my code to get this to work?

<?php
$errors = '';
$myemail = 'email@email.com'; // <-----Put Your email address here.
if (empty($_POST['date']) || empty($_POST['song3']) || 
    empty($_POST['song2']) || empty($_POST['song1'])) {
    $errors .= "\n Error: all fields are required"; 
}

$date = $_POST['date'];  
$song3 = $_POST['song3'];  
$song2 = $_POST['song2'];  
$song1 = $_POST['song1']; 

if (empty($errors)) {
    $to = $myemail;     
    $email_subject = "Hot 3 at 3- $date";   
    $email_body = "Here is today's Hot 3 at 3.\n\n\n" . "3. $song3 \n\n2. $song2 \n\n1. $song1";
    $headers = "From: KLIA-FM\n";
    $headers .= "Reply-To: $email_address";     
    mail($to, $email_subject, $email_body, $headers); // redirect to the 'thank you' page   
    header('Location: thank-you.html'); 
}  
?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html> 
<head>  
    <title>Contactform handler</title>
</head>

<body> <!-- This page is displayed only if there is some error -->
    <?php echo nl2br($errors); ?>
</body> 
</html>
Bizley
  • 17,392
  • 5
  • 49
  • 59
  • 2
    Possible duplicate of [How to convert a date from yyyy-mm-dd to Month(in words) day year?](http://stackoverflow.com/questions/28228874/how-to-convert-a-date-from-yyyy-mm-dd-to-monthin-words-day-year) – Dave Oct 11 '16 at 06:31

2 Answers2

0

Change this from:

 $date = $_POST['date'];

To:

$date = date('F d, Y', strtotime($_POST['date']));

Here read below, all the formats:

http://www.w3schools.com/php/func_date_date.asp

Kinshuk Lahiri
  • 1,468
  • 10
  • 23
0

Try this,

$date = date_create($date);
$date = date_format($date,"F,d,Y");
Dave
  • 3,073
  • 7
  • 20
  • 33