2017-02-15 26 views
0

我用下面的代码来发送电子邮件:PHP mail();如何设置字符集为主题和电子邮件

<?php 
$to = $_POST['email']; 
$subject = "Subject!"; 
$message = "Hello!"; 
$headers = "From: Me<[email protected]>\r\n"; 
$headers .= "Return-Path: [email protected]\r\n"; 
$headers .= "BCC: [email protected]\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/plain; charset=utf-8\r\n"; 
mail($to,$subject,$message,$headers); 
?> 

虽然使用charset=utf-8在主题和电子邮件地址线的人物仍然没有得到解码对。我收到了这样的字符:ößä

如何设置主题和电子邮件地址的字符集呢?

+0

你检查所提供的答案吗?如果它是正确的,请接受它。谢谢! – Dekel

回答

3

要编码的电子邮件的主题,你应该使用:

$subject = '=?utf-8?B?'.base64_encode($subject).'?='; 

然后里面的mail功能:

mail($to,$subject,...); 
+0

我可以这样做:'mail($ to,'=?utf-8?B?'。base64_encode($ subject)。'?=',$ message,$ headers);'? – David

+1

是的,它是完全一样的 – Dekel

+0

我试着''到''相同,但似乎不工作。电子邮件以无法投递的方式返回。我能做什么? – David

相关问题