[英]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.