Results 1 to 6 of 6

Thread: Showing Date In Email Subject

  1. #1
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Showing Date In Email Subject

    Shouldn't it be as simple as this to display the date in my email subject? When I run this it just display exactly what's written, ignores the code...

    PHP Code:
    $message = <<<HERE
    The following people are members as of echo date('d-m-Y');.
    The login information is as follows:
    -----------------------------------------

    $login
    HERE;


    $from "Email <me@mydomain.com>";

    mail($to$subject$message'From: '.$from);
    }

    ?> 

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    erm...
    $subject = date(...);
    ??


    As for the above, that's the body, not subject, and you're using the <<<...; method for setting a string, so it won't parse anything.

    There's limited parsing with the {$var} construct, but I think that's limited to variables.

    You could set
    $date = date(...);
    Then use {$date} in the <<<EOF thing,
    or you could just split the string and output (echo) date() directly, by itself, not as part of the EOF.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    You need to fix your mail function... highlighted at red

    Code:
    mail($to, $subject, $message,header('From: '.$from));

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmm... I don't think that's the original question.
    And, The headers in the mail function aren't used with the header() function, I don't believe. header(), from how I have seen it used, outputs directly, before any html in the php script, to the browser, informing it as to the type of output (like html, or javascript, or jpeg).
    I might be wrong here, though, since I haven't gone too deep in the use of headers within the mail() function.
    I do know, though, that just a string with the right format will work for that.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    It's a specific order of strings for the headers on the mail function, followed by \r\n after each one.

    From php.net:
    Code:
    $headers = 'From: webmaster@example.com' . "\r\n" .
        'Reply-To: webmaster@example.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    But again, that wasn't the question. The OP's original question (about date(); ) was already answered.
    - Mike

  6. #6
    Join Date
    Apr 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Use getdate() function to get the current date.

    Code:
     
    
    <?php
    $message = “The following people are members as of echo date('d-m-Y');. 
    The login information is as follows: 
    -----------------------------------------“;
    $subject = getdate();
    $from = "Email <me@mydomain.com>"; 
    mail($to, $subject, $message, 'From: '.$from); 
    } 
    ?>
    getdate() function returns an array that contains date and time information for a Unix timestamp.

    I think this answers your question.
    Last edited by tech_support; 04-16-2007 at 09:11 AM. Reason: Please wait until you have 5 posts before having a signature.

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
  •