Mail() help please

Hi everyone,

I am using mail() to send customers an order confirmation. All variables display correctly. What I am having a problem with is within my variable $message, I have a dynamically created array variable called $cartOutput which has a list of all items purchased. In the email received by the customer $cartOutput displays all the items in one continuous line instead of 1 line per item.

Example:
“Soap $4.00 Shampoo $3.00 Milk $3.50”
instead of:
Soap $4.00
Shampoo $3.00
Milk $3.50

Within my loop, the variable code looks like this:
$cartOutput .=‘Product: ’ . $product_name . ’ Price:’ . $product_price . ’ Quantity:’ . $product_quantity . ’ Line ttl:’ . $product_price . ‘’;

$cartOutput .= ‘’;

Within the quotes of the 2nd $cartOutput, I’ve tried \r\n , \n , even
but it just displays as regular text. i.e.: “Soap $4.00\r\nShampoo $3.00\nMilk $3.50

I tried removing the quotes but that gives me a syntax error.

I’ve even tried to put it in a table but that too shows the

, as text and still all in one line.

Please help.

The code that you posted uses single quotes, in order to use \n \r \t etc, you need to use double quotes.

‘\n’ => outputs \n
“\n” => outputs a newline character

Hi Smokey PHP,

Thank you, Thank you, Thank you!!!

I thought I tried everything and can’t believe the fix was this simple. Thank god for good people like you who guides us newbies through our rough patches. It works perfectly now.

My pleasure, glad to have helped. Happy coding!

Sponsor our Newsletter | Privacy Policy | Terms of Service