Forum Moderators: coopster

Message Too Old, No Replies

Adding header to php email form script

         

cyberdyne

12:35 am on May 26, 2011 (gmt 0)

10+ Year Member



I need to ad a 'received from' header to my email script but am having trouble with the code.

Currently have:
$headers = 'Received: from {$_SERVER['REMOTE_ADDR']} by www.domain.com'\n;
with HTTP; " . strftime("%A %d %B'%y at: %r").\r\n";


I know there are a few errors in there but I can't seem to get enough coffee down me to work them out.

Any help greatly appreciated
Thank you

rocknbil

4:48 pm on May 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are single quoted here

'Received: from {$_SERVER['REMOTE_ADDR']} by www.domain.com'

then the string ends and you have a bare newline

\n;

follwed by another bare string


with HTTP;

then a double quoted concatenated string

" . strftime("%A %d %B'%y at: %r").\r\n";

Single quotes do not interpolate variables, double quotes do. This includes newlines, tabs, etc. Also regular newlines are interpolated, which means you (usually) don't need \r\n. You need to step in and out of concatenation when you call functions and some array variables (unless wrapped in {}, and only when double-quoted.) Try

$headers = "Received: from {$_SERVER['REMOTE_ADDR']} by www.domain.com
with HTTP; " . strftime("%A %d %B'%y at: %r") . "
";

or

$headers = "Received: from {$_SERVER['REMOTE_ADDR']} by www.domain.com\r\n";
$headers .= "with HTTP; " . strftime("%A %d %B'%y at: %r")."\r\n";

cyberdyne

4:21 pm on Jun 2, 2011 (gmt 0)

10+ Year Member



I greatly appreciate your reply, many thanks.