2013-03-21 11 views
0

希望我可以得到一些帮助,因为这是驱使我坚果。PHP多部分文本/ HTML显示空白

我已经尝试过各种脚本来做到这一点,但我登陆的是这个。这张照片有什么问题?我收到一封电子邮件,但它完全空白。但是,电子邮件的来源包含内容。

EMAIL CODE

//define receiver and subject 

    $to = '[email protected]'; 
    $subject = 'Test email'; 

//create boundary 

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

//define the headers 

    $headers = "From: [email protected]\r\nReply-To: [email protected]"; 
    $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"$random_hash\""; 

//define the body of the message. 

    $message = "--$random_hash\n" . 
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . 
    "Content-Transfer-Encoding: 7bit\n\r" . 

    "Hello\n\rWorld!!!\n\r" . 

    "--$random_hash\n" . 
    "Content-Type: text/html; charset=\"iso-8859-1\"\n" . 
    "Content-Transfer-Encoding: 7bit\n\r" . 

    "<h2>Hello World!</h2>\n\r" . 

    "--$random_hash--"; 

//send the email 

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

EMAIL SOURCE(收)

Received: (qmail 26359 invoked by uid 48); 21 Mar 2013 10:09:01 -0700 
Date: 21 Mar 2013 10:09:01 -0700 
Message-ID: <[email protected]> 
To: [email protected] 
Subject: Test email 
X-PHP-Originating-Script: 10001:plug-send-direct.php 
From: [email protected] 
Reply-To: [email protected] 
Content-Type: multipart/alternative; boundary="f41fbfe6fda45eb7f5a2724ba135d292" 

--f41fbfe6fda45eb7f5a2724ba135d292 
Content-Type: text/plain; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit 


Hello 

World!!! 

--f41fbfe6fda45eb7f5a2724ba135d292 
Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit 

<h2>Hello World!</h2> 

--f41fbfe6fda45eb7f5a2724ba135d292-- 

是怎么回事?

回答

0

请确保您的HTML与“html”,“head”和“body”标签正确组合。另外,确保它们正确关闭。

<html> 
<head> 
</head> 
    <body> 
    Stuff 
    </body> 
</html>