我需要生成包含变音字符的德语电子邮件。在电子邮件本身,这种方法很完美,但不是电子邮件的主题。我尝试了许多不同的变音字母,除了ü外,它们似乎都有效。我也尝试过不同的邮件库(HTMLMimeMail和PHPMailer),但他们都失败了:
$mail = new htmlMimeMail();
$mail->setTextEncoding("base64");
$mail->setHTMLEncoding("base64");
$mail->setTextCharset("UTF-8");
$mail->setHTMLCharset("UTF-8");
$mail->setHeadCharset("UTF-8");
$mail->setSMTPParams(mailinglist_smtp_host,mailinglist_smtp_port);
$mail->setHtml("test");
$mail->setFrom("test@test.nl");
$mail->setSubject("The ï, ö, ë, ä, and é work, but when adding the ü it doesn't");
$recipients[] = "me@myhost.nl";
$mail->send($recipients);
&安培;
$mail = new PHPMailer();
$mail->IsMail();
$mail->FromName = 'test';
$mail->From = 'test@test.nl';
$mail->AddAddress("me@myhost.nl");
$mail->Subject = "The ï, ö, ë, ä, and é work, but when adding the ü it doesn't";
$mail->Body = "test";
$mail->Send();
任何人都可以帮我找到这个问题的来源和解决方案吗?
答案 0 :(得分:10)
您应quoted-printable对主题标题进行编码。
像这样:
$mail->Subject = "=?UTF-8?Q?" . quoted_printable_encode("The ï, ö, ë, ä, and é work, but when adding the ü it doesn't") . "?=";
引用PHP中的可打印编码:http://www.php.net/manual/en/function.quoted-printable-encode.php
编辑:$mail->CharSet = "UTF-8";
完成了这项工作。