50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
namespace ProVM\NotariaRaby\Common\Controller\Web;
|
|
|
|
use Psr\Container\ContainerInterface as Container;
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
use Slim\Views\Blade as View;
|
|
use Nette\Mail\SendmailMailer as Mailer;
|
|
use Nette\Mail\Message;
|
|
|
|
class Contacto {
|
|
public function __invoke(Request $request, Response $response, View $view, Container $container): Response {
|
|
$url = $container->get('urls.map');
|
|
return $view->render($response, 'contacto', compact('url'));
|
|
}
|
|
public function formulario(Request $request, Response $response, Mailer $mailer, Container $container): Response {
|
|
$post = $request->getParsedBody();
|
|
|
|
$body = [];
|
|
foreach ($post as $key => $val) {
|
|
$body []= $key . ': ' . $val;
|
|
}
|
|
$body = implode(PHP_EOL, $body);
|
|
$subject = 'Contacto Web - ' . $post['nombre'];
|
|
|
|
$message = $container->make(Message::class)
|
|
->setFrom($post['email'], $post['nombre'])
|
|
->addTo($container->get('email.recepcion'))
|
|
->addCc($container->get('email.administrativo'))
|
|
->setSubject($subject)
|
|
->setBody($body)
|
|
->setHTMLBody(nl2br($body));
|
|
//$mailer->send($message);
|
|
|
|
$output = [
|
|
'informacion' => $post,
|
|
'mail' => [
|
|
'to' => $container->get('email.recepcion'),
|
|
'cc' => $container->get('email.administrativo'),
|
|
'asunto' => $subject,
|
|
'mensaje' => $body
|
|
]
|
|
];
|
|
$response->getBody()->write(json_encode($output));
|
|
return $response
|
|
->withHeader('Content-Type', 'application/json')
|
|
->withStatus(201);
|
|
}
|
|
}
|