After another couple of hours realised that the echo statement was having trouble handling the “-” symbol in the header names. Those created automatically by the plugin included an underscore instead, and therefore the problem didn’t arise. Those custom ones whose headers were generated automatically by the plug in for some reason included hyphens rather than underscores. Annoying but rectified by putting the header name in a sting without hyphens.
Problem sorted.