title: How to write PHP code inside of Laravel Blade template?
body: <p>I am writing code for a site that was done in Laravel, I know that it is not recommended to write PHP code within the Blade template, but in this instance I have limited time available.</p>
  
  <pre><code>@php
     if($_POST["submit"]){
          $name = $_POST["name"];
          $email = $_POST["email"];
  
          $missingName = "&lt;p&gt;&lt;strong&gt;Please eneter your name.&lt;/strong&gt;&lt;/p&gt;";
          $invalidEmail = "&lt;p&gt;&lt;strong&gt;Invalid Email.&lt;/strong&gt;&lt;/p&gt;";
  
  
          if($name){
              $name = filter_var($name, FILTER_SANITIZE_STRING);
          }else{
  
              $errors .= $missingName;
          }
  
  
            $email = filter_var($email, FILTER_SANITIZE_EMAIL);
            $email = filter_var($email, FILTER_VALIDATE_EMAIL);
           if(filter_var($email, FILTER_VALIDATE_EMAIL)){
  
            }else{
                $errors .= $invalidEmail;
            }
          if($errors){
              $resultMessage = '&lt;div  class="alert alert-danger"&gt;' . $errors .'&lt;/div&gt;';
          }else{
  
              $to = "leads@relevant.systems";
              $subject = "DijiJock update request form.";
              $message = "&lt;html&gt;
                           &lt;body&gt;
                           &lt;h2 style='color:black'&gt;DijiJock update request form.&lt;/h2&gt;
                  &lt;p style='color:green'&gt;Name: $name&lt;/p&gt;
                  &lt;p style='color:green'&gt;Email: $email&lt;/p&gt;
                  &lt;p style='color:black'&gt;$name has requested DijiJock updates, please forward all updates to $email.&lt;/p&gt;
                           &lt;/body&gt;
                         &lt;/html&gt;";
              $headers = "Content-type: text/html";
  
  
              if(mail($to, $subject, $message, $headers)){
                  $resultMessage = '&lt;div  class="alert alert-success"&gt;Thank you for the meesage!&lt;/div&gt;';
  
              }else{
                  $resultMessage = '&lt;div  class="alert alert-warning"&gt;Email not sent! Please try again later.&lt;/div&gt;';
              }
          }
          echo $resultMessage;
      }             
  @endphp
  </code></pre>
  
  <p>The PHP code in the middle does not work?</p>