# Message ID and In-Reply-To encoding issue (=?UTF-8?Q?)

**URL:** <https://discourse.laminas.dev/t/message-id-and-in-reply-to-encoding-issue-utf-8-q/1278>\
**Category:** Components & MVC\
**Tags:** zend-mail\
**Created:** [December 17, 2019, 1:25pm UTC](https://discourse.laminas.dev/t/message-id-and-in-reply-to-encoding-issue-utf-8-q/1278 "2019-12-17T13:25:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDCR](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@SDCR](https://discourse.laminas.dev/u/SDCR)\
**Post date:** [December 17, 2019, 1:25pm UTC](https://discourse.laminas.dev/t/message-id-and-in-reply-to-encoding-issue-utf-8-q/1278/1 "2019-12-17T13:25:48Z")

</div>

I am using zend mail to send/reply to emails.

I need to create a message-ID and set In-Reply-To. The code works, but when I check the results there is a weird encoding, which messes everything up.

How it looks like:

```
In-Reply-To: =?UTF-8?Q?<8a299e85f4f6b03a991740b10ed194bde9c21619@localhost.eu>?=
Message-ID: =?UTF-8?Q?<76251b6a8a859d4c2bd7ecd70a3aff811991d6b7@localhost.eu>?=

```

How it should look:

```
In-Reply-To: <8a299e85f4f6b03a991740b10ed194bde9c21619@localhost.eu>
Message-ID: <76251b6a8a859d4c2bd7ecd70a3aff811991d6b7@localhost.eu>

```

The code I use to create the message-ID:

```
$messageid = new Header\MessageId();

$messageid->setEncoding("UTF-8");

$_messageid = $messageid->createMessageId();

if (strpos($_messageid, "?UTF-8?")) {

    $_messageid = mb_decode_mimeheader($_messageid);

} 

$message->getHeaders()->addHeaderLine('Message-ID', '<' . $_messageid . '>');

```

I also tried to remove setEncoding, but no luck so far.

The code for In-Reply-To:

`$message->getHeaders()->addHeaderLine('In-Reply-To', $in_re_to);`

If I \Log::info($in\_re\_to) everything looks fine. I dont see these weird UTF-8? thing.

I am using Zend Mail V 2.3.

---

<div class="post-metadata">

**Author:** ![xerkus](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/xerkus/32/22_2.png) [@xerkus](https://discourse.laminas.dev/u/xerkus)\
**Post date:** [December 17, 2019, 7:51pm UTC](https://discourse.laminas.dev/t/message-id-and-in-reply-to-encoding-issue-utf-8-q/1278/2 "2019-12-17T19:51:09Z")

</div>

`->addHeaderLine()` handles value as a generic header. I think that is where wrong encoding happens.  
What you should try instead is to add header object directly:

```php
$messageid = new Header\MessageId();
$messageid->setId(null); // calls createMessageId() internally

$message->getHeaders()->addHeader($messageId);

```
