将表单数据从php页面发送到UTF-8中的电子邮件

时间:2014-03-27 10:34:53

标签: php utf-8

表格数据发送到电子邮件时遇到了很大问题。当我填写订单时,在电子邮件中我得到:

VÄrdiņš:LÄ«va,

而不是Vārdiņš:Līva

我想我已经设置了utf-8,但没有任何改变。有人可以帮忙吗?

这是我的orders.php

    <?php
header('Content-Type: text/html; charset=utf-8');
mb_internal_encoding( 'UTF-8' );
//subject and email variables//
$emailSubject = 'Pasūtījums no www.gramatina.lv';
$webMaster = 'info@gramatina.lv';

//gathering data variables//
$type = $_POST['type'];
$typography = $_POST['typography'];
$spiral = $_POST['spiral'];
$color_name = $_POST['color_name'];
$nameYes = $_POST['nameYes'];
$unryu = $_POST['unryu'];
$nameU = $_POST['nameU'];
$shipping = $_POST['shipping'];
$totalPrice = $_POST['totalPrice'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$address = $_POST['address'];
$comments = $_POST['comments'];
$other_color = $_POST['other_color'];

$body = <<<EOD
Grāmatas veids: $type
Krāsa: $typography, $spiral, $unryu, $other_color
Ar vai bez vārdiņa: $color_name
Vārdiņš: $nameYes, $nameU
Piegādes veids: $shipping
Cena: $totalPrice
Vārds, uzvārds: $first_name, $last_name
E-pasta adrese: $email
Telefona numurs: $telephone
Piegādes adrese: $address
Komentārs: $comments
EOD;

$header = "From: $email";

If($_POST){
    mail($webMaster, $emailSubject, $body, $header);
    header('Location: thank_you_order.html');

}
?>

这是html页面标题:

        <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Mūsu mazuļa grāmatiņa</title>
    </head>
    <body>
        <div id="form">
            <form action="orders.php" method="post">
        </div>
    </body>
    </html>

2 个答案:

答案 0 :(得分:0)

试试这个:

mail($webMaster,'=?UTF-8?B?'.base64_encode($emailSubject).'?=', $body, $header_ . $header);

答案 1 :(得分:0)

您可以添加标题

  

&#34;内容类型:text / html;字符集= UTF-8&#34;

到您的邮件正文。

$headers = array("Content-Type: text/html; charset=UTF-8");

如果使用本机mail()函数,$ headers数组将是第4个参数邮件($ to,$ subject,$ message,$ headers)