2011-02-26 96 views
0

我在一個網站上工作,使用php的mail()函數發送電子郵件。但是,由於服務器發送HTML電子郵件時遇到一些問題,因此電子郵件未正確傳送。請幫助...代碼如下:代碼如下:不能以html格式發送郵件

<?php 
$fromAddr = 'Frendzpark <[email protected]>'; // the address to show in From field. 
$recipientAddr = '[email protected]'; 
$subjectStr = 'Demo:Account created successfully'; 

$mailBodyText = <<<HHHHHHHHHHHHHH 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> 
<title>Account created successfully</title> 
</head> 
<body> 
<p> 
<div style="color: #ff4e0a; height: 100px; font-weight: bold; font-size: 70px; font-family: 'Maiandra GD'; text-align: left; padding-left: 10px;"> 
     Chatmasti</div><hr /> 
    <div style="font-family: 'Trebuchet MS'; height: 160px; padding-left: 30px; font-size: 12px; border-left-width: thin; border-left-color: #ccccff; border-bottom-width: thin; border-bottom-color: #ccccff; border-right-width: thin; border-right-color: #ccccff;"> 
     Thank you for signing up. Your account has been created successfully and your account 
     details are as follows:<br /> 
     <br /> 
     Username: <b>user</b><br /> 
     Password: <b>pass</b><br /> 
      <br /> 
     You can start chatting after verifying your email address. To verify the email address 
     please click the link below:<br /> 
     <a href="http://www.chatmasti.uk.tc/verify=3973hfuhfri23892">http://www.chatmasti.uk.tc/verify=3973hfuhfri23892</a><br /> 
     Hope you enjoy this free service.<br /> 
     <br /> 
     Regards,<br /> 
     Sanket Raut.<br /> 
     Webmaster,<br /> 
     Chatmasti</div> 
</p> 
</body> 
</html> 
HHHHHHHHHHHHHH; 

$headers= <<<TTTTTTTTTTTT 
From: $fromAddr 
MIME-Version: 1.0 
Content-Type: text/html; 
TTTTTTTTTTTT; 

$sent=mail($recipientAddr , $subjectStr , $mailBodyText, $headers); 
if($sent) 
print "Mail sent"; 
else 
print "Error"; 

?> 

回答

0

我想你需要指定charset。添加charset選項的內容類型選擇的背後,是這樣的:

Content-type: text/html; charset=iso-8859-1 
+0

我在哪裏指定它? – 2011-02-26 12:18:47

+0

在標題部分。您已經擁有Content-type:text/html;所以把charset = iso-8859-1放在它後面。 – Ray 2011-02-26 12:21:03

+0

@射線:我在哪裏準確地指定它? – 2011-02-26 12:21:17