title: PHP - Sending Email HTML/Plain Text - Syntax Error?
body: <p>I am trying to implement a simple sendEmails function that sends HTML if possible, if not it sends plain text. However, I am getting a syntax error in the file for some reason, even though if I pass it through an online validator, such as phpcodechecker, it doesn't come up with any problems.</p>
  
  <p>The exact error: </p>
  
  <blockquote>
    <p>Parse error: syntax error, unexpected end of file in C:\xampp\htdocs..\func.php on line 83</p>
  </blockquote>
  
  <p>Note: I have only implemented the sendEmails function, which broke it.</p>
  
  <p>My code</p>
  
  <pre><code>&lt;?php
  
      //Input: Email | Output: Boolean for Domain Existence (such as @yahoo.com) [TESTED]
      function domainExists($email, $record = 'MX'){
          list($user, $domain) = explode('@', $email);
          return checkdnsrr($domain, $record);
      }
  
      function sendEmails($to, $type, $link){
          switch($type){
              case "register":
                  if(strlen($link)&gt;0) $authenticationLink = $link;
                  else throwError("Email Failed",1);
                  //Send Email
                  $subject = "Thank You For Registering";
                  $boundaryHash = md5(date('r',time()));
                  $headers = "From: admin@....com";
                  $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$boundaryHash."\"";
                  ob_start();
                  ?&gt;
                      --PHP-alt-&lt;?php echo $boundaryHash; ?&gt; 
                      Content-Type: text/plain; charset="iso-8859-1"
                      Content-Transfer-Encoding: 7bit
  
                      Thank you for registering with ...! 
                      We hope you enjoy our service! To get started, please authenticate your account by copying and pasting the following link:
                      &lt;?php echo $authenticationLink; ?&gt;
  
                      --PHP-alt-&lt;?php echo $boundaryHash; ?&gt; 
                      Content-Type: text/html; charset="iso-8859-1"
                      Content-Transfer-Encoding: 7bit
  
                      &lt;h2&gt;Thank You For Registering!&lt;/h2&gt;
                      &lt;p&gt;Thank you for registering with ...!&lt;/p&gt;
  
                      &lt;p&gt;We hope you enjoy our service! To get started, please authenticate your account with the following link:&lt;/p&gt;
                      &lt;a href="&lt;?php echo $authenticationLink; ?&gt;"&gt;Click to Authenticate&lt;/a&gt;
  
                      --PHP-alt-&lt;?php echo $boundaryHash; ?&gt;--
                  &lt;?
                  $message = ob_get_clean();
                  $mail_sent = mail( $to, $subject, $message, $headers );
                  echo $mail_sent ? "Mail sent" : "Mail failed";
                  break;
              default: break;
          }
          return;
      }
  
      //isEscaped(String, Con):boolean, [TESTED]
      function isEscaped($str, $con){
          return (mysqli_real_escape_string($con, $str) === $str);
      }
  
  
      //Type: | 0: Unknown Error | 1:  | 2: DB Error | 3: Security Issue - Unescaped |
      //String: | 'Fatal' | 'NonFatal' | 'Trivial' | Otherwise String will be output
      //[TESTED]
      function throwError($str, $type){
          //Making sure parameters are valid
          $t = (int)$type; 
          $s = (string)$str;  
  
          //Shorthand to auto output general errors
          switch ($s){ 
              case 'Fatal': 
                  $s = "FATAL ERROR: Please contact the administrator immediately!"; 
                  break;
              case 'NonFatal':
                  $s = "ERROR: Please contact the administrator!";
                  break;
              case 'Trivial':
                  $s = "Unexpected Error: Please go back and try again!";
                  break;
          }
  
          echo "&lt;p class='errorspan'&gt;".$s.": ".$t."&lt;/p&gt;";
          exit($t);
      }?&gt;
  </code></pre>