繁体   English   中英

PHP-表单显示符号而不是字母

[英]PHP - Form shows symbols instead of letters

问候我需要有关PHP表单文本编码的帮助。 当我通过表单发送电子邮件时-我收到的电子邮件中没有某些字符,例如“±čęėįšų”。 到目前为止,这是我尝试过的:

<!doctype html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Kontaktai</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/main.css">
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script src="js/main.js"></script>
</head>
<body class="one">
<div id="holder">
    <div id="full-width-background">
        <div class="container">
        <?php include 'header.php';?>

        <?php
    if (isset($_POST["submit"])) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $human = intval($_POST['human']);
        $from = 'ITConnect'; 
        $from .= 'Content-Type: text/html; charset="UTF-8"';
        $from .= 'Content-Transfer-Encoding: 7bit';  
        $to = 'mail@mail.lt'; 
        $subject = 'Kliento kontaktas';
        $body = "Nuo: $name\n\n Adresatas: $email\n\n Tekstas:\n $message";
        // Check if name has been entered
        if (!$_POST['name']) {
            $errName = 'Įveskite savo vardą';
        }
        // Check if email has been entered and is valid
        if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
            $errEmail = 'Įveskite teisingą el. pašto adresą';
        }
        //Check if message has been entered
        if (!$_POST['message']) {
            $errMessage = 'Parašykite žinutę';
        }
        //Check if simple anti-bot test is correct
        if ($human !== 5) {
            $errHuman = 'Anti-Spam atsakymas neteisingas';
        }
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
    if (mail ($to, $subject, $body, $from)) {
        $result='<div class="alert alert-success">Dėkojame, žinutė išsiūsta! Atsakysime per vieną darbo dieną.</div>';
    } else {
        $result='<div class="alert alert-danger">Žinutė nebuvo išsiūsta. Atsiprašome už nesklandumus.</div>';
    }
}
    }

如果我在消息中发送的是“±ąčaac”之类的信息,我收到的是:??? aac。 请协助!

我想问题是您没有明确设置邮件的内容类型...

而不是使用

if (mail($to, $subject, $body, $from)) {
   ...
}

尝试这个:

$headers = "From: $from <$from>\r\n". 
           "MIME-Version: 1.0" . "\r\n" . 
           "Content-type: text/html; charset=UTF-8" . "\r\n"; 
if (mail($to, $subject, $body, $headers)) {
   ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM