title: Using PHP code in the value of a variable
body: <p>I am trying to send an email in PHP where the content of the email has some conditional checks and some database query lookups. </p>
  
  <p>What I would like to acheive is having my email code as a variable (similar to below) so that I can sent mail() the content to the relevant people.</p>
  
  <pre><code> $emailContent = "&lt;p&gt;My email content&lt;/p&gt;";
  </code></pre>
  
  <p>However the value of this variable would have some code like this:</p>
  
  <pre><code> &lt;table&gt;
  &lt;?php
        $get_course_units     = "SELECT * FROM course_units where course_units.course_code = {$courseCodeExtract}";
        $course_units_results = $conn-&gt;query($get_course_units);
        if ($course_units_results-&gt;num_rows &gt; 0) {
            while ($courseUnits = $course_units_results-&gt;fetch_assoc()) {
   ?&gt;
        &lt;tr&gt;
             &lt;td&gt;&lt;?php echo $courseUnits["unit_code"]; ?&gt; – &lt;?php echo $courseUnits["unit_name"]; ?&gt; &lt;/td&gt;
        &lt;/tr&gt;
      &lt;?php
       } //end loop for course units
   } //end if for course units
   ?&gt;
   &lt;/table&gt;
  </code></pre>
  
  <p>How should I continue?</p>