2013-04-25 63 views
0

我有一個觸發電子郵件的PHP應用程序..現在,收件人得到的電子郵件與所有的HTML打印在一個文本塊..不能似乎在這裏找到錯誤,任何想法?電子郵件被髮送爲HTML

$user_info = get_userdata($venderid); 

$shoperMail = $user_info->user_email; 
$shoperName = $user_info->display_name; 

$to  = $shoperMail.", [email protected]"; 
$subject = "Sales Order from website"; 

$message = ''; 
$message = "Hi $shoperName,<br><br>"; 
$message .= "A Gift has been redeemed for your services.<br><br>"; 
$message .= "Customer: $currentuserName<br><br>"; 
$message .= "Redemption Amount: $$redempt<br><br>"; 
$message .= "Customer code:$confirmationCode<br><br>"; 
$message .= "To access their contact & order information, simply log in to your account & select: Gift Cards > Vendor Orders.<br><br>"; 
$message .= "*Once you have provided the customer with your company's voucher, certificate or online coupon code, please 'Approve' their purchase.<br><br>"; 
$message .= "Log in: <a href='".$url."/login/'>http://test.com</a><br><br>"; 
$message .= "If you have any questions, please don't hesitate to contact me.<br><br>"; 
$message .= "Test test<br>order Gift Cards<br><i>doing cool stuff.</i><br><br>toll free: 866.test x.tes x 9<br><a href='http://www.test.com/'>Test.com</a>,<br><a href='http://www.facebook.com/test/'>facebook.com/test</a><br><a href='http://twitter.com/test/'>twitter.com/test</a><br><br><br>" ; 
$message .= "**The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, re-transmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this email in error, please contact the sender immediately by return electronic transmission and then immediately delete this transmission, including all attachments, without copying, distributing or disclosing same. "; 

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= "To: ".$shoperMail."\r\n"; 
$headers .= "From: [email protected]\r\n"; 

mail($to,$subject,$message,$headers); 
+0

使用\ n而不是
,
在您的按摩身體文字 – underscore 2013-04-25 18:51:41

+2

不會手動建立mime電子郵件。使用phpmailer或swiftmailer。他們會自動完成所有這些工作,並且您只需提供html即可。你也沒有提供完整有效的html文檔。只是一些帶有html標籤的文本。 – 2013-04-25 18:51:59

+0

@SamithaHewawasam - 它應該是一個HTML電子郵件。如果您使用\ n,它將不會出現在完成的HTML中。 – andrewsi 2013-04-25 18:54:40

回答

0

您需要設置HTML內容類型,例如,從Codex

add_filter('wp_mail_content_type', 'my_set_html_content_type'); 
wp_mail('[email protected]', 'The subject', '<p>The <em>HTML</em> message</p>'); 
remove_filter('wp_mail_content_type', 'my_set_html_content_type'); // reset content-type 

篩選回調:

function my_set_html_content_type() 
{ 
    return 'text/html'; 
} 
0

我已經嵌入你在相同的HTML郵件代碼我通常使用的標記。

試試這個:

// Getting info  
$user_info = get_userdata($venderid); 
$shoperMail = $user_info->user_email; 
$shoperName = $user_info->display_name; 
$to = $shoperMail.", [email protected]"; 

// HTML 
$message = ''; 
$message = "Hi $shoperName,<br><br>"; 
$message .= "A Gift has been redeemed for your services.<br><br>"; 
$message .= "Customer: $currentuserName<br><br>"; 
$message .= "Redemption Amount: $$redempt<br><br>"; 
$message .= "Customer code:$confirmationCode<br><br>"; 
$message .= "To access their contact & order information, simply log in to your account & select: Gift Cards > Vendor Orders.<br><br>"; 
$message .= "*Once you have provided the customer with your company's voucher, certificate or online coupon code, please 'Approve' their purchase.<br><br>"; 
$message .= "Log in: <a href='".$url."/login/'>http://test.com</a><br><br>"; 
$message .= "If you have any questions, please don't hesitate to contact me.<br><br>"; 
$message .= "Test test<br>order Gift Cards<br><i>doing cool stuff.</i><br><br>toll free: 866.test x.tes x 9<br><a href='http://www.test.com/'>Test.com</a>,<br><a href='http://www.facebook.com/test/'>facebook.com/test</a><br><a href='http://twitter.com/test/'>twitter.com/test</a><br><br><br>" ; 
$message .= "**The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, re-transmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this email in error, please contact the sender immediately by return electronic transmission and then immediately delete this transmission, including all attachments, without copying, distributing or disclosing same. "; 

// Subject 
$subject = "Sales Order from website"; 

// Header 
$innerboundary ="=_".time()."_="; 
$header ="MIME-Version: 1.0\n"; 
$header.="To: ".$to."\n"; 
$header.="From: [email protected]\n"; 
$header.="Reply-To: [email protected]\n"; 
$header.="X-Mailer: kmPHP-Mailer\n"; 
$header.="Content-Type: multipart/alternative;\n\tboundary=\"".$innerboundary."\"\n"; 

// Body 
$body.="\n--".$innerboundary."\n"; 
$body.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n"; 
$body.="Content-Transfer-Encoding: base64\n\n"; 
$body.=chunk_split(base64_encode(($message)))."\n\n"; 
$body.="\n--".$innerboundary."--\n"; 
$body.="\n\n"; 

// Send 
mail($shoperMail,$subject,$body,$header); 
0

重申上述

馬克乙評論不要用手建立MIME電子郵件。請使用phpmailerswiftmailer。他們會自動完成所有這些工作,並且您只需提供html即可。

這樣做會使您通過以不同方式解決問題變得更容易。