-1

我的网站上有一个用 php 制作的联系表格。问题是它完美地发送英文字母但不支持俄文字母。所以,我需要更改编码,我该怎么做?

这是一个代码:

<div id="center">
    <p class="please">Please contact us using this form.</p>
    <div id="formbox">
        <?
            if (isset ($_POST['message'])) {
            $name = @ trim ($_POST['name']);
            $contact = @ trim ($_POST['contact']);
            $message = @ trim ($_POST['message']);
            if (! $name or ! $contact or ! $message) echo ('<p style="color: red">You should fill in all the blanks.</p>');
            else { mail ("support@myemail.com",
                  "Message from Giftosite (Sender: $name)",
                  "$message \n\n Reply to: \n $contact");
                  echo ('<p style="color: green">Message has been sent, thank you!</p>');
                  $_POST['name'] = $_POST['contact'] = $_POST['message'] = '';
            }
            }
            ?>
            <form method="POST" class="form">
            <p class="formcontent">Your name:</p>
            <input name="name" value="<?=@$_POST['name'];?>">
            <p class="formcontent">Your e-mail address:</p>
            <input name="contact" value="<?=@$_POST['contact'];?>">
            <p class="formcontent">Message:</p>
            <textarea name="message" rows="6" cols="36"><?=@$_POST['message'];?></textarea>
            <p><input type="submit" value=" Send "></p>
            </form>
    </div>
</div>
4

2 回答 2

3

在电子邮件中设置标题

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
           'Content-type: text/html; charset=UTF-8;' . "\r\n" .
           'Reply-To: webmaster@example.com' . "\r\n" .
           'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

所以,在你的代码而不是这个

mail ("support@myemail.com", $message from Giftosite (Sender: $name)", "$message \n\n Reply to: \n $contact");

你将会有

$headers = 'From: webmaster@example.com' . "\r\n" .
           'Content-type: text/html; charset=UTF-8;' . "\r\n" .
           'Reply-To: webmaster@example.com' . "\r\n" .
           'X-Mailer: PHP/' . phpversion();
mail ("support@myemail.com", $message from Giftosite (Sender: $name)", "$message \n\n Reply to: \n $contact", $headers);
于 2012-06-22T07:09:24.140 回答
0

您需要在发送 Unicode 字符之前为您的电子邮件设置标题,试试这个

$header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
mail ("support@myemail.com",
                  "Message from Giftosite (Sender: $name)",
                  "$message \n\n Reply to: \n $contact", $header_);
于 2012-06-22T07:13:10.830 回答