如何使用PHP管理邮件中的特定格式设计?

时间:2013-07-16 05:40:51

标签: html css php

我想以特定格式发送邮件...我想通过mail.mail发送成功发送的运送信息和跟踪号码,但以某种格式显示...以下格式我希望实现..

Dear xyz ,                                                            

Per your request, this email is to notify you that your items have been    
shipped.                                                                   

You can track the status of this order, and all of your orders, online     
by visiting your account at http://www.uline.com/MyAccount/myUline.aspx    

The following items were included in this shipment:                        
---------------------------------------------------------------------------
     Qty   UM   Item#         Description               Price   Shipped    
---------------------------------------------------------------------------
   1,000   M    S-209         4.5X5.5 INV ENCLOSED P   $0.023    1,000     
---------------------------------------------------------------------------

This shipment was sent to:                                                 

    xyz xxx                                                              
    3372 KENSINGTON DR                                                     
    AVON, OH  44011                                                        

Po#: xyz

Carrier: UPS Ground                                                        

Here are your tracking numbers:                                            

1ZA6898Axxxxxxxxx                                                         

我试过这个.....................

$subject="computermall Shipping Confirmation - Order#: ".$_REQUEST['ordid']."";

 $header="from:orders@computermall.co.in";

$content="<html><body>Dear ".$rw['firstname']."&nbsp;".$rw['lastname']."  ,    <br>                                                 

Per your request, this email is to notify you that your items have been    
shipped <br><br>                 

Here is your tracking number :  ".$_REQUEST['trackno']."   <br>   <br>                             

---------------------------------------------------------------------------<br>
Order#:     ".$row3['order_id']." <br> 
Order Date: ".$row3['order_date']."    <br>        

---------------------------------------------------------------------------<br>        

Sold To:                  <br>                                                            

".$rw['firstname']."&nbsp;".$rw['lastname']."    <br>                                                

".$rw['address']."      <br>              
".$rw['city']."      <br>    
".$rw['pincode']."    <br> <br> 

 Ship To:              <br> 

".$rw['firstname']."&nbsp;".$rw['lastname']." <br>                                                  

".$rw['address']."     <br>              
".$rw['city']."        <br>  
".$rw['pincode']."    <br> <br> 

--------------------------------------------------------------------------- <br> 
Qty&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;         Product      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;               Price     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   <br> 
--------------------------------------------------------------------------- <br> ";
$s="select * from tbl_shoppingcart where cust_name='".$_REQUEST['username']."' and action='confirm' and order_id=".$_REQUEST['ordid']." order by id desc";
                    $q=mysql_query($s) or die($s);
                    $num=mysql_num_rows($q);
                    while($row=mysql_fetch_array($q)){ 
                    $_SESSION['gtotal']=$row['grand_total'];
                     echo" 
".$row['qty']."  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ".$row['p_name']."  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;             Rs.".$row['price']." &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br> <br>";
} echo"
---------------------------------------------------------------------------<br>
Sub-Total    Rs.".$_SESSION['gtotal']."    <br>
Shipping     00.00   <br>
Sales Tax     $0.00    <br>
Total*      Rs.".$_SESSION['gtotal']."  <br>

</body></html>";


mail($email, $subject, $content, $header);

以这种格式发送邮件......

<html><body>Dear chirag&nbsp;ode  ,    <br>                                                 

Per your request, this email is to notify you that your items have been    
shipped <br><br>                 

Here is your tracking number :  ab12345cd567   <br>   <br>                             

---------------------------------------------------------------------------<br>
Order#:     33133271 <br> 
Order Date: 15-07-13    <br>        

---------------------------------------------------------------------------<br>        

Sold To:                  <br>                                                            

chirag&nbsp;ode    <br>                                                

dhartipark society      <br>              
vadodara      <br>    
390002    <br> <br> 

 Ship To:              <br> 

chirag&nbsp;ode <br>                                                  

dhartipark society     <br>              
vadodara        <br>  
390002    <br> <br> 

--------------------------------------------------------------------------- <br> 
Qty&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;         Product      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;               Price     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   <br> 
--------------------------------------------------------------------------- <br>

3 个答案:

答案 0 :(得分:0)

为了实现您的电子邮件,最好的方法是使用USE表,tr和td!不仅仅是br或div元素。

答案 1 :(得分:0)

我的代码中没有看到特殊的标题。吉尔伯特工具正确,显示这样的电子邮件更容易使用表格,但必须发送一些邮件箱HTML标题,所以尝试将其添加到$ he​​ader

答案 2 :(得分:0)

首先Please use PDO instead of mysql_*Heredoc in PHP可以帮助您使用多行字符串。 :)

如果邮件不是纯文本。您应该包含Content-Type邮件标题,以告知您的邮件内容类型,电子邮件客户端将正确显示邮件。

$header  = "From: orders@computermall.co.in\r\n";
$header .= "Content-Type: text/html; charset=utf-8\r\n";