Адпраўка HTML электроннай пошты з PHP

У мяне ёсць некаторы код, які адпраўляе па электроннай пошце з укладаннем. Я атрымліваю ліст з дадаткам, але ён адлюстроўвае HTML элементы. Я выкарыстоўваю Content-Type: шматчастковы/змешаны; мяжа = ... і калі я адправіць ліст з укладаннем я бачу HTML-элементы ў электроннай пошце, але, калі я пашлю яго без укладанняў электроннай пошты адлюстроўваецца правільна. Вось код:

if(is_uploaded_file($_FILES['attachment']['tmp_name'])){
            //die("uploaded");
            copy($_FILES['attachment']['tmp_name'],"attachments/" . $_FILES['attachment']['name']);
            $file = $_FILES['attachment']['tmp_name'];
            $file_type = $_FILES['attachment']['type'];
            $file_name = $_FILES['attachment']['name'];
            $fopen = fopen($file, 'rb');
            $data = fread($fopen,filesize($file));
            fclose($fopen);

            $semi_rand = md5(time());
            $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

            $headers = "From: " .EMAIL_FROM_ADDR. "\r\n";
            $headers .= "Reply-To: ".EMAIL_FROM_ADDR."\r\n";
            $headers .= "CC: [email protected]\r\n";    
            $headers .= "MIME-Version: 1.0\r\n";
            $headers .= "Content-Type: multipart/mixed; boundary=\"{$mime_boundary}\"";
            $message = "This is a multi-part message in MIME format.\n\n".
                       "--{$mime_boundary}\n".
                       "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . 
                       "Content-Transfer-Encoding: 7bit\n\n".
                       "<table border='1' cellspacing='1' cellpadding='1'>".
                        "<tr><td>Vendor Name:</td><td>".$_POST['vendor_name']."</td></tr>".
                        "<tr><td>Internet Agreement No:</td><td>".$_POST['internet_agreement_no']."</td></tr>".
                        "<tr><td>Vendor Duns No:</td><td>".$_POST['vendor_duns_no']."</td></tr>".
                        "<tr><td>Fee to NEXCOM:</td><td>".$_POST['fee_to_nexcom']."%</td></tr>".
                        "<tr><td>Settlement Worksheet For:</td><td>".$_POST['settlement_worksheet_date']."</td></tr>".
                        "<tr><td colspan='2'> </td></tr>".
                        "<tr><td>Total Gross Sales:</td><td>$".$_POST['total_gross_sales_1']."</td></tr>".
                        "<tr><td>Deductions:</td><td>$".$_POST['deductions']."</td></tr>".
                        "<tr><td>Refunds/Credits(Attach Backup):</td><td>$".$_POST['refunds_credits']."</td></tr>".
                        "<tr><td>Sales Tax:</td><td>$".$_POST['sales_tax']."</td></tr>".
                        "<tr><td>State Tax:</td><td>$".$_POST['state_tax']."</td></tr>".
                        "<tr><td>Other(Explain):".$_POST['explain_1']."</td><td>$".$_POST['other_1']."</td></tr>".
                        "<tr><td>Other(Explain):".$_POST['explain_2']."</td><td>$".$_POST['other_2']."</td></tr>".
                        "<tr><td>Total Deductions:</td><td>$".$_POST['total_deductions']."</td></tr>".
                        "<tr><td>Total Gross Sales:</td><td>$".$_POST['total_gross_sales_2']."</td></tr>".
                        "<tr><td>Less Deductions:</td><td>$".$_POST['less_deductions']."</td></tr>".
                        "<tr><td>Net Sales Subject to Commission:</td><td>$".$_POST['net_sales_subject']."</td></tr>".
                        "<tr><td>Net Commission due to NEXCOM:</td><td>$".$_POST['net_commission_due']."</td></tr>".
                        "<tr><td colspan='2'>Comments:</td></tr>".
                        "<tr><td colspan='2'>".$_POST['comments']."</td></tr>".
                       "</table>\n\n";

            $data = chunk_split(base64_encode($data));
            $message .= "--{$mime_boundary}\n".
                        "Content-Type: {$file_type}; name=\"{$file_name}\"\n".
                        "Content-Disposition: attachment; filename=\"{$file_name}\"\n".
                        "Content-Transfer-Encoding: base64\n\n".
                        $data."\n\n".
                        "--{$mime_boundary}--\n";       
        }
        else{
            //die("not uploaded");
            $headers = "From: " .EMAIL_FROM_ADDR. "\r\n";
            $headers .= "Reply-To: ".EMAIL_FROM_ADDR."\r\n";
            $headers .= "CC: [email protected]\r\n";
            $headers .= "MIME-Version: 1.0\r\n";
            $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
            $message = "<table border='1' cellspacing='1' cellpadding='1'>".
                        "<tr><td>Vendor Name:</td><td>".$_POST['vendor_name']."</td></tr>".
                        "<tr><td>Internet Agreement No:</td><td>".$_POST['internet_agreement_no']."</td></tr>".
                        "<tr><td>Vendor Duns No:</td><td>".$_POST['vendor_duns_no']."</td></tr>".
                        "<tr><td>Fee to NEXCOM:</td><td>".$_POST['fee_to_nexcom']."%</td></tr>".
                        "<tr><td>Settlement Worksheet For:</td><td>".$_POST['settlement_worksheet_date']."</td></tr>".
                        "<tr><td colspan='2'> </td></tr>".
                        "<tr><td>Total Gross Sales:</td><td>$".$_POST['total_gross_sales_1']."</td></tr>".
                        "<tr><td>Deductions:</td><td>$".$_POST['deductions']."</td></tr>".
                        "<tr><td>Refunds/Credits(Attach Backup):</td><td>$".$_POST['refunds_credits']."</td></tr>".
                        "<tr><td>Sales Tax:</td><td>$".$_POST['sales_tax']."</td></tr>".
                        "<tr><td>State Tax:</td><td>$".$_POST['state_tax']."</td></tr>".
                        "<tr><td>Other(Explain):".$_POST['explain_1']."</td><td>$".$_POST['other_1']."</td></tr>".
                        "<tr><td>Other(Explain):".$_POST['explain_2']."</td><td>$".$_POST['other_2']."</td></tr>".
                        "<tr><td>Total Deductions:</td><td>$".$_POST['total_deductions']."</td></tr>".
                        "<tr><td>Total Gross Sales:</td><td>$".$_POST['total_gross_sales_2']."</td></tr>".
                        "<tr><td>Less Deductions:</td><td>$".$_POST['less_deductions']."</td></tr>".
                        "<tr><td>Net Sales Subject to Commission:</td><td>$".$_POST['net_sales_subject']."</td></tr>".
                        "<tr><td>Net Commission due to NEXCOM:</td><td>$".$_POST['net_commission_due']."</td></tr>".
                        "<tr><td colspan='2'>Comments:</td></tr>".
                        "<tr><td colspan='2'>".$_POST['comments']."</td></tr>".
                       "</table>";
        }           
0

2 адказы

Вы пішаце Content-Type: Тэкст/раўніну; у целе паведамлення. Ўстаноўка гэтага Тэкст/HTML павінен зрабіць трук.

1
дададзена

Вы можаце выкарыстоўваць бібліятэкі, каб зрабіць гэта для вас. Яны добра выкарыстоўваюцца і маюць шмат памылак ліквідаваны, і яны вольныя.

Тыя, я бачу, згадаў большасць SO з'яўляюцца

http://swiftmailer.org/

http://phpmailer.worxware.com/

Мае асабістыя перавагі пасля выкарыстання як для Swiftmailer

0
дададзена