[英]utf-8 mail php greek characters
我在我的網站上創建了一個表單。 我希望客戶能夠編寫和發送希臘字符,但在郵件中,我收到的是這樣的 Ï≥εÏ∞Ï≥ μεγ»εεεα 而不是希臘字符。 我嘗試使用以下代碼將編碼更改為 UTF-8:
mail($recipient, $subject, '=?UTF-8?B?'.base64_encode($content).'?=');
Thsis 代碼在另一台我測試過它的服務器上工作,但在我的服務器上不起作用。 有人可以幫忙嗎?
這是我的完整 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 ;
}
?>
主題或其他標頭字段值應使用編碼字句法,但正文則不會; 在那里你可以使用 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));
試試這個。
$header = 'Content-type: text/plain; charset=UTF-8' . "\r\n";
mail($recepient,$subject, '=?UTF-8?B?'.base64_encode($content).'?=', $header);
如果您要發送 html 電子郵件,請使用 Content-type: text/html。
$content
從哪里來? 在 mail() 之前,您是否做過任何不是多字節安全的substr($content)
之類的事情?
/* Set internal character encoding to UTF-8 */
mb_internal_encoding("UTF-8");
$headers = 'MIME-Version: 1.1';
$headers .= 'Content-type: text/html; charset=utf-8';
$headers .= "From: $name <$email>";
$headers .= "Return-Path: $emailTo";
$headers .= "Reply-To: $email";
$headers .= "X-Mailer: PHP/". phpversion();
希臘字符 φίλε μου 就是這種情況。 我編輯了郵箱的設置。 例如在 Roundcube Settings > Displaying Messages > Advanced Settings > Default Character Set = UTF-8 (Unicode)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.