title: How to use variables in phpmailer message body
body: <p>I'm editing a form and I want to receive as mail when users fill it and send it. I received variables on mail before, such like: Name: $name. Now contact.php returns a blank page and I can't receive the form as mail.</p>
  
  <p>I tried before that, </p>
  
  <pre><code>$body_message = 'Name: ' . $name . "\r\n"; 
  $body_message .= 'E-mail: ' . $mail_from . "\r\n"; 
  $body_message .= 'Message: ' . $message;
  </code></pre>
  
  <p>But it doesn't work. And that also,</p>
  
  <pre><code>$mail-&gt;Body = '&lt;b&gt;You have a reservation!&lt;/b&gt;
  Name: $name
  Surname: $surname
  Phone: $phone
  Mail: $mail
  Address: $address
  Services: $check
  ';
  </code></pre>
  
  <p>Now my code:</p>
  
  <pre><code>$name = $_POST['name'];
  $surname = $_POST['surname'];
  $mail = $_POST['mail'];
  $phone = $_POST['phone'];
  $address= $_POST['address'];
  
  if(!empty($_POST['check_list'])) {
      foreach($_POST['check_list'] as $check) {           
          return $check;
      }
  }
  
  $mail-&gt;Subject = 'Reservation';
  $mail-&gt;Body    = '&lt;b&gt;You have a reservation!&lt;/b&gt;&lt;/br&gt;'
  .'Name: '.$name.'&lt;/br&gt;'
  .'Surname: '.$surname.'&lt;/br&gt;'
  .'Mail: '.$mail.'&lt;/br&gt;'
  .'Phone: '.$phone.'&lt;/br&gt;'
  .'Address: '.$address.'&lt;/br&gt;'
  .'Services: '.$check;
  
  if(!$mail-&gt;send()) {
      echo 'Message could not be sent.';
      echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
  } else {
      echo 'Message has been sent';
      header('Location: index.php');
      exit();
  }
  </code></pre>