utf-8邮件php希腊字符 [英] utf-8 mail php greek characters

查看:96
本文介绍了utf-8邮件php希腊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im在我的网站中创建一个表单.我希望客户能够书写和发送希腊字符,但是在邮件中我会收到类似Ï≥α∞∞≥Îαβαβα的信息,而不是希腊字符.我尝试使用以下代码将编码更改为UTF-8:

im creating a form in my site. I want the costumers to be able to write and send Greek characters but in the mail im getting something like this Ï≥εÏ∞Ï≥ ελληÎ∏Βκα istead of greek characters. I tryed to change the encoding to UTF-8 with this code:

mail($recipient, $subject, '=?UTF-8?B?'.base64_encode($content).'?=');

Thsis代码可在另一台经过我测试的服务器中使用,但不能在我的服务器中使用.有人可以帮忙吗?

Thsis code works in another server that ive tested it but doesnt work in my server. Can anybody help?

这是我完整的php代码

Here is my full php code

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

推荐答案

编码字语法对于主题或其他标题字段值是期望的,但对于正文不是期望的;在那里,您可以使用MIME和 Content-Type :

$headerFields = array('MIME-Version: 1.0', 'Content-Type: text/plain;charset=utf-8');
mail($recipient, '=?UTF-8?B?'.base64_encode($subject).'?=', $content, implode("\r\n", $headerFields));

这篇关于utf-8邮件php希腊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆