title: PHP Class not found while it's succesfully included
body: <p>I have searched on this forum for a solution and other places as well. But I can't find the problem with the code I wrote. The php file called <strong>Email_Service.php</strong> looks like this:</p>
  
  <pre><code>&lt;?php
  ////////////////////////////////////////
  //          [Email-Service] v3.5     /
  //////////////////////////////////////
  
  //Email Service Class
  class EmailService {
      //Properties
      private $email_basis;
      private $type;
  
      //Constructor
      function __construct($type) {
          echo '[EmailService] type: ' . $type;
      }
  
      //Send Email function with passed on arrays from test_pagina.php
      function versturen($emailInfo, $klantInfo) {
          //Email info
          $email_van = $emailInfo['email_van'];
          $email_naar = $emailInfo['email_naar'];
          $email_onderwerp = $emailInfo['email_onderwerp'];
  
          //Controleer of het opgegeven email adres geldig is en geen rare tekens bevat
          $pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i"; 
          if (preg_match($pattern, trim(strip_tags($emailInfo['email_van'])))) { 
              $cleanedFrom = trim(strip_tags($emailInfo['email_van'])); 
          } else {
              return "The email address you entered was invalid. Please try again!"; 
          }
  
          //Hier word de email_template geopend voor elke type.
          //Zorg vraag formulier
          if ($emailInfo['type'] == 'zorgvraag') {
              //$email_basis = file_get_contents(base_url() . 'include/email_template_zorgvraag.txt'); //(LOKAAL)
              //file_get_contents(base_url() . "assets/email_template.txt"); //(ONLINE)
          } else if ($emailInfo['type'] == 'aanmelden') {
              //$email_basis = file_get_contents(base_url() . 'mail_php/email_template_aanmeldformulier.txt'); //(LOKAAL)
          }
  
          //Personaliseer de email door de velden te vervangen met de ingevulde parameters
          $email_basis = str_replace("f_voornaam", $klantInfo['voornaam'], $email_basis);
          $email_basis = str_replace("f_achternaam", $klantInfo['achternaam'], $email_basis);
          $email_basis = str_replace("f_telefoon", $klantInfo['telefoon'], $email_basis);
          $email_basis = str_replace("f_email", $klantInfo['email_van'], $email_basis);
          $email_basis = str_replace("f_bericht", $klantInfo['$bericht'], $email_basis);
          $email_basis = str_replace("f_locatie", $klantInfo['$locatie'], $email_basis);
  
          //Genereer headers
          $headers = "From: " . $cleanedFrom . "\r\n";
          $headers .= "Reply-To: ". strip_tags($_POST['f_email']) . "\r\n";
              $headers .= "MIME-Version: 1.0\r\n";
              $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  
              //Hier word de mail verstuurd als alles goed is
              if (mail($emailInfo['email_naar'], $emailInfo['email_onderwerp'], $email_basis, $headers)) {
                  //CC
                  mail('info@yourdomain.nl', $emailInfo['email_onderwerp'], $email_basis, $headers);
              } else {
                  echo 'Er is iets fout gegaan. Probeer het later nog een keer!';
                  die();
              }
          }
     }
  ?&gt;
  </code></pre>
  
  <p>It's called from another php file called test_pagina.php which looks like this:</p>
  
  <pre><code>&lt;?php
  include 'https://yourdomain.nl/assets/Email_Service.php';   //ONLINE
  //require base_url() . 'assets/Email_Service.php';                      //LOKAAL
  
  //Haal gemeeente uit de adres balk
  $url = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  $url_onderdeel = explode('/', $url);
  $gemeente = $url_onderdeel[4];
  $gemeenteHoofdletter = ucfirst($gemeente);
  
  //Email parameters
  $email_van; $email_naar; $email_onderwerp = "Vraag van ". $gemeenteHoofdletter;
  $voornaam; $achternaam; 
  $telefoon; $bericht;
  $emailInfo; $klantInfo;
  
  //Controleert de ingevulde velden
  if (isset($_POST['f_email_van'])    ||
      isset($_POST['f_voornaam'])     ||
      isset($_POST['f_achternaam'])   ||
      isset($_POST['f_telefoon'])     ||
      isset($_POST['f_bericht']))     {
          //Email info
          $email_van = $_POST['f_email_van'];
          $email_naar = "socialekaartpro@gmail.com";
  
          /*Stuur Email
          Dé Parameters:(emailInfo, klantInfo)*/
          $emailInfo = array (
                      'email_van' =&gt; $email_van, 
                      'email_naar' =&gt; $email_naar,
                      'email_onderwerp' =&gt; $email_onderwerp);
          $klantInfo = array (
                      'voornaam' =&gt; $_POST['f_voornaam'],
                      'achternaam' =&gt; $_POST['f_achternaam'],
                      'telefoon' =&gt; $_POST['f_telefoon'],
                      'bericht' =&gt; $_POST['f_bericht'],
                      'locatie' =&gt; $gemeenteHoofdletter);
  
          //Voeg de mail script toe zodat we de functie stuurEmail kunnen aanroepen
          $mail = new EmailService('zorgvraag');
          $mail -&gt; versturen($emailInfo, $klantInfo);
  }
  ?&gt;
  
  &lt;!--=== Type Woning ===--&gt;
  &lt;div class="page-topbar"&gt;
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-sm-4"&gt;
                  &lt;h3&gt;Bedrijfsnaam&lt;/h3&gt;
              &lt;/div&gt;
              &lt;div class="col-sm-8 hidden-xs"&gt;
                  &lt;ol class="breadcrumb"&gt;
                      &lt;li&gt;&lt;a href="&lt;?php echo base_url(); ?&gt;nijmegen"&gt;Gemeente Nijmegen&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="&lt;?php echo base_url(); ?&gt;nijmegen/woningverhuur"&gt;Woningverhuur&lt;/a&gt;&lt;/li&gt;
                      &lt;li class="active"&gt;Bedrijfsnaam&lt;/li&gt;
                  &lt;/ol&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt; 
  &lt;/div&gt;
  
  &lt;div class="content container" style="padding-top: 10px;"&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-md-12"&gt;
              &lt;div class="panel panel-default"&gt;
                  &lt;div class="panel-heading left" style="margin-bottom: -1px;background-color: rgba(255, 255, 255, 0);"&gt;&lt;a href="&lt;?php echo base_url(); ?&gt;nijmegen/woningverhuur" style="font-size: 13px; text-decoration: none;"&gt;&lt;i class="glyphicon glyphicon-menu-left"&gt;&lt;/i&gt; Terug naar overzicht&lt;/a&gt;
                      &lt;ul class="pull-right"&gt;
                          &lt;a href="" onclick="javascript:window.print();" style="font-size: 13px;text-decoration: none;"&gt;&lt;i class="fa fa-print" aria-hidden="true"&gt;&lt;/i&gt;Print&lt;/a&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;!--================================== Overzicht ========================--&gt;
  &lt;div class="job-description"&gt;
  &lt;div class="container content"&gt;
  &lt;div class="row"&gt;
  &lt;div class="col-md-8"&gt;
  &lt;div class="left-inner" style="margin-left: 0px;"&gt;
      &lt;h3 style="margin-top: 28px;margin-bottom: 12px;"&gt;Test pagina&lt;/h3&gt;
      &lt;p&gt;
      LEEG LEEG
      &lt;/p&gt;
  
      &lt;h3 style="margin-top: 40px;margin-bottom: 12px;"&gt;LEEG LEEG&lt;/h3&gt;
      &lt;p&gt;
      LEEG LEEG
      &lt;/p&gt;
  
      &lt;h3 style="margin-top: 40px;margin-bottom: 12px;"&gt;LEEG LEEG&lt;/h3&gt;
      &lt;p&gt;
      LEEG LEEG
      &lt;/p&gt;
  
  
      &lt;h3 style="margin-top: 40px;margin-bottom: 12px;"&gt;LEEG LEEG&lt;/h3&gt;
      &lt;p&gt;
      LEEG LEEG
      &lt;/p&gt;
  
  
      &lt;br&gt;
      &lt;br&gt;
          &lt;a href="#" target="_blank" class="btn btn-primary" style="margin-left: 0px;margin-bottom: 20px;"&gt; Naar de website LEEG LEEG&lt;/a&gt;                        
      &lt;br&gt;
  &lt;/div&gt;  
  &lt;/div&gt;                  
  
  &lt;div class="col-sm-4"&gt;
  &lt;div class="panel panel-default" style="margin-top: 9px;"&gt;
      &lt;div class="panel-heading" style="border-bottom-color: rgba(217, 217, 217, 0);margin-top: 2px;"&gt;Doelgroep&lt;/div&gt;
      &lt;div class="panel-body"&gt;
          &lt;div class="row"&gt;
              &lt;p style="margin-top: -22px;margin-left: 16px;padding-right: 7px;"&gt;
              LEEG | LEEG
              &lt;/p&gt;
          &lt;/div&gt;  
      &lt;/div&gt;
      &lt;div class="panel-heading" style="border-bottom-color: rgba(217, 217, 217, 0);margin-top: -14px;"&gt;Leeftijdscatogarie&lt;/div&gt;
      &lt;div class="panel-body"&gt;
          &lt;div class="row"&gt;
              &lt;p style="margin-top: -22px;margin-left: 16px;margin-bottom: 2px;"&gt;
              LEEG | LEEG
              &lt;/p&gt;
          &lt;/div&gt;  
      &lt;/div&gt;                          
  &lt;/div&gt;          
  
  &lt;div class="panel panel-default" style="margin-top: 9px;"&gt;
      &lt;div class="panel-heading" style="border-bottom-color: rgba(217, 217, 217, 0);margin-bottom: -15px;"&gt;Contact gegevens&lt;/div&gt;
      &lt;div class="panel-body"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-xs-4 col-md-4"&gt;
                  &lt;p style="font-weight: 600;color: #000000;margin-bottom: 0px;"&gt;Naam&lt;/p&gt;
                  &lt;p style="font-weight: 600;color: #000000;margin-bottom: 0px;"&gt;Adres&lt;/p&gt;
                  &lt;p style="font-weight: 600;color: #000000;margin-bottom: 0px;"&gt;Postcode&lt;/p&gt;
                  &lt;p style="font-weight: 600;color: #000000;margin-bottom: 0px;"&gt;Plaats&lt;/p&gt;
                  &lt;p style="font-weight: 600;color: #000000;margin-bottom: 0px;"&gt;Telefoon&lt;/p&gt;
              &lt;/div&gt;
  
              &lt;div class="col-xs-6 col-md-6" style="width: 65%;"&gt;
                  &lt;p style="margin-bottom: 0px;"&gt;LEEG&lt;/p&gt;
                  &lt;p style="margin-bottom: 0px;"&gt;LEEG&lt;/p&gt;
                  &lt;p style="margin-bottom: 0px;"&gt;LEEG&lt;/p&gt;
                  &lt;p style="margin-bottom: 0px;"&gt;LEEG&lt;/p&gt;
                  &lt;p style="margin-bottom: 0px;"&gt;LEEG&lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;  
  
          &lt;hr style="margin-top: 20px;margin-bottom: 10px;"&gt;  
  
          &lt;div class="row"&gt;
              &lt;div class="col-md-12"&gt;
                  &lt;div class="panel-heading" style="margin-left: -15px;margin-top: -12px;margin-bottom: -15px;"&gt;
                  &lt;h4 class="panel-title"&gt;
                      &lt;span style="font-size: 13px;font-weight: 600;"&gt;Heeft u een zorgvraag, &lt;/span&gt;
                      &lt;a href="#mail-1" data-parent="#accordion-v1" data-toggle="collapse" class="accordion-toggle"&gt;
                          &lt;span style="color: #3299bb;font-weight: 600;text-decoration: underline;"&gt; klik dan hier&lt;/span&gt;
                      &lt;/a&gt;
                  &lt;/h4&gt;
              &lt;/div&gt;
  
  &lt;!--Bevestiging script JSalert
  &lt;div&gt;
      &lt;script src="https://socialekaartgemeente.nl/assets/js/sweetalert-dev.js"&gt;&lt;/script&gt;
      &lt;script src="https://code.jquery.com/jquery-1.10.2.js"&gt;&lt;/script&gt;
          &lt;link rel="stylesheet" href="https://socialekaartgemeente.nl/assets/css/sweetalert.css"&gt;
          &lt;script type="text/javascript"&gt;
              function JSalert(){
                  //event.preventDefault();;
                  swal("Congrats!", ", Uw mail is verzonden!", "success");
              }
      &lt;/script&gt;
  &lt;/div&gt;--&gt;
  
  &lt;!-- =============================[EMAIL FORM]================================== --&gt;
  &lt;!-- onSubmit="window.location.reload()" --&gt;
  &lt;!-- ="javascript:JSalert();" --&gt;
  
  
  
              &lt;div class="panel-collapse collapse" id="mail-1"&gt;
                  &lt;div class="panel-body" style="margin-left: -15px;"&gt;
                      &lt;form action=""  method="post" id="form_mail" &gt;
                          &lt;div class="row"&gt;
                              &lt;div class="col-sm-12"&gt;
                                  &lt;div class="form-group"&gt;
                                      &lt;input id="voornaam" type="text" name="f_voornaam" class="form-control" placeholder="Voornaam*" required="required" data-error="Firstname is required."&gt;
                                      &lt;div class="help-block with-errors"&gt;&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="col-sm-12"&gt;
                                  &lt;div class="form-group"&gt;
                                      &lt;input id="achternaam" type="text" name="f_achternaam" class="form-control" placeholder="Achternaam*" required="required" data-error="Firstname is required."&gt;
                                      &lt;div class="help-block with-errors"&gt;&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="col-sm-12"&gt;
                                  &lt;div class="form-group"&gt;
                                      &lt;input id="telefoon" type="text" name="f_telefoon" class="form-control" placeholder="Telefoonnummer*" required="required" data-error="Firstname is required."&gt;
                                      &lt;div class="help-block with-errors"&gt;&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="col-sm-12"&gt;
                                  &lt;div class="form-group"&gt;
                                      &lt;input id="email" type="text" name="f_email_van" class="form-control" placeholder="Email*" required="required" data-error="Firstname is required."&gt;
                                      &lt;div class="help-block with-errors"&gt;&lt;/div&gt;
                                  &lt;/div&gt;  
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label class="sr-only" for="message"&gt;Bericht&lt;/label&gt;
                              &lt;textarea class="input-lg form-control" name="f_bericht" rows="5" id="bericht" placeholder="Uw zorgvraag"&gt;&lt;/textarea&gt;
                              &lt;span class="help-block"&gt;&lt;/span&gt;
                          &lt;/div&gt;
                          &lt;!--Verzend knop--&gt;
                          &lt;button type="submit" class="btn btn-sm btn-primary" style="margin-bottom: -15px;"&gt;Bericht verzenden&lt;/button&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;  
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="panel panel-default" style="margin-top: 9px;"&gt;
      &lt;div class="panel-body"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-12"&gt;
                  &lt;ul class="social-icons pull-left" style="margin-left: -2px;margin-top: 4px;margin-bottom: -8px;"&gt;
                      &lt;li style="margin-left: 0px;"&gt;&lt;a href="#" target="_blank" data-original-title="Facebook" class="rounded-x social_facebook"&gt;&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="#" target="_blank" data-original-title="Twitter" class="rounded-x social_twitter"&gt;&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="#" target="_blank" data-original-title="Linkedin" class="rounded-x social_linkedin"&gt;&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="#" target="_blank" data-original-title="Goole Plus" class="rounded-x social_googleplus"&gt;&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="#" target="_blank" data-original-title="Youtube" class="rounded-x social_youtube"&gt;&lt;/a&gt;&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/div&gt;  
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;!-- Google Maps --&gt;
  &lt;div class="panel panel-default" style="margin-top: 9px;"&gt;
      &lt;div class="panel-body"&gt;
          &lt;!-- Laad Google Maps --&gt;
          &lt;style&gt;#map-container { height: 200px }&lt;/style&gt;
          &lt;div id="map-container" class="col-md-12"&gt;&lt;/div&gt;
          &lt;script src="//maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;
          &lt;script&gt;    
              function init_map() {
                  //Definieer de coordinaten en zet zoom level
                  var var_location = new google.maps.LatLng(00000000, 00000000);
                  var var_mapoptions = {
                      center: var_location,
                      zoom: 14
                  };
  
                  //Plaats de marker bij de coordinaten 
                  var var_marker = new google.maps.Marker({
                      position: var_location,
                      map: var_map,
                      title:"Venice"});
  
                  //^Teken the map met de instellingen hierboven^
                  var var_map = new google.maps.Map(document.getElementById("map-container"),
                      var_mapoptions);
                      var_marker.setMap(var_map); 
                  }
                  google.maps.event.addDomListener(window, 'load', init_map);
          &lt;/script&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I keep getting this error:
  Fatal error: </p>
  
  <blockquote>
    <p>Class 'EmailService' not found in (/file location)</p>
  </blockquote>
  
  <p>Which is in this case uploaded to the server so it can be easily called upon on the whole website. I have never had this problem with writing and using a class. What am I possibly doing wrong? A lot more people have posted the same question about this error before, but they seem to have a different setup.</p>