Results 1 to 2 of 2

Thread: show date in php submitted email

  1. #1
    Join Date
    Apr 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default show date in php submitted email

    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.

    Code:
    <?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!!

  2. #2
    Join Date
    Apr 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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]); }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •