Email wont "\\n"

I am trying to get an email to generate

and i get as far as the next line command

any ideas?

$body = “Client Name: " .”{$Fname} " . “{$Lname}” . "
"X-------stops working here
"Country: " . “{$country}” . “<br />”;
"Phone: " . “{$Phone}” . “<br />”;
"Email: " . “{$Email}” . “<br />”;
"Message: " . “{$Message}” . “<br />”;

You haven’t concateneated those bits properly. Try something like

$body = "Client Name: " ."{$Fname} " . "{$Lname}" . "\
" .
"Country: " . "{$country}" . "<br />" .
"Phone: " . "{$Phone}" . "<br />" .
"Email: " . "{$Email}" . "<br />" .
"Message: " . "{$Message}" . "<br />"; 

or perhaps just make it even simpler:

$body = "Client Name: $Fname $Lname\
" .
        "Country: $country\
" .
        "Phone: $Phone\
" .
        "Email: $Email\
" .
        "Message: $Message"; 


do you have any tips on making the resulting email a bit nicer eg colours, images etc

Did it work?

do you have any tips on making the resulting email a bit nicer eg colours, images etc

That’s a different kettle of fish, as you are talking about an HTML email. Someone else will have to help you with that. :slight_smile:

worked very well thanks heaps

html email , you say.

thanks again

Yes, adding colors to text is basically talking HTML email. The mail() function only deals with plain text email. You can send HTML email (as shown here: ), but that method doesn’t provide a plain text version, which is good to include for those who can’t view the HTML version. You could check out PHPM@iler or [URL=“”]Zend_Mail to send both versions.

@minusten, your script is rather cumbersome. You are concatenating variables, dispite them already being in double quotes (to interpolate them). You also could use the predefined constant PHP_EOL, so that there will be a carriage return regardless of what architecture you are working on.

Here is a script that is a lot more optimised:

$body = 'Client Name: ',$Fname,' ',$Lname,PHP_EOL,
'Country: ',$country,PHP_EOL,
'Phone: ',$Phone,PHP_EOL,
'Email: ',$Email,PHP_EOL,
'Message: ',$Message,PHP_EOL;

What you will notice in my script above is that I do not bother concatenating or interpolating variables. This means there is no resource overhang for php when try to parse the variable $body.

Hi modernW. Welcome to the forums. :slight_smile:

That code looks much neater. Thanks for posting it. (I pop over here from the design forums now and then, and I always learn something good. :slight_smile: )

First off, you’re code won’t actually run… $body is a variable/string, not echo, so those commas won’t work as you HAVE to use string addition there.

Second, one could use single quotes as you did and then OMIT PHP EOL and just use actual carriage returns in the code instead of screwing with extra vars or escape codes.

$body = 'Client Name: '.$Fname.' '.$Lname.'
Country: '.$country.'
Phone: '.$Phone.'
Email: '.$Email.'
Message: '.$Message;

Functional equivalent, and even simpler. (and this one would actually run).

Oh, and @ the OP, adding HTML to e-mails is just a great way to get them flagged as spam; you want colors and bold and the like, then you don’t want e-mails. Stick to plain-text, then your mails might actually have a chance of reaching people.

Whoops, yes you are correct (im not sure why but i thought i was writing about echoing out content…). Using commas for stacking can only be done in echo, and yes seen as it is a variable there is no need to use the constant PHP_EOL.

And alternative to your code above would be using heredoc:

$body = <<< string
Client Name: $Fname $Lname
Country: $country
Phone: $Phone
Email: $Email
Message: $Message