How Can I Place A MYSQL Database Record In A Variable With PHP? : <p>I need some assistance with my code here. I'm using a mail() function to send a welcome email to a registrant.</p>

<p>My mailer script looks like this:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php

$to = print require("includes/email.php");

$subject = "This is where I have my subject";

$txt = "Greetings
		"."\n"."
		Thank you for registering.
		"."\n"."
		This is some of my text
		"."\n"."
		Best Regards
		Admin";
$headers = "From: email@domain.com";

mail($to,$subject,$txt,$headers);

header("Location: pay.php");

?&gt;</code></pre>
</div>
</div>
</p>

<p>and my includes/email.php code looks like this:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
$conn = mysqli_connect('localhost', 'username', 'password', 'database');
// Check connection
if ($conn-&gt;connect_error) {
die('Connection failed: ' . $conn-&gt;connect_error);
} 

$sql = 'SELECT email_address FROM table WHERE id=(SELECT MAX(id) FROM `table`)';

$result = $conn-&gt;query($sql);
if ($result-&gt;num_rows &gt; 0) {
// output data of each row
while($row = $result-&gt;fetch_assoc()) {
echo $row['email_address'];
}}
$conn-&gt;close();
?&gt;</code></pre>
</div>
</div>
</p>

<p>Now I want my $to variable to have the email_address record from my database and for the mail() function to send an email to that email when the mailer script is run. When I run the script, an email is displayed on the screen and no email is sent but everything works when I manually put an email address on the $to variable. How can I successfully get the script to send the email to the requested email on the database?</p>
