我有这个网页。
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Send Email</title>
</head>
<body>
<form method="GET">
<input type="text" name="myEmail" placeholder="Имейл"/><br>
<input type="text" name="recieverEmail" placeholder="Получател"/><br>
<input type="text" name="subject" placeholder="Предмет"/><br>
<textarea rows="4" cols="50" name="message" placeholder="Съобщение"></textarea><br>
<input type="submit" name="button" value="send"/>
</form>
<?php
if(isset($_GET['button'])){
$sender = $_GET['myEmail'];
$reciever = $_GET['recieverEmail'];
$subject = $_GET['subject'];
$message = $_GET['message'];
$headers = "From: " . $sender . "\r\n";
mail($reciever, $subject, $message, $headers);
}
?>
</body>
</html>
我从html表单中获取数据。我需要一种方法来将电子邮件的编码设置为UTF-8,因为当我想用保加利亚语发送电子邮件时,它不会转换为保加利亚语。有任何想法吗?提前谢谢。
答案 0 :(得分:0)
在代码中再添加一个header属性,如下所示:
if(isset($_GET['button'])){
$sender = $_GET['myEmail'];
$reciever = $_GET['recieverEmail'];
$subject = $_GET['subject'];
$message = $_GET['message'];
$headers = "From: " . $sender . "\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8"; //check this header attribute. It will append to the `From` header.
mail($reciever, $subject, $message, $headers, $encoding);
}