View Full Version : Showing Date In Email Subject
tomyknoker
04-12-2007, 06:02 AM
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...
$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);
}
?>
djr33
04-12-2007, 06:36 AM
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.
boogyman
04-12-2007, 12:25 PM
You need to fix your mail function... highlighted at red
mail($to, $subject, $message,header('From: '.$from));
djr33
04-12-2007, 01:03 PM
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.
mburt
04-12-2007, 01:31 PM
It's a specific order of strings for the headers on the mail function, followed by \r\n after each one.
From php.net:
$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.
realmetrics.com
04-16-2007, 03:28 AM
Use getdate() function to get the current date.
<?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.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.