Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an umlaut ü in the mail subject

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("[email protected]");    

$mail->setSubject("The ï, ö, ë, ä, and é work, but when adding the ü it doesn't");

$recipients[] = "[email protected]";    
$mail->send($recipients);

&

$mail = new PHPMailer();
$mail->IsMail();
$mail->FromName = 'test';
$mail->From = '[email protected]';
$mail->AddAddress("[email protected]");
$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?

like image 723
Sander Avatar asked Nov 30 '12 13:11

Sander


People also ask

How do you type an umlaut in an email?

Press and release Ctrl and the colon (including the Shift key), and then press the vowel.

How do you type Ü?

Hold down the “alt” key on your keyboard and type one of these codes: ä : Alt + 0228. ö : Alt + 0246. ü : Alt + 0252.

Can you have umlauts in email addresses?

The use of non-ASCII characters in the local part of an email address is valid, but at this time the majority of popular email clients do not allow an address to be created with a non-ASCII character. For this reason, the support for sending to this type of email address has not been widely adopted.

Can email subjects have special characters?

Special characters are supported in the subject line, preheader, and body of your email. However, you should consider using them sparingly, as too many could land your email in your contacts' junk or spam folders. Did you know?


1 Answers

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.

like image 139
Timothy E. Johansson Avatar answered Sep 28 '22 23:09

Timothy E. Johansson