Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-20854

CiviMail Track Opens breaks the mailing HTML

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 4.7.21
    • Fix Version/s: None
    • Component/s: CiviMail
    • Labels:
      None
    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      User and Admin Doc
    • Funding Source:
      Contributed Code
    • Verified?:
      No

      Description

      The "Track Opens" functionality in CiviMail inserts a tiny image at the end of the mailing. When the recipient opens the email message, the image is loaded through the sender's server and this is how CiviMail knows that the email message was opened.

      The problem is with where the HTML code for the image is inserted. Currently, it is appended to the end of the mailing's HTML code. In /civicrm/CRM/Mailing/BAO/Mailing.php:

      array_push($html, "\n" . '<img src="' . $config->userFrameworkResourceURL . "extern/open.php?q=$event_queue_id\" width='1' height='1' alt='' border='0'>" );

      $html is an array with the mailing's full HTML code. Since the image is pushed to the end, we have an undesirable situation where the code of the mailing becomes something like:

      <html>
      <body>
      blah blah
      </body>
      </html>
      <img src="https://myserver.com/image.jpg">

      The proper place for the <img> tag is clearly somewhere between the <body> tags. This is important because broken HTML may lower the sender's reputation with inbox providers like Gmail, Yahoo and such.

      So is there a string that we can be certain always exists so that we can add the image next to it? The most reliable string I can think of is "</body>". If we insert the image right before it, the HTML will look good.

      A potential problem arises if people do not use the surrounding tags like <html> and <body>. So, to help educate them about the importance of these tags, we can add some further explanation in the help text for the Track Opens option. Something like:

       

      Track the number of times recipients open this mailing in their email software.
      
      This option inserts a tiny image at the end of your mailing. When the recipient opens the email message, the image is loaded through your server and this is how CiviMail knows that the email message was opened. However, if images are blocked on the recipient's end (as sometimes they are by default), they might read the email message without CiviMail registering that it was read.
      The image will be inserted right before the closing </body> HTML tag.
      

       

      If this sounds good, I can submit a patch.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              borislavzlatanov Borislav Zlatanov
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: