2012-03-21 61 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>