The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

Adding date to contact form

  • # August 16, 2012 at 11:03 am

    Im trying to add the date to the top of an email confirmation.

    // prepare email body text
    $Body = "";
    $Body .= $Name;
    $Body .= "n";
    $Body .= 'I am delighted you contacted me via our website bla bla bla. ';

    Here is my best try…

    // prepare email body text
    $Body = "";
    $Body .= < ? print(Date("l F d, Y")); ?>;
    $Body .= $Name;
    $Body .= "n";
    $Body .= 'I am delighted you contacted me via our website. ';

    Obvious PHP Rookie

    # August 20, 2012 at 2:43 am

    You’re concatenating your message via your $Body variable, so it is rending in the message…. So, printing out the date isn’t going to work. You’ll need to create a date variable and append it in your message.


    $date = date('Ymd'); // or whatever format you'd like

    $Body = "blah...blahn";
    $Body .= "The date is: ".$date."n";
    //etc, etc...
    # August 20, 2012 at 5:55 am

    This reply has been reported for inappropriate content.

    You could also use it in a hidden field of the form.

    For example;

    <input type="hidden" name="date" id="date" value="" />

    Then assign a variable and output in the mailer script.

    # August 20, 2012 at 10:28 am

    Seems that broke it without error message. See anyhting strange?

    $EmailFrom = "TESTTHANK";
    $Subject = "Thank You";
    $Name = Trim(stripslashes($_POST));
    $Email = Trim(stripslashes($_POST));
    $date = date('Ymd');

    $Body = "";
    $Body .= "The date is: ".$date."n";
    $Body .= $Name . ",";
    $Body .= "n";
    $Body .= '
    I am delighted you contacted me via our website.
    Kelly Mills
    # August 21, 2012 at 1:31 pm

    What’s happening that’s indicating that something is broke? Are you not receiving the email? If so, can you post more code. Also, for the sake of consistency I would use lowercase trim() since that’s how it appears in the manual…

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed