Log in

View Full Version : show date in php submitted email



phpstarter
04-15-2010, 12:04 PM
I am having trouble showing the date in an email which is being submitted with php. I am a complete beginner with PHP so I suspect this is very basic but help would be greatly appreciated, my sendmail code is below . I would like to show the date and time the email was submitted in the body of the email.



<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['phone'] ;
$Name = $_REQUEST['name'] ;
$headers = "From: \"----.co.uk\"<noreply@----.co.uk>\r\n".
"Return-Path: <noreply@----.co.uk>\r\n".
"X-Mailer: PHP/" . phpversion();
$subject = "---- website contact request";



$fields = array();
$fields{"name"} = "name";
$fields{"company"} = "company";
$fields{"phone"} = "phone";
$fields{"creative"} = "creative";
$fields{"publicrelations"} = "publicrelations";
$fields{"digital"} = "digital";


$body = "Below is the result of your feedback form:\n\n";echo date("Y/m/d"); foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: noreply@----.co.uk";
$subject2 = "---- website contact request";


if($from == '') {print "You have not entered a phone number, please go back and try again";}
else {
if($Name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
if($send)
{header( "Location: http://www.----.co.uk/thankyou.php" );}
else
{print "We encountered an error sending your mail, please notify ----@----.co.uk"; }
}
}
?>

All help is greatly appreciated!!

phpstarter
04-15-2010, 12:18 PM
Nice, have resolved the issue....very simple in the end but for those who are interested:

Firstly declare:
$date = date ("l, F jS, Y");
$time = date ("h:i A");

To show in email body use:
$body = "Below is the result of your feedback form, Below is the result of your feedback form. It was submitted on $date at $time.:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }