2012-03-21 63 views
1

我一直在寻找大约一个小时,谷歌不是我的朋友。我已经改变了我的代码,添加\ n \ r,添加纯文本格式,HTML格式...PHP新行将不打印

的电子邮件打印成这样:

Below is the site survey information for test Restaurant Name: test Contact Name: test Walk-Thru Contact Name: test Site Surveyor: Brandon Projected Install Date: test Projected Opening Date: test Projected Completion Date: test 
Item(s) Needed: test 
Priority Level: Necessary for Install 
Item(s) Needed: 
Priority Level: Necessary for Install 
Item(s) Needed: 
Priority Level: Necessary for Install 

只有前几行印刷在一起,但是完成日期之后的所有内容都是以新行打印。以下是目前为止的消息代码:

//Prepare content 

$subject = "Site Survey Information"; 
$from_header = "From: $formval_RestaurantName"; 
$headers .= "Content-type: textrn"; 

$to = "$formval_receiver"; 




$contents .= "Below is the site survey information for $formval_RestaurantName\r\n"; 
$contents .= "Restaurant Name: $formval_RestaurantName\r\n"; 
$contents .= "Contact Name: $formval_ContactName\r\n"; 
$contents .= "Walk-Thru Contact Name: $formval_walkthru\r\n"; 
$contents .= "Site Surveyor: $formval_surveyor\r\n"; 
$contents .= "Projected Install Date: $formval_install\r\n"; 
$contents .= "Projected Opening Date: $formval_open\r\n"; 
$contents .= "Projected Completion Date: $formval_finish\r\n"; 
$contents .= "Item(s) Needed: $formval_items1\r\n"; 
$contents .= "Priority Level: $formval_priority_1\r\n"; 
$contents .= "Item(s) Needed: $formval_items2\r\n"; 
$contents .= "Priority Level: $formval_priority_2\r\n"; 
$contents .= "Item(s) Needed: $formval_items3\r\n"; 
$contents .= "Priority Level: $formval_priority_3\r\n"; 
$contents .= "Item(s) Needed: $formval_items4\r\n"; 
$contents .= "Priority Level: $formval_priority_4\r\n"; 
$contents .= "Item(s) Needed: $formval_items5\r\n"; 
$contents .= "Priority Level: $formval_priority_5\r\n"; 
$contents .= "Item(s) Needed: $formval_items6\r\n"; 
$contents .= "Priority Level: $formval_priority_6\r\n"; 
$contents .= "Item(s) Needed: $formval_items7\r\n"; 
$contents .= "Priority Level: $formval_priority_7\r\n"; 
$contents .= "Item(s) Needed: $formval_items8\r\n"; 
$contents .= "Priority Level: $formval_priority_8\r\n"; 
$contents .= "Item(s) Needed: $formval_items9\r\n"; 
$contents .= "Priority Level: $formval_priority_9\r\n"; 
$contents .= "Item(s) Needed: $formval_items10\r\n"; 
$contents .= "Priority Level: $formval_priority_10\r\n"; 
$contents .= "Item(s) Needed: $formval_items11\r\n"; 
$contents .= "Priority Level: $formval_priority_11\r\n"; 
$contents .= "Item(s) Needed: $formval_items12\r\n"; 
$contents .= "Priority Level: $formval_priority_12\r\n"; 
$contents .= "Item(s) Needed: $formval_items13\r\n"; 
$contents .= "Priority Level: $formval_priority_13\r\n"; 
$contents .= "Item(s) Needed: $formval_items14\r\n"; 
$contents .= "Priority Level: $formval_priority_14\r\n"; 
$contents .= "Item(s) Needed: $formval_items15\r\n"; 
$contents .= "Priority Level: $formval_priority_15\r\n"; 

我还能做些什么来让它打印新行?

+1

什么是Content-type中的“textrn”? – allaire 2012-03-21 19:43:52

+0

你看到哪个电子邮件客户端没有打印新行,或者你只是在浏览器中查看它?虽然电子邮件HTML通常是非常挑剔的,但基础知识(如'
')仍然在全面工作。对于每次需要文本以新行开始时,您应告诉PHP打印一个网站上看到的'
' – Mattygabe 2012-03-21 19:45:15

+0

,有人说会将其转换为纯文本电子邮件。由于我一直在研究这个代码一个月,但它还没有真正起作用,所以我已经迫不及待地尝试了任何东西。 – user1284324 2012-03-21 19:45:44

回答

2

我想我以前见过这个。在嵌入变量之后使用\ r \ n,PHP中可能存在一个错误。

试试这个语法,看看它是否工作。

$contents .= 'Restaurant Name: ' . $formval_RestaurantName . "\r\n"; 
+0

谢谢,效果很好! – user1284324 2012-03-21 19:57:39

+0

什么错误?怎么样?! – meze 2012-03-21 19:59:19

+0

@meze我认为这是一个PHP错误,但我无法找到它的报告。它并不总是会发生,但是如果将转义字符放在双引号内的变量后面,则转义字符并不总是正确解析。你可以做一些像'$ contents。=“餐厅名称:{$ formval_RestaurantName} \ r \ n”;'也可以。 – AndrewR 2012-03-21 20:08:37

0

尝试使用PHP_EOL恒定

单独的变量和换行具有空间:
“预计完成日期:$ formval_finish \ r \ n” 个;

+0

我已经试过了。 – user1284324 2012-03-21 19:58:31

0

如果它被读为HTML,那么\ n被视为空白,而不是新行。改用<br>