title: How do I put an if statement inside the body of a PHPMailer code?
body: <p>I'm trying to put an if statement inside the body along with the html, but it's not working. I'm using PHPMailer, is something wrong with the code?</p>
  <pre><code>&lt;?php
  
  require  'email/PHPMailerAutoload.php';
  
  extract($_POST);
  
  $mail = new PHPMailer;
  
  
  $mail -&gt;isHTML(true);
  $mail -&gt;CharSet = 'UTF-8';
  
  $mail -&gt;Body .=&quot;
  
  if($result != null){
      echo &quot;Name: &quot; $result
  }
  
  &quot;;
  </code></pre>
  <p>I tried it the way Artem Medianyk said and it worked, but when I put the other variables that way, it didn't work.</p>
  <pre><code>$body = '';
  
  if ($result_SRV_AA_A10_name_go != null) {
    $body = &quot;Name: &quot; . $result_SRV_AA_A10_name_go;
  }
  
  if ($result_SRV_AA_A10_email_go != null) {
    $body = &quot;E-mail: &quot; . $result_SRV_AA_A10_email_go;
  }
  
  if ($result_SRV_AA_A10_tel_go != null) {
    $body = &quot;Telefone: &quot; . $result_SRV_AA_A10_tel_go;
  }
  
  if ($result_SRV_AA_B9_name_go != null) {
    $body = &quot;Name: &quot; . $result_SRV_AA_B9_name_go;
  }
  
  if ($result_SRV_AA_B9_email_go != null) {
    $body = &quot;E-mail: &quot; . $result_SRV_AA_B9_email_go;
  }
  
  if ($result_SRV_AA_B9_tel_go != null) {
    $body = &quot;Telefone: &quot; . $result_SRV_AA_B9_tel_go;
  }
  
  $body = json_encode($body);
  
  $mail -&gt;Body .= $body;
  </code></pre>
  <p>My idea is to check the answers that have been filled out and then send them in the best way by email. what could i do to achieve this?</p>