2017-12-27 796 views
1

我有以下的PHP代碼:PHP無法發送UTF-8的消息

<?php 

$to  = '[email protected]'; 
$subject = date("d/m/Y"); 
$message = 'Hey 123 [email protected]# αβγ'; 

$headers = "From: testsite <[email protected]>\n"; 
$headers .= "Cc: testsite <[email protected]>\n"; 
$headers .= "X-Sender: testsite <[email protected]>\n"; 
$headers .= 'X-Mailer: PHP/' . phpversion(); 
$headers .= "X-Priority: 1\n"; // Urgent message! 
$headers .= "Return-Path: [email protected]\n"; // Return path for errors 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=iso-8859-1\n"; 

mail($to,$subject,$message,$headers); 

echo "<script type='text/javascript'>alert('Message sent! We will get back to you soon!');</script>"; 
echo "<script>window.location.href = 'http://example.com';</script>"; 
?> 

郵件被髮送罰款。問題是αβγ(Unicode字符)沒有正確收到郵件收件人的結尾。

這是收件人看到的是:Hey 123 [email protected]# αβγ 這是他應該明白:Hey 123 [email protected]# αβγ

我到處找用盡一切方法,改變標題,將我的字符串爲Unicode等等等等,但什麼事都沒有工作。也許我做錯了什麼?

+0

可能的問題與實際閱讀器? – GrumpyCrouton

+0

你正在使用錯誤的字符集。 –

+0

@FunkFortyNiner我該如何解決這個問題? –

回答

4

使用UTF-8字符集標題,例如:

$headers .= "Content-Type: text/html; charset=iso-8859-1\n"; 

業大:

$headers .= "Content-Type: text/html; charset=UTF-8\n";