emogrifier: False positives for content-type meta element presence check

I’ve recently updated Emogrifier and when moving from the old style syntax to the new, I receive this error: PHP Fatal error: Uncaught TypeError: Return value of Pelago\Emogrifier\CssInliner::getHeadElement() must be an instance of DOMElement, null returned in /var/www/vhosts/test.system/httpdocs/vendor/pelago/emogrifier/src/CssInliner.php:1293

Is there a reason there must always be a <head> element? https://github.com/MyIntervals/emogrifier/blob/b43b650880d189b0ada61d95d0729c7424b1752d/src/CssInliner.php#L1291

I’m just inlining CSS in a simple email template that doesn’t use a <head> element for anything. I’ve added a blank one for now but strikes me as a little arbitrary.

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@JakeQZ I’ve hit this error again and can replicate it with this HTML - https://gist.github.com/bbeckford/eea6c7a1a8a4957166050dda413a9af1

Code to reproduce:

$template_body_processed = CssInliner::fromHtml(file_get_contents("email.html"))->inlineCss($css)->render();

This produces the following error:

Fatal error: Uncaught TypeError: Return value of Pelago\Emogrifier\CssInliner::getHeadElement() must be an instance of DOMElement, null returned in /var/www/vhosts/redacted/httpdocs/vendor/pelago/emogrifier/src/CssInliner.php on line 1293
TypeError: Return value of Pelago\Emogrifier\CssInliner::getHeadElement() must be an instance of DOMElement, null returned in /var/www/vhosts/redacted/httpdocs/vendor/pelago/emogrifier/src/CssInliner.php on line 1293

Version info from composer.lock: (running PHP v7.3.27)

        "name": "pelago/emogrifier",
        "version": "v5.0.0",
        "source": {
            "type": "git",
            "url": "https://github.com/MyIntervals/emogrifier.git",
            "reference": "b43b650880d189b0ada61d95d0729c7424b1752d"
        },

Hey thanks for the fix @JakeQZ 😃

@bbeckford Thanks! We’ll have a look at the problem.

Hi @oliverklee included html is here - https://gist.github.com/bbeckford/eea6c7a1a8a4957166050dda413a9af1

I haven’t included the CSS at this stage as I’d have to comb through it to make sure it was ok for public consumption, let me see if I can reproduce with something simpler…

Hi @JakeQZ - sorry for the delay.

Strange, I can’t seem to replicate this now! The dev environment I was testing on has moved on now so there’s no way for me to know for sure but perhaps I was using an older version at the time,

Now definitely using emogrifier v5.0.0 and the snippet above does work.

I’ve removed this line from the code I was working on and I will let you know if this ever reoccurs on any of my instances: image

Thanks for your help!