【发布时间】:2015-05-10 11:40:40
【问题描述】:
这就是全部内容。由于我从今天开始使用 PHP,因此我面临着这个问题。 我已经为我工作的 ISP 公司建立了一个表格,它通过电子邮件发送表格结果。客户填写此表格以向我们请求新服务。由于公司是外国(保加利亚),99% 的人都会用 Cyrillic 填写,所以我自己填写了测试,并收到了这封电子邮件。
发件人:DÑD´
电话号码:56
选定的服务:
互联网:100 ||电视:舒适
留言:
ЪЕÐÐÐÐС
所以我做了一些研究,在 StackOverflow 中查看了其他一些关于此的帖子,但没有一个有效......大多数建议添加
$header .= "\nContent-type: text/plain; charset=\"utf-8\"";
一个问题是我不确定如何实施这个解决方案,第二个问题是它对提出问题的人不起作用,甚至在我审查的一个问题中也不起作用。
这是 PHP 代码和 HTML 代码,希望您能给我一个确切的修复方法,因为我几乎不知道 PHP 的语法。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Online Request</title>
<meta content="php, contact, form, thinking" name="keywords">
<meta content="Contact us and let us know if we can help you out further." name="description">
<style>
input, textarea {
color: #fff;
padding: 5px;
margin: 10px;
font-family: Cambria, Cochin, serif;
font-size: medium;
font-weight: bold;
outline: none;
}
p {
font-family: Cambria, Cochin, serif;
font-size: large;
margin-bottom: -5px;
}
input[type=text], textarea {
width: 350px;
background-color: #000;
border: 1px solid #000;
}
input[type=submit] {
width: 100px;
background-color: #710000;
border: 1px solid #000;
font-size: large;
color: #FFFFFF;
}
input[type=submit]:hover {
background-color: #990000;
cursor: pointer;
}
input[type=submit]:active {
background-color: #4A6F00;
}
h1 {
text-size: 26px;
font-family: Arial;
text-shadow:
-1px -1px 0 #000,
1px -1px 0 #000,
-1px 1px 0 #000,
1px 1px 0 #000;
color: #ff0000;}
body {
padding: 10px;
background-color: #F4F4F4;
}
.checkbox {
font-family: Cambria, Cochin, serif;
font-size: large;
margin-bottom: -5px;
}
</style>
</head>
<body>
<h1>Online Request</h1>
<form action="emailer.php" method="POST" accept-charset="UTF-8">
<div>
<p>Имена</p>
<input name="name" type="text"> <br>
</div>
<div>
<p>Телефон за връзка</p>
<input type="text" name="number" min="10" max="10">
<br>
</div>
<div>
<p> Вид услуга - Internet </p> <br/>
<input name="servicetypeINT" type="radio" value="30"><span class="checkbox"> Internet Value - 30Mpbs </span> <br/>
<input name="servicetypeINT" type="radio" value="60"><span class="checkbox"> Internet Mania - 60 Mbps </span><br/>
<input name="servicetypeINT" type="radio" value="100"><span class="checkbox"> Internet Extreme - 100Mbps</span> <br/>
<input name="servicetypeINT" type="radio" value="150"><span class="checkbox"> Internet Pro - 150Mpbs</span><br/>
</div>
<hr/>
<div>
<p>Вид услуга - Телевизия</p> <br/>
<input name="servicetypeTV" type="radio" value="anal"><span class="checkbox"> Аналогова телевизия - 50 канала </span> <br/>
<input name="servicetypeTV" type="radio" value="start"><span class="checkbox"> Start TV - 40+ Цифрови канала </span><br/>
<input name="servicetypeTV" type="radio" value="comfort"><span class="checkbox"> Confort TV - 160+ Цифрови канала</span> <br/>
<input name="servicetypeTV" type="radio" value="mania"><span class="checkbox"> Mania TV - 160+ Цифрови / 20+ HD канала</span><br/>
</div>
<div>
<p>Comment</p>
<textarea cols="30" name="comment" rows="9"></textarea>
<br> </div>
<div>
<input name="submit" type="submit" value="Изпрати"> </div>
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])) {
$to = "denislav@svishtov.net";
$subject = "New Internet and/or TV request";
// data the visitor provided
$name_field = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$phone_field = filter_var($_POST['number']);
$selectedINT_field = filter_var($_POST['servicetypeINT']);
$selectedTV_field = filter_var($_POST['servicetypeTV']);
$comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
//constructing the message
$body = "
From: $name_field\n\n
Phone number: $phone_field\n\n
Selected Services:\n\nInternet: $selectedINT_field || TV: $selectedTV_field \n\n
Message:\n\n $comment ";
// ...and away we go!
mail($to, $subject, $body);
// redirect to confirmation
header('Location: confirmation.html');
} else {
// handle the error somehow
echo "Грешка в попълването на формата";
}
?>
另一个有趣的事实是,当我从本地机器打开文件时(因为如果我从在线托管的机器上尝试,我会得到错误回显)php 代码本身中的西里尔文文本显示就像电子邮件结果一样... 但是当我从主机打开它时,通过直接解决它,我得到了正确的错误消息......保加利亚语......没有任何乱码。
PHP 中的代码行
header('Content-Type: text/html; charset=utf-8');
似乎转换了标题消息。我尝试寻址$name_field('Content-Type: text/html; charset=utf-8');
但结果是空白,php 无法正常运行,我猜是因为我给了它一个错误或无法操作的代码行,地址为$name_field。
问题是,我该如何正确解决这个问题,而且我什至可以通过这种方法走上正确的轨道?
【问题讨论】: