UTF8 mailto中的特殊字符:subject = link和Outlook

时间:2023-01-06 14:37:33

I'm in the last stages of re-coding a site that formally used iso-8859-1 character encoding, but now is UTF-8 throughout.

我正在重新编码一个正式使用iso-8859-1字符编码的网站的最后阶段,但现在整个都是UTF-8。

The problem is that the subject section of the mailto href link is not working with Outlook, when special characters are used. I get the usual garbled character representations, indicative of an obvious character encoding issue when the link is clicked and the new mail window pops up in outlook.

问题是,当使用特殊字符时,mailto href链接的主题部分不能与Outlook一起使用。我得到了通常的乱码字符表示,指示单击链接时出现明显的字符编码问题,并在Outlook中弹出新的邮件窗口。

I've tried rawurlencode() to fix ths issue, but this doesn't seem to work with Outlook...

我已经尝试过rawurlencode()来修复这个问题,但这似乎不适用于Outlook ...

<a href="mailto:blah@blah.com?subject=<?=rawurlencode($subj);?>">send email</a>

So then thought, Outlook must insist on a different encoding, and tried utf-8 decoding the subject string first...

所以后来认为,Outlook必须坚持不同的编码,并尝试首先解码主题字符串的utf-8 ...

<a href="mailto:blah@blah.com?subject=<?=rawurlencode(utf8_decode($subj));?>">send email</a>

Bingo! Works great Outlook. But now fails in everything else :(

答对了!工作很棒Outlook。但现在其他一切都失败了:(

I can't find a solution that works accross all mail clients.

我找不到适用于所有邮件客户端的解决方案。

It worked fine across all mail clients when the whole page was displayed in iso-8859-1. But not when the page content is utf-8.

当整个页面显示在iso-8859-1中时,它在所有邮件客户端上都运行良好。但不是当页面内容是utf-8时。

Unfortunately the client wants to retain this direct email link, despite having a functioning mail form directly beneath it!

不幸的是,客户希望保留这个直接的电子邮件链接,尽管它下面有一个正常运行的邮件表单!

Is there a happy solution to this?

这有一个快乐的解决方案吗?

3 个解决方案

#1


9  

If you use utf-8 try this:

如果你使用utf-8试试这个:

<?php $subject = "=?UTF-8?B?" . base64_encode($subject) . "?="; ?>

#2


0  

The reason the subject line is sometimes garbled is because when you specify an encoding, it doesn't apply to the email header. Your subject line is in the email header. Here's a function to apply UTF8 encoding on the subject line:

主题行有时出现乱码的原因是,当您指定编码时,它不适用于电子邮件标题。您的主题行位于电子邮件标题中。这是在主题行上应用UTF8编码的函数:

function EncodeSubject($_subject)
{
    $encodedSubject = str_replace("&quot;", '"', $_subject);
    $encodedSubject = preg_replace('/[^x09\x20-\x3C\x3E-\x7E]/e', 'sprintf("=%02X", ord("$0"));', $encodedSubject);
    $encodedSubject = str_replace(' ', '_', $encodedSubject);
    return ="?utf-8?q" . $encodedSubject . "?=";
}

#3


-1  

You need to check following

你需要检查以下内容

1) HTML Code

1)HTML代码

<meta contentType="text/html; charset=UTF-8"/>

2) Browser Setting for IE View --> Encoding --> Unicode (UTF-8)

2)IE视图的浏览器设置 - >编码 - > Unicode(UTF-8)

3) Content Type / MIME Type should be "application/x-www-form-urlencoded"

3)内容类型/ MIME类型应为“application / x-www-form-urlencoded”

#1


9  

If you use utf-8 try this:

如果你使用utf-8试试这个:

<?php $subject = "=?UTF-8?B?" . base64_encode($subject) . "?="; ?>

#2


0  

The reason the subject line is sometimes garbled is because when you specify an encoding, it doesn't apply to the email header. Your subject line is in the email header. Here's a function to apply UTF8 encoding on the subject line:

主题行有时出现乱码的原因是,当您指定编码时,它不适用于电子邮件标题。您的主题行位于电子邮件标题中。这是在主题行上应用UTF8编码的函数:

function EncodeSubject($_subject)
{
    $encodedSubject = str_replace("&quot;", '"', $_subject);
    $encodedSubject = preg_replace('/[^x09\x20-\x3C\x3E-\x7E]/e', 'sprintf("=%02X", ord("$0"));', $encodedSubject);
    $encodedSubject = str_replace(' ', '_', $encodedSubject);
    return ="?utf-8?q" . $encodedSubject . "?=";
}

#3


-1  

You need to check following

你需要检查以下内容

1) HTML Code

1)HTML代码

<meta contentType="text/html; charset=UTF-8"/>

2) Browser Setting for IE View --> Encoding --> Unicode (UTF-8)

2)IE视图的浏览器设置 - >编码 - > Unicode(UTF-8)

3) Content Type / MIME Type should be "application/x-www-form-urlencoded"

3)内容类型/ MIME类型应为“application / x-www-form-urlencoded”