亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP郵件:如何發送HTML?

PHP郵件:如何發送HTML?

滄海一幻覺 2019-09-06 15:50:46
下面的代碼是正確發送電子郵件,但身體。我需要在消息正文中顯示html而我無法做到。網絡中的示例將不會發送電子郵件:(如何修復我的代碼以發送帶有html的電子郵件?萬分感謝!<?php$to = '[email protected]';$subject = 'I need to show html'; $from ='[email protected]'; $body = '<p style=color:red;>This text should be red</p>';ini_set("sendmail_from", $from);$headers = "From: " . $from . "\r\nReply-To: " . $from . "";  $headers .= "Content-type: text/html\r\n"; if (mail($to, $subject, $body, $headers)) {  echo("<p>Sent</p>"); } else {  echo("<p>Error...</p>"); }?>
查看完整描述

3 回答

?
呼如林

TA貢獻1798條經驗 獲得超3個贊

將此標題用于郵件:


 $header  = "MIME-Version: 1.0\r\n";

 $header .= "Content-type: text/html; charset: utf8\r\n";

對于內容/正文:


<html>

    <head>

        <meta http-equiv="content-type" content="text/html; charset=utf-8" />

... ... ...

使用內聯css命令并建議使用表格作為接口非常重要。


...


在你的郵件正文中,你必須將HTML代碼放在頭部和正文中


查看完整回答
反對 回復 2019-09-06
?
手掌心

TA貢獻1942條經驗 獲得超3個贊

你看過收到的郵件的標題了嗎?它說


回復:[email protected]:text / html

\r\n在這里添加另一個:


Reply-To: " . $from . "\r\n";


查看完整回答
反對 回復 2019-09-06
?
楊__羊羊

TA貢獻1943條經驗 獲得超7個贊

我發現這很好用!

<?php

//define the receiver of the email

$to = '[email protected]';

//define the subject of the email

$subject = 'Test HTML email'; 

//create a boundary string. It must be unique 

//so we use the MD5 algorithm to generate a random hash

$random_hash = md5(date('r', time())); 

//define the headers we want passed. Note that they are separated with \r\n

$headers = "From: [email protected]\r\nReply-To: [email protected]";

//add boundary string and mime type specification

$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 

//define the body of the message.

ob_start(); //Turn on output buffering

?>

--PHP-alt-<?php echo $random_hash; ?>  

Content-Type: text/plain; charset="iso-8859-1" 

Content-Transfer-Encoding: 7bit


Hello World!!! 

This is simple text email message. 


--PHP-alt-<?php echo $random_hash; ?>  

Content-Type: text/html; charset="iso-8859-1" 

Content-Transfer-Encoding: 7bit


<h2>Hello World!</h2>

<p>This is something with <b>HTML</b> formatting.</p> 


--PHP-alt-<?php echo $random_hash; ?>--

<?

//copy current buffer contents into $message variable and delete current output buffer

$message = ob_get_clean();

//send the email

$mail_sent = @mail( $to, $subject, $message, $headers );

//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 

echo $mail_sent ? "Mail sent" : "Mail failed";

?>


查看完整回答
反對 回復 2019-09-06
  • 3 回答
  • 0 關注
  • 1331 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號