0

I'm sending an email using Zend Framework 2, using layout with properly set <META content="text/html; charset=UTF-8" http-equiv=Content-Type> in <head> tag.
When I put a link containing IP address in the content of the email, Outlook (365 version) stops recognizing charset properly and displays email in Western European (Windows) encoding.
Of course, if I change encoding in Actions -> Other Actions -> Encoding to UTF-8 it displays properly.
Do you happen to know, how to force Outlook to display the email in UTF-8?

When I change link to not contain IP address, Outlook recognizes UTF-8 encoding properly, the only problem is when the link contains IP address.
I checked it there is a problem only with $this->serverurl() method, but given the IP address is hardcoded, the effect is the same: no UTF-8 recognition.

Contents of the email (without layout):

<?php 
echo sprintf(
    $this->translate('scp.notification.done'),
    '<a href="'.$this->serverurl() . $this->url('system-change-proposal/view', array('id' => $this->id)) . '">' . $this->info['PROPOSAL_NUMBER'] . '</a><br/>',
    $this->info['CREATE_DATE'] . '<br/>',
    $this->info['TOPIC'] . '<br/>',
    $this->info['CONTENT']
); 
?>

Email displays like this (polish language with broken polish diacritic characters):

UWAGA. Wiadomość pochodzi z serwera DEWELOPERSKIEGO ZPB – prosimy ją zignorować! Dzień dobry, zrealizowaliśmy Twój wniosek o zmiany w ZPB o nr 2019/2 z dnia 2019-08-13 12:43:32 Tytuł: test Treść: testujemy różne rzeczy Jeżeli masz pytania dot. realizacji wniosku proszę o kontakt z Help Desk nr tel xxx xxx xxx

Full HTML of the email:

<!doctype html>
<html>
  <head>
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Simple Transactional Email</title>
    <style>
      /* -------------------------------------
          GLOBAL RESETS
      ------------------------------------- */
      img {
        border: none;
        -ms-interpolation-mode: bicubic;
        max-width: 100%; }

      body {
        background-color: #f6f6f6;
        font-family: sans-serif;
        -webkit-font-smoothing: antialiased;
        font-size: 14px;
        line-height: 1.4;
        margin: 0;
        padding: 0;
        -ms-text-size-adjust: 100%;
        -webkit-text-size-adjust: 100%; }

      table {
        border-collapse: separate;
        mso-table-lspace: 0pt;
        mso-table-rspace: 0pt;
        width: 100%; }
        table td {
          font-family: sans-serif;
          font-size: 14px;
          vertical-align: top; }

      /* -------------------------------------
          BODY & CONTAINER
      ------------------------------------- */

      .body {
        background-color: #f6f6f6;
        width: 100%; }

      /* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */
      .container {
        display: block;
        Margin: 0 auto !important;
        /* makes it centered */
        max-width: 800px;
        padding: 10px;
        width: 800px; }

      /* This should also be a block element, so that it will fill 100% of the .container */
      .content {
        box-sizing: border-box;
        display: block;
        Margin: 0 auto;
        max-width: 800px;
        padding: 10px; }

      /* -------------------------------------
          HEADER, FOOTER, MAIN
      ------------------------------------- */
      .main {
        background: #fff;
        border-radius: 3px;
        width: 100%; }

      .wrapper {
        box-sizing: border-box;
        padding: 20px; }

      .footer {
        clear: both;
        padding-top: 10px;
        text-align: center;
        width: 100%; }
        .footer td,
        .footer p,
        .footer span,
        .footer a {
          color: #999999;
          font-size: 12px;
          text-align: center; }

      /* -------------------------------------
          TYPOGRAPHY
      ------------------------------------- */
      h1,
      h2,
      h3,
      h4 {
        color: #000000;
        font-family: sans-serif;
        font-weight: 400;
        line-height: 1.4;
        margin: 0;
        Margin-bottom: 30px; }

      h1 {
        font-size: 35px;
        font-weight: 300;
        text-align: center;
        text-transform: capitalize; }

      p,
      ul,
      ol {
        font-family: sans-serif;
        font-size: 14px;
        font-weight: normal;
        margin: 0;
        Margin-bottom: 15px; }
        p li,
        ul li,
        ol li {
          list-style-position: inside;
          margin-left: 5px; }

      a {
        color: #3498db;
        text-decoration: underline; }

        .text-left {
          text-align: left;
        }
        .text-right {
          text-align: right;
        }
        .text-center {
          text-align: center;
        }
        .text-justify {
          text-align: justify;
        }
        .text-nowrap {
          white-space: nowrap;
        }

        .table {
          border-spacing: 0;
          border-collapse: collapse;
        }
        td,
        th {
          padding: 0.5em;
        }

        .zpb-table th {
            padding:7px;
            padding-top:4px;
            padding-bottom:4px;
            font-weight:bold;
            text-align:center;
            background-color:#F6F6F6;
            border-right: 1px solid #D2E9EF;
            box-shadow: 0px 2px 5px #888888;
        }

        .zpb-table td {
            vertical-align: middle !important;
        }

      .table-bordered th,
      .table-bordered td {
        border: 1px solid #ddd !important;
      }

        .alert {
          padding: 15px;
          margin-bottom: 20px;
          border: 1px solid transparent;
          border-radius: 4px;
        }

        .alert-warning {
          color: #8a6d3b;
          background-color: #fcf8e3;
          border-color: #faebcc;
        } 

      /* -------------------------------------
          BUTTONS
      ------------------------------------- */
      .btn {
        box-sizing: border-box;
        width: 100%; }
        .btn > tbody > tr > td {
          padding-bottom: 15px; }
        .btn table {
          width: auto; }
        .btn table td {
          background-color: #ffffff;
          border-radius: 5px;
          text-align: center; }
        .btn a {
          background-color: #ffffff;
          border: solid 1px #3498db;
          border-radius: 5px;
          box-sizing: border-box;
          color: #3498db;
          cursor: pointer;
          display: inline-block;
          font-size: 14px;
          font-weight: bold;
          margin: 0;
          padding: 12px 25px;
          text-decoration: none;
           }

      .btn-primary table td {
        background-color: #3498db; }

      .btn-primary a {
        background-color: #3498db;
        border-color: #3498db;
        color: #ffffff; }

      /* -------------------------------------
          OTHER STYLES THAT MIGHT BE USEFUL
      ------------------------------------- */
      .last {
        margin-bottom: 0; }

      .first {
        margin-top: 0; }

      .align-center {
        text-align: center; }

      .align-right {
        text-align: right; }

      .align-left {
        text-align: left; }

      .clear {
        clear: both; }

      .mt0 {
        margin-top: 0; }

      .mb0 {
        margin-bottom: 0; }

      .preheader {
        color: transparent;
        display: none;
        height: 0;
        max-height: 0;
        max-width: 0;
        opacity: 0;
        overflow: hidden;
        mso-hide: all;
        visibility: hidden;
        width: 0; }

      .powered-by a {
        text-decoration: none; }

      hr {
        border: 0;
        border-bottom: 1px solid #f6f6f6;
        Margin: 20px 0; }

      .table-bordered th,
      .table-bordered td {
        border: 1px solid #ddd !important;
      }

      /* -------------------------------------
          RESPONSIVE AND MOBILE FRIENDLY STYLES
      ------------------------------------- */
      @media only screen and (max-width: 620px) {
        table[class=body] h1 {
          font-size: 28px !important;
          margin-bottom: 10px !important; }
        table[class=body] p,
        table[class=body] ul,
        table[class=body] ol,
        table[class=body] td,
        table[class=body] span,
        table[class=body] a {
          font-size: 16px !important; }
        table[class=body] .wrapper,
        table[class=body] .article {
          padding: 10px !important; }
        table[class=body] .content {
          padding: 0 !important; }
        table[class=body] .container {
          padding: 0 !important;
          width: 100% !important; }
        table[class=body] .main {
          border-left-width: 0 !important;
          border-radius: 0 !important;
          border-right-width: 0 !important; }
        table[class=body] .btn table {
          width: 100% !important; }
        table[class=body] .btn a {
          width: 100% !important; }
        table[class=body] .img-responsive {
          height: auto !important;
          max-width: 100% !important;
          width: auto !important; }}

      /* -------------------------------------
          PRESERVE THESE STYLES IN THE HEAD
      ------------------------------------- */
      @media all {
        .ExternalClass {
          width: 100%; }
        .ExternalClass,
        .ExternalClass p,
        .ExternalClass span,
        .ExternalClass font,
        .ExternalClass td,
        .ExternalClass div {
          line-height: 100%; }
        .apple-link a {
          color: inherit !important;
          font-family: inherit !important;
          font-size: inherit !important;
          font-weight: inherit !important;
          line-height: inherit !important;
          text-decoration: none !important; }
        .btn-primary table td:hover {
          background-color: #34495e !important; }
        .btn-primary a:hover {
          background-color: #34495e !important;
          border-color: #34495e !important; } }

    </style>
    </head>
    <body class="">
        <table border="0" cellpadding="0" cellspacing="0" class="body">
            <tr>
                <td>&nbsp;</td>
                <td class="container">
                    <div class="content">
                        <table class="main">
                            <tr>
                                <td>
                                    <span style="color: #ee0000; font-size: 17px;">
                                        UWAGA. Wiadomość pochodzi z serwera DEWELOPERSKIEGO ZPB – prosimy ją zignorować!                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <td class="wrapper">Dzień dobry, zrealizowaliśmy Twój wniosek o zmiany w ZPB o nr <a href="http://zpb//scp/view/5613">2019/2</a><br/> z dnia 2019-08-13 12:43:32<br/> Tytuł: test<br/> Ttreść: testujemy różne rzeczy Jeżeli masz pytania dot. realizacji wniosku proszę o kontakt z Help Desk nr tel xxx xxx xxx<br/>
</td>
                            </tr>
                        </table>
                    </div>
                </td>
                <td>&nbsp;</td>
            </tr>
        </table>
    </body>
</html>

On production server $this->serverurl() will output normal address, but on test servers it will always output an IP address, which should not (but currently do) break the encoding recognition.

I checked and in webmail, problem is the same as in Outlook, GMail on the other hand displays it properly.
Maybe it could be an IMAP server config problem? I know nothing about such things.

I asked the same Question on Stackoverflow but after consideration I think it better suits in here.

Full headers taken out from Outlook email propeties:

Received: from 195.245.224.194 (HELO mx-1.tauron.pl) (195.245.224.194)
  by 94.152.180.72 with SMTP; 20 Aug 2019 07:27:18 -0000
Received: (qmail 43535 invoked by uid 1272007); 20 Aug 2019 07:27:18 -0000
Received: from poczta.tpe.corp (10.170.11.93) by
 TPCE-EXCA01V-TD-ZPB-new-version.tpe.corp (10.170.6.50) with Microsoft SMTP
 Server id 14.3.408.0; Tue, 20 Aug 2019 09:27:14 +0200
Received: from unknown (HELO poczta.tpe.corp) ([10.170.6.40])
  by mx-1.tauron.pl with ESMTP; 20 Aug 2019 09:27:15 +0200
From: "TD Zarzadzanie Praca Brygad" <td.powidomienia.zpb@tauron-dystrybucja.pl>
To: <agaller@arpus.pl>
Subject: Zrealizowano wniosek o zmiany 2019/2
Date: Tue, 20 Aug 2019 09:27:14 +0200
Message-ID: <9b640ef7-8f15-4891-bd9c-6cf6922fffb5@TPCE-EXCA01V.tpe.corp>
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="----=_NextPart_000_0000_01D5573A.4D3DE7C0"
X-Mailer: Microsoft Outlook 16.0
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on 3010302.s.tld.pl
X-Spam-Flag: YES
X-Spam-Level: *******
X-Spam-Report: =?ISO-8859-1?Q?
    * -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at
    *      https://www.dnswl.org/, no trust
    *      [195.245.224.194 listed in list.dnswl.org]
    * -1.5 BAYES_00 BODY: Bayesowskie prawdopodobie=f1stwo spamu wynosi 0 do
    *       1%
    *      [score: 0.0000]
    * -0.1 SPF_HELO_PASS SPF: HELO matches SPF record
    *  8.1 WEIRD_PORT URI: U=bfywa niestandardowego numeru portu dla HTTP
    *  0.7 MIME_HTML_ONLY BODY: Wiadomo=b6=e6 posiada tylko cz=ea=b6ci
    *      tekstowe/html MIME
    *  0.0 HTML_MESSAGE BODY: Wiadomo=b6=e6 zawiera kod HTML?=
X-Spam-Relay-Country: PL ** **
X-IronPort-AV: E=Sophos;i="5.64,408,1559512800"; 
   d="scan'208,217";a="76099017"
X-IronPort-AV: E=McAfee;i="6000,8403,9354"; a="76099017"
X-C2ProcessedOrg: 5199a320-9f4c-49ed-bc0e-d8ad42683a42
X-Spam-Status: Yes, score=7.2 required=5.0 tests=BAYES_00,HTML_MESSAGE, MIME_HTML_ONLY,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,WEIRD_PORT autolearn=disabled version=3.4.2
X-EsetId: 37303A29D5F1F66E61726A
Thread-Index: AQKbkkKOZgQGewYhh0xjSjHTj+sQ2w==

Additional info seen in "original message" display by GMail:

MIME-Version: 1.0
Content-Type: text/html
Content-Transfer-Encoding: 8bit
From: "TD Zarządzanie Pracą Brygad" <td.powidomienia.zpb@tauron-dystrybucja.pl>
To: <gallareton@gmail.com>
Subject: Zrealizowano wniosek o zmiany 2019/2

There is nothing about encoding here, charset is set only in <head> of the message.

  • What are the _headers_ of the email message like? The `` tag isn't always used by mail clients. – u1686_grawity Aug 20 '19 at 11:19
  • I added headers info from Outlook, is that what you're asking for? – Arkadiusz Galler Aug 20 '19 at 11:40
  • Close. I forgot that Outlook doesn't show the whole thing at once... Since the main headers have content-type multipart (as HTML messages generally do), each part has _its own_ Content-Type "sub-header" and its own charset= parameter, which Outlook probably won't show. Gmail would be able to show the whole message as-is, including the HTML part's own Content-Type header. – u1686_grawity Aug 20 '19 at 12:08
  • Added header info from GMail – Arkadiusz Galler Aug 20 '19 at 12:12
  • That doesn't look like the same kind of message at all though... (Could it be that your company's spam filter transforms it into multipart?) But it probably shows the problem anyway: you didn't specify the charset in the Content-Type header, which is what mail clients generally use. – u1686_grawity Aug 20 '19 at 12:18
  • @grawity Thank you very much for your help. Seems that antispam filter on mail server is changing the Content-Type of message (having not standard port in link automatically defines mail as spam) and causing charset to be not recognized. – Arkadiusz Galler Aug 20 '19 at 12:37

0 Answers0