title: How to get PHP variable from another file?
body: <p>I'm trying to make a forgot password system with PHPMailer on xampp.
  But when I send an email,the email body is a html mail template,what I get from another file <code>$mail-&gt;Body = file_get_contents('mail_template.php');</code>,and I have problem,because I don't know how should I get the data of the <code>$url</code> variable and send it to <code>mail_template.php</code> file to use it for the link in the mail.
  I tried the <code>include 'filename.php';</code> command,but haven't worked.</p>
  <p>Here is the code:</p>
  <pre><code>if (isset($_POST[&quot;submitButton&quot;])) {
      $emailTo = $_POST[&quot;email&quot;];
  
      $code = md5(uniqid(rand(), true));
      $query = $con-&gt;prepare(&quot;INSERT INTO resetpasswords(code,email) VALUES('$code', '$emailTo')&quot;);
      $query-&gt;execute();
      if (!$query) {
          exit(&quot;Something went wrong...&quot;);
      }
  
      $mail = new PHPMailer(true);
  
      try {
          //Server settings                                           // Enable verbose debug output
          $mail-&gt;isSMTP();                                            // Send using SMTP
          $mail-&gt;Host = 'smtp.gmail.com';                    // Set the SMTP server to send through
          $mail-&gt;SMTPAuth = true;                                   // Enable SMTP authentication
          $mail-&gt;Username = 'mail@gmail.com';                     // SMTP username
          $mail-&gt;Password = 'password';                               // SMTP password
          $mail-&gt;SMTPSecure = 'ssl';         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
          $mail-&gt;Port = 465;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
  
          //Recipients
          $mail-&gt;setFrom('mail@mail.com', 'Email');
          $mail-&gt;addAddress($emailTo);     // Add a recipient
          $mail-&gt;addReplyTo('no-reply@website.com', 'No reply');
  
  
          // Content
          $url = &quot;http://&quot; . $_SERVER[&quot;HTTP_HOST&quot;] . dirname($_SERVER[&quot;PHP_SELF&quot;]) . &quot;/resetPassword/code/$code&quot;;
          $mail-&gt;isHTML(true);                                  // Set email format to HTML
          $mail-&gt;Subject = 'Reset your password!';
          $mail-&gt;Body = file_get_contents('mail_template.php');
          $mail-&gt;AltBody = 'This is the body in plain text for non-HTML mail clients';
  
          $mail-&gt;send();
      } catch (Exception $e) {
          echo &quot;Message could not be sent. Error: {$mail-&gt;ErrorInfo}&quot;;
      }
      header(&quot;refresh:10;url=login.php&quot;);
  }
  </code></pre>
  <p>So from this php file,I want to send the data of the <code>$url</code> to the <code>mail_template.php</code></p>
  <p>Is this possible to do?</p>