无法通过邮件发送HTML邮件()

时间:2013-05-04 15:01:02

标签: email php

以下代码发送的邮件包含所有HTML标记。我怎样摆脱尝试了几种方法,但邮件输出仍然用html标签打乱。如果有更好的方法通过mail();

发送元素数组,也需要帮助

我的代码:

<?php
    include('Mail.php');
    include('mail\mime.php');

    $errors=array();
    if(empty ($_POST)===false)
    {
        //$product = $_POST['product'];
        //$quantity = $_POST['quantity'] ;
        $email="noreply@cortexonline.in";
        $item1 = $_POST['product']['1'];
        $item2 = $_POST['product']['2'];
        $item3 = $_POST['product']['3'];
        $item4 = $_POST['product']['4'];
        $item5 = $_POST['product']['5'];
        $quan1 = $_POST['quantity']['1'];
        $quan2 = $_POST['quantity']['2'];
        $quan3 = $_POST['quantity']['3'];
        $quan4 = $_POST['quantity']['4'];
        $quan5 = $_POST['quantity']['5'];
        $message = "<html><head><title></title>
            </head> <body> <table> 
                <tr><td>Shop id=</td>
                </tr><tr><td>Product Name</td>
                    <td>Quantity</td></tr>
                <tr><td>".$item1."</td>
                    <td>".$quan1."</td></tr>
                <tr><td>".$item2."</td>
                    <td>".$quan2."</td></tr>
                <tr><td>".$item3."</td>
                    <td>".$quan3."</td></tr>
                <tr><td>".$item4."</td>
                    <td>".$quan4."</td><td>".$item5."</td><td>".$quan5."</td></tr>
            </table></body></html>";
        $header = 'From: "Quick order" <noreply@cort.in>'.PHP_EOL.
            'Reply-to: <noreply@cort.in>'.PHP_EOL.
            'MIME-Version: 1.0'.PHP_EOL.
            'Content-Type: text/plain; charset=utf-8'.PHP_EOL.
            'Content-Transfer-Encoding: 8bit'.PHP_EOL.
            'X-Mailer: PHP/'.PHP_VERSION.PHP_EOL;

   if(ctype_alpha($quan1)===true||ctype_alpha($quan2)===true||ctype_alpha($quan3)==true||ctype_alpha($quan4)===true||ctype_alpha($quan5)===true)
    {
        $errors[]=' Quantity cannot be alphabet /n
            Cannot send request';
    }

    if(isset($_POST['send'])===true)
    {       
        if (empty($errors)===false)
        {
            echo '<script language="javascript">alert("NOT SENT! Qunatity cannot be Alphabet")</script>';
        }
        else
        {
            mail('order@cortexonline.in','Quick order',$message,$header);

            echo '<script language="javascript">alert("Your order sent!")</script>';
            echo '<script language="javascript">window.location = "index.php"</script>';
        }
    }
    else
    {
        echo '<script language="javascript">alert("ORDER NOT SENT! Please Try Again.")</script>';
        echo '<script language="javascript">window.location = "index.php"</script>';
    }
}
?> 

还尝试使用单引号,但它无效。

1 个答案:

答案 0 :(得分:2)

试试这个:

$header = 'From: "Quick order" <noreply@cort.in>'.PHP_EOL.
            'Reply-to: <noreply@cort.in>'.PHP_EOL.
            'MIME-Version: 1.0'.PHP_EOL.
            'Content-Type: text/html; charset=utf-8'.PHP_EOL.
            'Content-Transfer-Encoding: 8bit'.PHP_EOL.
            'X-Mailer: PHP/'.PHP_VERSION.PHP_EOL;