<form>

时间:2019-01-20 16:25:26

标签: php html forms utf-8

我已经填写了联系表格,但由于我不是英语,所以我使用诸如“á”,“ň”,“š”等字符。 但是,当我用这些字符填写表单时,我提交了表单,并收到了电子邮件,其中所有这些“未知”字符都被替换为“ @-”之类的字符。该网站是.html,而不是.php。我不在数据库中存储任何内容。

我放了
<meta charset="UTF-8">以及
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> in the <head>
我也将<form>属性修改为<form id="contact-form" action="send_me" enctype="multipart/form-data" accept-charset="utf-8">
然后将header('Content-type: text/html; charset=utf-8');添加到了我的php文件中。
但是没有任何帮助。

这是一段HTML:

<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />




<form id="contact-form" action="send_me" enctype="multipart/form-data" accept-charset="utf-8">
    <div class="field-group">
    <div class="inputgroup">
            <label for="name">Name</label>
            <input id="name" class="text form-input" type="name" name="name"/>
    </div>
    </div>
    <div class="field-group">
    <div class="inputgroup">
        <label for="message">Message</label>
        <textarea id="message" class="text form-input" type="message" name="message">
        </textarea>
    </div>
    </div>
    <div class="field-group">
    <div class="contact-form__button" style="">
        <input role="button" type="submit" name="submit">
    </div>
    </div>
    <div id="odo" class="contact-form__message"></div>
</form>


JS:

$(".form-input").focus(function() {
    let parent = $(this).parent();
    if (!parent.hasClass("active")) {
        parent.addClass("active")
        }
 });
 $(".form-input").blur(function() {
    let self = $(this);
    let parent = self.parent();
    if (parent.hasClass("active") && self.val().length === 0) {
        parent.removeClass("active")
    }
 });
 $("#contact-form").submit(function(e) {
    e.preventDefault();
    const url = "sendMailB.php";
    messageHolder = $(".contact-form__message");
    messageHolder.removeClass();
    messageHolder.text('');
    const successMessage = 'Successfully sent!';
    const errorMessage = 'Oops, try later';
    $.ajax({
        type: "POST",
        url: url,
        data: $("#contact-form").serialize(),
        success: function(data) {
            console.log(data);
                        messageHolder.addClass("success");            
                        messageHolder.text(successMessage);
        },
        error: function(error){
        console.log('error');
        messageHolder.addClass("error");
        messageHolder.text(errorMessage);
            }
    });
 });


PHP:

header('Content-type: text/html; charset=utf-8');
$to = "paula@soulmates.sk";
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$extra = "From email: $email\r\n Answer to email: $email\r\n";<br>
$subject = "Mail from ".$name."";
$odkaz = $message;
$mess = "Name: ".$name."\nEmail: ".$email."\nPhone: ".$phone."\nMessage: ".$odkaz." \n";

$too = $email;
$subjectt = "Thank you for contacting us";
$messs = "Thank you message";
$extraa = "From email: $to\r\n Answer to email: $to\r\n";


mail ($to, $subject, $mess, $extra)
mail ($too, $subjectt, $messs, $extraa);

?>

我只需要用户输入的所有信息即可按原样接收信息。我需要“Safaládka”在收到的电子邮件中保留“Safaládka”,而不要变成例如“ SafalˇA-dka”

1 个答案:

答案 0 :(得分:1)

将标头作为邮件功能中的第四个参数传递。

mail ($to, $subject, $mess, $header);