我在我的网站上创建了一个表单。我希望客户能够编写和发送希腊字符,但在邮件中我收到类似 Ï≥εÏ∞Ï≥ ελληÎ∏Î'κα 而不是希腊字符。我尝试使用以下代码将编码更改为 UTF-8:
mail($recipient, $subject, '=?UTF-8?B?'.base64_encode($content).'?=');
这个代码在我测试过的另一台服务器上工作,但在我的服务器上不起作用。有人可以帮忙吗?
这是我的完整 php 代码
<?php
if ((isset($_POST['name'])) && (strlen(trim($_POST['name'])) > 0)) {
$name = stripslashes(strip_tags($_POST['name']));
} else {$name = 'No name entered';
}
if ((isset($_POST['lastname'])) && (strlen(trim($_POST['lastname'])) > 0)) {
$lastname = stripslashes(strip_tags($_POST['lastname']));
} else {$lastname = 'No name entered';
}
if ((isset($_POST['nomos'])) && (strlen(trim($_POST['nomos'])) > 0)) {
$nomos = stripslashes(strip_tags($_POST['nomos']));
} else {$nomos = 'No name entered';
}
if ((isset($_POST['polh'])) && (strlen(trim($_POST['polh'])) > 0)) {
$polh = stripslashes(strip_tags($_POST['polh']));
} else {$polh = 'No name entered';
}
if ((isset($_POST['address'])) && (strlen(trim($_POST['address'])) > 0)) {
$address = stripslashes(strip_tags($_POST['address']));
} else {$address = 'No name entered';
}
if ((isset($_POST['TK'])) && (strlen(trim($_POST['TK'])) > 0)) {
$TK = stripslashes(strip_tags($_POST['TK']));
} else {$TK = 'No name entered';
}
if ((isset($_POST['email'])) && (strlen(trim($_POST['email'])) > 0)) {
$email = stripslashes(strip_tags($_POST['email']));
} else {$email = 'No email entered';
}
if ((isset($_POST['phone'])) && (strlen(trim($_POST['phone'])) > 0)) {
$phone = stripslashes(strip_tags($_POST['phone']));
} else {$phone = 'No phone entered';
}
if ((isset($_POST['sxolia'])) && (strlen(trim($_POST['sxolia'])) > 0)) {
$sxolia = stripslashes(strip_tags($_POST['sxolia']));
} else {$sxolia = 'Δεν υπάρχουν σχόλια';
}
ob_start();
?>
<html>
<head>
<style type="text/css">
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table width="550" border="1" cellspacing="2" cellpadding="2">
<tr bgcolor="#eeffee">
<td>Όνομα</td>
<td><?=$name; ?></td>
</tr>
<tr bgcolor="#eeffee">
<td>Επίθετο</td>
<td><?=$lastname; ?></td>
</tr>
<tr bgcolor="#eeffee">
<td>Νομός</td>
<td><?=$nomos; ?></td>
</tr>
<tr bgcolor="#eeffee">
<td>Πόλη</td>
<td><?=$polh; ?></td>
</tr>
<tr bgcolor="#eeffee">
<td>Διεύθυνση</td>
<td><?=$address; ?></td>
</tr>
<tr bgcolor="#eeffee">
<td>T.Κ</td>
<td><?=$TK; ?></td>
</tr>
<tr bgcolor="#eeffee">
<td>Τηλέφωνο</td>
<td><?=$phone; ?></td>
</tr>
<tr bgcolor="#eeffee">
<td>Email</td>
<td><?=$email; ?></td>
</tr>
<tr bgcolor="#eeffee">
<td>Σχόλια</td>
<td><?=$sxolia; ?></td>
</tr>
</table>
</body>
</html>
<?
$body = ob_get_contents();
$to = 'mymail@yahoo.gr';
$email = 'mymail@yahoo.gr';
$fromaddress = "address";
$fromname = "Online Contact";
require ("phpmailer.php");
$mail = new PHPMailer();
$mail -> From = "address";
$mail -> FromName = "Book Order";
$mail -> AddAddress("mymail@gmail.com", "Name 5");
$mail -> WordWrap = 50;
$mail -> IsHTML(true);
$mail -> Subject = "Book Form: Book form submitted";
$mail -> Body = $body;
$mail -> AltBody = "This is the text-only body";
if (!$mail -> Send()) {
$recipient = 'mymail@yahoo.gr';
$subject = 'Contact form failed';
$content = $body;
$header = 'Content-type: text/html; charset=UTF-8' . "\r\n";
mail($recepient,$subject, '=?UTF-8?B?'.base64_encode($content).'?=', $header);
exit ;
}
?>