使用PHP从html表单发送电子邮件,当它们显示在gmail,yahoo等上时,sender_name +收件人_name +主题由正方形和其他符号组成。电子邮件地址和阿拉伯文的邮件正文都可以。
但是,出于测试目的,如果我在脚本本身中键入sender_name +收件人_name +主题,则它们将被核心显示。以下作品:
$sender_name="some arabic words here";
$sender_name='=?UTF-8?B?'.base64_encode($sender_name).'?=';
$recipient_name = "some arabic words here";
$recipient_name='=?UTF-8?B?'.base64_encode($recipient_name).'?=';
$subject = " arabic words ..";
$subject= '=?UTF-8?B?'.base64_encode($subject).'?=';
这不起作用:-
$sender_name=$_POST['sender_name'];
$sender_name='=?UTF-8?B?'.base64_encode($sender_name).'?=';
$recipient_name=$_POST['recipient_name'];
$recipient_name='=?UTF-8?B?'.base64_encode($recipient_name).'?=';
$subject=$_POST['subject'];
$subject= '=?UTF-8?B?'.base64_encode($subject).'?=';
更新: 我尝试过:-
$sender_name=$_POST['sender_name'];
$recipient_name=$_POST['recipient_name'];
$subject=$_POST['subject'];
$sender_name = mb_encode_mimeheader($sender_name,"UTF-8", "Q");
$recipient_name = mb_encode_mimeheader($recipient_name,"UTF-8", "Q");
$Subject = mb_encode_mimeheader($Subject,"UTF-8", "Q");
以下内容显示在gmail,yahoo,。:-
发件人姓名:=?UTF-8?B?PT9VVEYtOD9RPz0zRj0zRj0zRj0zRj0zRj0zRj0zRj0zRj0zRj0yMD0zRj0zRj
收件人姓名:=?UTF-8?B?PT9VVEYtOD9RPz0zRj0zRj0zRj89?=
主题:???= UTF-8乙PT9VVEYtOD9RPz0zRj0zRj0zRj0zRj0zRj0zRj0zRj0yMD0zRj0zRj0zRj0zRj0zRj0zRj0yMD0zRj0zRj0yMD0zRj0zRj0zRj89DQogPT9VVEYtOD9RPz0zRj0zRj0zRj0zRj0yMD0zRj0zRj0zRj0zRj0zRj0zR
问题出在表单所在的html文件中。它是Windows-1256编码的。使用iconv解决了如下问题。谢谢deceze!
$recipient_name = $_POST['$recipient_name'];
$recipient_name = iconv("windows-1256", "utf-8//TRANSLIT//IGNORE", $recipient_name);
$recipient_name = '=?UTF-8?B?'.base64_encode($recipient_name).'?=';
$sender_name = $_POST['$sender_name'];
$sender_name = iconv("windows-1256", "utf-8//TRANSLIT//IGNORE", $sender_name);
$sender_name = '=?UTF-8?B?'.base64_encode($sender_name).'?=';
$Subject = $_POST['$Subject'];
$Subject = iconv("windows-1256", "utf-8//TRANSLIT//IGNORE", $Subject);
$Subject = '=?UTF-8?B?'.base64_encode($Subject).'?=';