Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php html和css代码在电子邮件中不可读_Php_Html_Css_Email - Fatal编程技术网

Php html和css代码在电子邮件中不可读

Php html和css代码在电子邮件中不可读,php,html,css,email,Php,Html,Css,Email,我真的很难使用php mail()函数制作带有附件的电子邮件,我已经成功地附加了我的文件,但邮件只是显示了HTML和CSS代码,而不是邮件正文,如下所示: 这是我的代码: $htmlbody = ' <!doctype html> <html> <head> <title>Inv

我真的很难使用php mail()函数制作带有附件的电子邮件,我已经成功地附加了我的文件,但邮件只是显示了HTML和CSS代码,而不是邮件正文,如下所示:

这是我的代码:

 $htmlbody = '
                    <!doctype html>
                    <html>
                    <head>
                        <title>Invoice</title>

                        <style>
                        .invoice-box{
                            background-color: rgb(244, 244, 244);
                            max-width:800px;
                            margin:auto;
                            padding:30px;
                            border:1px solid #eee;
                            box-shadow:0 0 10px rgba(0, 0, 0, .15);
                            font-size:16px;
                            line-height:24px;
                            font-family:"Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
                            color:#555;
                            border-color: #fe7100;
                            border-width: medium;
                        }

                        .invoice-box table{
                            width:100%;
                            line-height:inherit;
                            text-align:left;
                        }

                        .invoice-box table td{
                            padding:5px;
                            vertical-align:top;
                        }

                        .invoice-box table tr td:nth-child(2){
                            text-align:right;
                        }

                        .invoice-box table tr.top table td{
                            padding-bottom:20px;
                        }

                        .invoice-box table tr.top table td.title{
                            font-size:45px;
                            line-height:45px;
                            color:#333;
                        }

                        .invoice-box table tr.information table td{
                            padding-bottom:40px;
                        }

                        .invoice-box table tr.heading td{
                            background:#33665e;
                            border-bottom:1px solid #ddd;
                            font-weight:bold;
                            color: white;
                        }

                        .invoice-box table tr.details td{
                            padding-bottom:5px;
                        }

                        .invoice-box table tr.item td{
                            border-bottom:1px solid #eee;
                        }

                        .invoice-box table tr.item.last td{
                            border-bottom:none;
                        }

                        .invoice-box table tr.total td:nth-child(2){
                            border-top:2px solid #eee;
                            font-weight:bold;
                        }

                        @media only screen and (max-width: 600px) {
                            .invoice-box table tr.top table td{
                                width:100%;
                                display:block;
                                text-align:center;
                            }

                            .invoice-box table tr.information table td{
                                width:100%;
                                display:block;
                                text-align:center;
                            }
                        }

                        .block-garis{
                          width: 100%;
                          height: 3px;
                          background-color: #fe7100;
                        }
                        </style>
                    </head>

                    <body>
                        <div class="invoice-box">
                            <table cellpadding="0" cellspacing="0">
                                <tr class="top">
                                    <td colspan="2">
                                        <table>
                                            <tr>
                                                <td class="title">
                                                    <img src="https://4travelo.com/logo.png" style="width:100%; max-width:200px;">
                                                </td>

                                                <td>
                                                    Invoice #: '.$id.'<br>
                                                    Created: '.$tglbook.'<br>
                                                    Due: '.$timeexpiry.'
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>

                                <tr>
                                  <td colspan="2"><div class="block-garis"></div></td>
                                </tr>

                                <tr class="information">
                                    <td colspan="2">
                                        <table>
                                            <tr>
                                                <td>
                                                    4travelo.<br>
                                                    Jl. Kebonsari Menanggal 2B<br>
                                                    Surabaya.
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr class="heading">

                                    <td>
                                        Keterangan Hotel
                                    </td>

                                    <td>
                                        &nbsp;
                                    </td>
                                </tr>

                                <tr class="details">
                                    <td>
                                        Nama Hotel
                                    </td>

                                    <td>
                                        '.$hotelname.'
                                    </td>
                                </tr>
                                <tr class="details">
                                    <td>
                                        Alamat Hotel
                                    </td>

                                    <td>
                                        '.$alamat.'
                                    </td>
                                </tr>
                                <tr class="details">
                                    <td>
                                        Checkin
                                    </td>

                                    <td>
                                       '.$checkin.'
                                    </td>
                                </tr>
                                <tr class="details">
                                  <td>
                                      Checkout
                                  </td>

                                  <td>
                                     '.$checkout.'
                                  </td>
                                </tr>

                                <tr class="heading">
                                    <td>
                                        Guest
                                    </td>

                                    <td>
                                        &nbsp;
                                    </td>
                                </tr>

                                <tr class="item">
                                    <td>
                                        Guest Name
                                    </td>

                                    <td>
                                        '.$paxesname.'
                                    </td>
                                </tr>

                                <tr class="item">
                                    <td>
                                        Type Kamar
                                    </td>

                                    <td>
                                       '.$room.'
                                    </td>
                                </tr>

                                <tr class="item">
                                    <td>
                                        Include BF/Net
                                    </td>

                                    <td>
                                        '.$meal.'
                                    </td>
                                </tr>

                                <tr class="item">
                                    <td>
                                        Dewasa
                                    </td>

                                    <td>
                                        '.$adult.'
                                    </td>
                                </tr>

                                <tr class="item">
                                    <td>
                                        Anak - Anak
                                    </td>

                                    <td>
                                        '.$child.'
                                    </td>
                                </tr>

                                <tr class="heading">
                                    <td>
                                        Total
                                    </td>

                                    <td>
                                        &nbsp;
                                    </td>
                                </tr>

                                 <tr class="item">
                                    <td>
                                        Total
                                    </td>

                                    <td>
                                        <b>Rp '.$payment.'</b>
                                    </td>
                                </tr>
                                <tr>
                                  <td>&nbsp;</td>
                                  <td>&nbsp;</td>
                                </tr>

                                <tr>
                                  <td>&nbsp;</td>
                                  <td>&nbsp;</td>
                                </tr>

                                <tr>
                                  <td>&nbsp;</td>
                                  <td>&nbsp;</td>
                                </tr>
                                <tr style="font-size:10px; padding-top:50px;">
                                  <td><b>Hotel cancelation policy :
                                  <br>1. Pemesanan non refundable<br>
                                  2. Tanggal inap & tipe kamar tidak dapat dirubah</b>
                                  </td>
                                  <td><b>our partner : </b> <br><img src="https://4travelo.com/hb.png" alt=""></td>
                                </tr>

                                <tr>
                                  <td>&nbsp;</td>
                                  <td style=""></td>
                                </tr>
                            </table>
                        </div>

                    </body>
                    </html>';
        $to = $email; //Recipient Email Address
        $subject = "Test email with attachment"; //Email Subject
        $headers = "From: admin@4travelo.com\r\nReply-To: admin@4travelo.com";
        $random_hash = md5(date('r', time()));
        $headers .= "\r\nContent-Type: multipart/mixed; 
        boundary=\"PHP-mixed-".$random_hash."\"";
        // Set your file path here
       $attachment = chunk_split(base64_encode(file_get_contents('/home/travelo/public_html/4travelo.com/triomacan/4travelo_beta-2.0/document/'.$invoice.'.pdf'))); 


        //define the body of the message.
        $message = "--PHP-mixed-$random_hash\r\n"."Content-Type: multipart/alternative; 
        boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
        $message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain; 
        charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n";


        //Insert the html message.
        $message .= "$htmlbody";
        $message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";


        //include attachment
        $message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: application/zip; 
        name=\"invoice.pdf\"\r\n"."Content-Transfer-Encoding: 
        base64\r\n"."Content-Disposition: attachment\r\n\r\n";

        $message .= $attachment;
        $message .= "/r/n--PHP-mixed-$random_hash--";


        //send the email
        $mail = mail( $to, $subject , $message, $headers, '-f admin@4travelo.com' );

        echo $mail ? "Mail sent" : "Mail failed";
$htmlbody='1!'
发票联
.发票箱{
背景色:rgb(244244244);
最大宽度:800px;
保证金:自动;
填充:30px;
边框:1px实心#eee;
盒影:0 10px rgba(0,0,0,15);
字体大小:16px;
线高:24px;
字体系列:“Helvetica Neue”,“Helvetica”,Helvetica,Arial,无衬线;
颜色:#555;
边框颜色:#fe7100;
边框宽度:中等;
}
.发票箱表{
宽度:100%;
行高:继承;
文本对齐:左对齐;
}
.发票箱表格td{
填充物:5px;
垂直对齐:顶部;
}
.发票箱表tr td:n子项(2){
文本对齐:右对齐;
}
.发票箱表格tr.顶部表格td{
垫底:20px;
}
.发票箱表格tr.顶部表格td.标题{
字体大小:45px;
线高:45px;
颜色:#333;
}
.发票箱表tr.信息表td{
填充底部:40px;
}
.发票箱表tr.标题td{
背景:#33665e;
边框底部:1px实心#ddd;
字体大小:粗体;
颜色:白色;
}
.发票箱表tr.详细信息td{
垫底:5px;
}
.发票箱表tr.项目td{
边框底部:1px实心#eee;
}
.发票箱表tr.item.last td{
边框底部:无;
}
.发票箱表tr.总计td:第n个子项(2){
边框顶部:2个实心#eee;
字体大小:粗体;
}
@仅介质屏幕和(最大宽度:600px){
.发票箱表格tr.顶部表格td{
宽度:100%;
显示:块;
文本对齐:居中;
}
.发票箱表tr.信息表td{
宽度:100%;
显示:块;
文本对齐:居中;
}
}
布洛克·加里斯{
宽度:100%;
高度:3倍;
背景色:#fe7100;
}
发票:'.$id.
已创建:'.$tglbook.'
到期日:'.$timeexpiration' 4旅行。
Jl。Kebonsari Menanggal 2B
泗水。 凯特兰根酒店 纳马酒店 “.$hotelname”
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: My Name Here <noreply@example.co.uk>' . "\r\n";
$message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/html; 
$message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain; 
$message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/html;