title: Use PHPMailer with Slim Framework
body: <p>I'm using the Slim Framework to create several web services, now I want to create a service like:
  www.example.com/public/feedback
  This service must send a mail with data from a form, then I can't find the way to use PHPMailer library in the Slim structure. Does I must include the library in the index.php and it can be used in the routes.php file? Thanks in advance. </p>
  
  <p>Edit:
  I hope that this can clarify my concerns:</p>
  
  <pre><code>require __DIR__ . '/../vendor/autoload.php';
  
  require __DIR__ . '/../../PHPMailer/Exception.php';
  require __DIR__ . '/../../PHPMailer/PHPMailer.php';
  require __DIR__ . '/../../PHPMailer/SMTP.php';
  
  session_start();
  
  // Instantiate the app
  $settings = require __DIR__ . '/../src/settings.php';
  $app = new \Slim\App($settings);
  </code></pre>
  
  <p>The above code is in my index.php file in public folder and in the routes.php in the src folder I have the next code:</p>
  
  <pre><code>use PHPMailer\PHPMailer\PHPMailer;
  use PHPMailer\PHPMailer\Exception;
  use PHPMailer\PHPMailer\SMTP;
  $app-&gt;get('/feedback',function(Request $request,Response $response,array $args){
    $mail = PHPMailer(true);
    try {
        //Server settings
        $mail-&gt;SMTPDebug = 2;                                       // Enable verbose debug output
        $mail-&gt;isSMTP();                                            // Set mailer to use SMTP
        $mail-&gt;Host       = 'example.com';         // Specify main and backup SMTP servers
        $mail-&gt;SMTPAuth   = true;                                   // Enable SMTP authentication
        $mail-&gt;Username   = 'user@example.com';// SMTP username
        $mail-&gt;Password   = 'secret';                         // SMTP password
        $mail-&gt;SMTPSecure = 'tls';                                  // Enable TLS encryption, `ssl` also accepted
        $mail-&gt;Port       = 587;                                    // TCP port to connect to
  
        //Recipients
        $mail-&gt;setFrom('user@example.com','WebApp Contact');
        $mail-&gt;addAddress('mmucino@yahoo.com','Marco Muciño');               // Name is optional
  
        // Content
        $mail-&gt;isHTML(true);                                  // Set email format to HTML
        $mail-&gt;Subject = 'Here is the subject';
        $mail-&gt;Body    = 'This is the HTML message body &lt;b&gt;in bold!&lt;/b&gt;';
        $mail-&gt;AltBody = 'This is the body in plain text for non-HTML mail clients';
  
        $mail-&gt;send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail-&gt;ErrorInfo}";
    }
    return $response-&gt;withJSON(array(
      'status' =&gt; 'OK'
    ));
  </code></pre>
  
  <p>With my real data instead of example.com</p>
  
  <p>But the if I call the service with the url:</p>
  
  <pre><code>example.com/public/feedback
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>Slim Application Error
  The application could not run because of the following error:
  
  Details
  Type: Error
  Message: Call to undefined function PHPMailer()
  File: /home/tecallia/public_html/gabriel/src/routes.php
  Line: 405
  </code></pre>
  
  <p>What am I doing wrong? Thanks in advance.</p>