Using Phpmailer and Ajax with Slim Framework

Asked

Viewed 78 times

1

I’m a beginner in PHP and I need to treat a post route using Ajax, Slim and Phpmailer.

In my index where you have the form I am using this jquery code for Ajax request:

<script>
    $(function () {
        $('.form').submit(function () {
            $.ajax({
                url: '/send-email',
                type: 'POST',
                data: $('.form').serialize(),
                success: function (data) {
                    $('.show').html(data);
                }
            });
            return false;
        });
    })
</script>

I need to know, which negotiations I need to do so that I receive the form data and put it in another file called send-form.php where Phpmailer will work with this data.

<?php

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use Slim\Views\PhpRenderer;

require 'vendor/autoload.php';

$app = new \Slim\App([
    'settings' => [
        'displayErrorDetails' => true
    ]
]);

$container = $app->getContainer();
$container['renderer'] = new PhpRenderer("./src/views");

$app->get('/', function(Request $request, Response $response) {
    return $this->renderer->render($response, "index.html");
});

$app->get('/sobre', function(Request $request, Response $response) {
    return $this->renderer->render($response, "about.html");
});

$app->get('/contato', function(Request $request, Response $response) {
    return $this->renderer->render($response, "contact.html");
});

$app->get('/servicos', function(Request $request, Response $response) {
    return $this->renderer->render($response, "services.html");
});

$app->post('/send-email', function(Request $request, Response $response) {

});


$app->run();

?>

This is my index.php with the routes. What should I do in the post route for the data to arrive in the send-form.php?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.