2010-11-23 31 views
3

我使用PHP的默認郵件功能發送HTML電子郵件。 我的代碼:不需要的「!」標記在PHP的HTML電子郵件

//SENDMAIL 

// multiple recipients 
$to = ''. $email .'' . ', '; // note the comma 
$to .= '[email protected]'; 


// subject 
$subject = 'subject'; 

// message 
$message = ' 
<html> 
<head> 
<title>Email</title> 
<meta http-equiv="Content-Type" content="text/html; charset=windows-1257"> 
<style type="text/css"> 
body,td,th { 
font-family: Verdana; 
font-size: 12px; 
} 
</style> 
</head> 
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> 
html table data ...... in html syntax 
'; 

if(($b1 == "true" || $b2 == "true" || $b3 == "true" || $b4 == "true" || $b5 == "true" || $b6 == "true" || $b7 == "true" || $b8 == "true" || $b9 == "true" || $b10 == "true" || $b11 == "true" || $b12 == "true" || $b13 == "true" || $b14 == "true" || $b15 == "true" || $b16 == "true") && $enb == "true") 
{ 
$message .= 'link1<br> 
'; 
} 
if(($b1 == "true" || $b2 == "true" || $b3 == "true" || $b4 == "true" || $b5 == "true" || $b6 == "true" || $b7 == "true" || $b8 == "true" || $b9 == "true" || $b10 == "true" || $b11 == "true" || $b12 == "true" || $b13 == "true" || $b14 == "true" || $b15 == "true" || $b16 == "true") && $nlb == "true") 
{ 
$message .= 'link2<br> 
'; 
} 
$message .='html body continued in html syntax 
$message .= '</html>'; 

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; 

// Additional headers 
$headers .= 'To: ' . "\r\n"; 
$headers .= 'From: Sender <[email protected]>' . "\r\n"; 
$headers .= 'Cc: ' . "\r\n"; 
$headers .= 'Bcc: ' . "\r\n"; 

// Mail it 
mail($to, $subject, $message, $headers); 

當有時發來的消息,並不總是似乎有神祕的!在文本中間標記。 例如: 「謝謝你!或你的電子郵件」 或 「Ki!d的問候」,和cetra。 這似乎是沒有模式,所以我想問,如果這是在PHP郵件常見的錯誤,以及如何克服它?

謝謝!

+1

你能顯示這樣的句子生成的源代碼嗎? – 2010-11-23 14:41:07

回答

2

電子郵件的每行允許的最大字符數有限(998),我認爲這取決於它。 使用wordwrap來避免這些長行。

0

你混合

元HTTP的當量= 「Content-Type的」 內容= 「text/html的; 的charset =窗口-1257」

和頭

Content-type: text/html; charset=utf-8 

轉到utf-8並讓sur e它是utf-8你實際上是通過 發送的,使用http://www.php.net/manual/en/function.mb-convert-encoding.php mb_convert_encoding轉換爲utf-8。

mail($to, $subject, mb_convert_encoding($message, "UTF-8"), $headers); 
0

使用http://php.net/wordwrap將行數限制爲80個字符,並在包裝​​行的末尾附加一個等號(=)。

0

我剛剛在ASP頁面上遇到了與VB腳本相同的事情。解決方案是相同的:使用vbNewLine分解VB中的HTML行。