How to set an umlaut ü in the mail subject

不想你离开。 提交于 2019-12-18 12:33:17

问题


I need to generate German e-mails which contain umlaut characters. In the e-mail itself this works perfectly, but not in the subject of the e-mail. I've tried many different umlaut letters and they all seem to work except for the ü. I also tried different mail libraries (HTMLMimeMail & PHPMailer) and they both fail at this:

$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();

Can anyone help me find the source of and the solution to this problem?


回答1:


You should quoted-printable encode the subject header.

Like this:

$mail->Subject = "=?UTF-8?Q?" . quoted_printable_encode("The ï, ö, ë, ä, and é work, but when adding the ü it doesn't") . "?=";

Quoted printable encode in PHP: http://www.php.net/manual/en/function.quoted-printable-encode.php

Edit: $mail->CharSet = "UTF-8"; did the job.



来源:https://stackoverflow.com/questions/13645869/how-to-set-an-umlaut-%c3%bc-in-the-mail-subject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!