PHP - 附加的html字符串被切断

I'm generating some html to be used with the MPDF php library for generating a PDF. But when I create some HTML with php which has a loop inside it, it cuts of the beginning of the string, here's my code:

$page = "<div class='A4'><h1>Test: lookbook</h1><p>";
$page .= $date;

$page .= "</p><div class='items'>";

while ($the_query->have_posts()) {
    $the_query->the_post();
    $page .= "<img src='";
    $page .= get_field('product_image')['url'];
    $page .= "'>";
}
$page .= "</div></div><div class='footer'>A Story in every gemstone</div>";

echo $page;

Running the above code returns:

1<img src='urltoimage'></div></div><div class='footer'>A Story in every gemstone</div>

So it looks like everything before the while loop is being cut out.

$page is a Wordpress global variable that exists within The Loop.

https://codex.wordpress.org/Global_Variables

WordPress-specific global variables are used throughout WordPress code for various reasons. Almost all data that WordPress generates can be found in a global variable.

While inside the loop, these globals are set, containing information about the current post being processed.

...

$page (int) The page of the current post being viewed. Specified by the query var page.