繁体   English   中英

在我的PHP表单上遇到西里尔字母问题

[英]Having problems with Cyrillic on my PHP form

当有人用西里尔文给我发送电子邮件时,我收到了一些奇怪的来信。 这是我的一部分:

HTML代码:

<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>';
}
?>

请更换:

$from = 'From: PappuLighting'; 

$headers = 'From: PappuLighting'; 

并更改:

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

至:

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

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

也是if (mail ($to, $subject, $body, $from)) To 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);
?>

暂无
暂无

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

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