PHP mail();如何设置主题和电子邮件的字符集 [英] PHP mail(); How to set charset for subject and email

查看:64
本文介绍了PHP mail();如何设置主题和电子邮件的字符集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码发送电子邮件:

I'm using the following code to send an e-mail:

<?php
$to = $_POST['email'];
$subject = "Subject!";
$message = "Hello!";
$headers = "From: Me<example@example.com>\r\n";
$headers .= "Return-Path: example@example.com\r\n";
$headers .= "BCC: example@example.com\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主题和电子邮件地址行中的字符仍无法正确解码.我收到这样的字符:ößä.

Although using charset=utf-8 the characters in the subject and the email address line still doesn't get decoded right. I'm getting characters like this: ößä.

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

How can I set the charset for subject and email address line, too?

推荐答案

要对电子邮件的主题进行编码,您应该使用:

To encode the subject of an email you should use:

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

然后在mail函数内部:

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

这篇关于PHP mail();如何设置主题和电子邮件的字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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