2012-03-27 101 views
0

我創建了一個在線商店,並且我想發送一封電子郵件收據......我已經使用php mail()函數將原始HTML發送到了正確的電子郵件地址,但是那都是它是原始的HTML ...有沒有一種方式,電子郵件客戶端(Gmail中)會認爲這是一個網絡佈局發送HTML並將其格式化爲電子郵件

在它看起來像這樣的時刻,電子郵件客戶端接收它

<HTML><BODY><TABLE class = product cellpadding = 0 cellsspacing = 0 border = 0 width = 
100%><tr><td width = 50 height = 60><a href="shopProcessCart.php?action=delete&id=3" 
class="r"><img src="inc/remove.png" border="0" alt="Remove"></a></td><td>Cape Clear 
History Part 2</td><td width = 70>&euro;14.99</td><td width = 40><input type="number" 
name="qty3" value="1" size="2" maxlength="2" /></td></TABLE><p>Total: 
<strong>&euro;14.99</strong></p></BODY></HTML> 

回答

1

你只需要設置頁眉到HTML郵件:

$to = "[email protected]"; 
    $from = "[email protected]"; 
    $subject = "Hello! This is HTML email"; 

    //begin of HTML message 
    $message = <<<EOF 
<html> 
    <body bgcolor="#DDDDDD"> 
    YOUR HTML EMAIL 
    </body> 
</html> 
EOF; 
    //end of message 
    $headers = "From: $from\r\n"; 
    $headers .= "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-type: text/html\r\n"; 

    mail($to, $subject, $message, $headers); 
1

你將不得不設置html標頭

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

並將其作爲參數傳遞給php的mail()函數

郵件($ to,$ subject,$ message,$ headers);

+0

非常感謝該 – kev670 2012-03-27 01:05:02

相關問題