Search code examples
phpapachephpmailerslim

Localhost don't reload php script


I have an script in PHP and even saving and trying to execute it in different browsers It seems like it's cached or something because every change I do, it doesn't appear live.

EDIT 2 I'm trying this in my server and it works fine, if I change the file, the web changes as usual. My server is running a Debian with apache2 exactly as I have locally.

EDIT I tried to remove the $app->post('/send-mail', 'AppmaticController:sendMail'); and it stills working!!

Class /app/controllers/AppmaticController.php

namespace Appmatic\Controllers;

use Appmatic\Errors\ErrorHandler;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class AppmaticController
{
    private $slimApp;

    public function __construct($app)
    {
        $this->slimApp = $app;
    }

    public function sendMail(RequestInterface $request, ResponseInterface $response, $arguments)
    {

        $name = filter_var($request->getParsedBody()['name'], FILTER_SANITIZE_STRING);
        $email = filter_var($request->getParsedBody()['email'], FILTER_SANITIZE_EMAIL);
        $subject = filter_var($request->getParsedBody()['subject'], FILTER_SANITIZE_STRING);
        $message = filter_var($request->getParsedBody()['message'], FILTER_SANITIZE_STRING);

        $mail = new \PHPMailer();
        $mail->isSMTP();
        $mail->Host = 'smtp.1and1.es';
        $mail->Port = 587;
        $mail->SMTPAuth = true;
        $mail->Username = '[email protected]';
        $mail->Password = 'pass';
        $mail->SMTPSecure = 'tls';

        $mail->setFrom($email, $name);
        $mail->addAddress('[email protected]', 'Nulltilus');
        $mail->isHTML(false);

        $mail->Subject = $subject;
        $mail->Body = $message;

        if(!$mail->send()) {
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
            echo 'El mensaje se ha enviado';
        }

    }
}

/public_html/index.php

<?php

use Appmatic\Controllers as Controllers;
use Appmatic\Database;

require '../vendor/autoload.php';
require '../app/controllers/AppmaticController.php';
require '../app/utils/ErrorHandler.php';
include '../app/config/constants.php';

$config = require '../app/config/config.php';
$app = new \Slim\App($config);

require '../app/routes.php';

$container = $app->getContainer();

$container['view'] = function () {
    return new \Slim\Views\PhpRenderer('../app/views/');
};

$container['AppmaticController'] = function ($container) {
    return new Controllers\AppmaticController($container);
};

$app->run();

/app/routes.php

<?php
$app->post('/send-mail', 'AppmaticController:sendMail');

Server: localhost, Apache2
OS: Ubuntu 16.04
PHP 7.0


Solution

  • PHPStorm, the IDE I use, turns mad. When I tried to close it, I realized I couldn't close it and when I tried to open the project, there's no changes made so that's the problem.

    But when I opened the file before with Sublime changes were effective so I think that's a bug with PHPStorm or something similar.

    Thanks everyone who tried to help :)