在PHP表单上遇到Cyrillic问题

时间:2017-06-09 08:45:51

标签: php html

当有人给我发送一封西里尔字母的电子邮件时,我会收到一些奇怪的信件。这是我的一部分:

HTML code:

<form method="post" action="index.php" id="formaa" accept-charset="UTF-8">

    <input name="name" placeholder="Name" id="aa">
    <input name="email" type="email" placeholder="E-mail" id="aa">      
    <textarea name="message" placeholder="Message"></textarea>      
    <input name="human" placeholder="2+2=" id="ab">
    <input id="submit" name="submit" type="submit" value="Submit">

</form>

PHP(满):

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: PappuLighting'; 
$to = 'v.karageorgiev@pappu-lighting.com'; 
$subject = 'Hello';
$human = $_POST['human'];
$headers .= "Content-Type: text/html; charset=utf-8";
$headers .= "Content-Transfer-Encoding: 8bit";

$body = "From: $name\n E-Mail: $email\n Message:\n $message";

if ($_POST['submit'] && $human == '4') {                 
    if (mail ($to, $subject, $body, $from)) { 
    echo '<p>Your message has been sent!</p>';
} else { 
    echo '<p>Something went wrong, go back and try again!</p>'; 
} 
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>

2 个答案:

答案 0 :(得分:0)

请更改:

$from = 'From: PappuLighting'; 

$headers = 'From: PappuLighting'; 

并改变:

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

要:

if (mail ($to, $subject, $body, $headers)) { 

答案 1 :(得分:0)

$from = 'From: PappuLighting';替换为$headers = 'From: PappuLighting';

同样if (mail ($to, $subject, $body, $from))if (mail ($to, $subject, $body, $headers))

https://www.w3schools.com/php/func_mail_mail.asp检查邮件功能的示例代码     

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";

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