render($response, 'contacto'); } public function enviar(Request $request, Response $response, Container $container, Mailer $mailer): Response { $post = $request->getParsedBody(); $body = []; $filename = implode(DIRECTORY_SEPARATOR, [ $container->get('folders.templates'), 'contacto', 'email.php' ]); $html = file_get_contents($filename); foreach ($post as $key => $val) { $body []= ucwords($key) . ': ' . $val; $html = str_replace('{{$' . $key . '}}', $val, $html); } $body = implode(PHP_EOL, $body); $subject = 'Contacto Web - ' . $post['nombre']; $message = $container->make(Message::class) ->setFrom($container->get('emails')[0]) ->addTo($container->get('emails')[0]) ->addCc($container->get('emails')[1]) ->setSubject($subject) ->setBody($body) ->setHTMLBody($html); $status = $mailer->send($message); $message = $container->make(Message::class) ->setFrom($container->get('emails')[0]) ->addTo($post['mail'], $post['nombre']) ->setSubject($subject) ->setBody('Su correo a CapitalInvestments ha sido recibido.'); $mailer->send($message); $output = [ 'informacion' => $post, 'estado' => $status, 'mail' => [ 'from' => $post['mail'], 'to' => $container->get('emails')[0], 'cc' => $container->get('emails')[1], 'asunto' => $subject, 'mensaje' => $body, 'html' => $html ] ]; $response->getBody()->write(json_encode($output)); return $response ->withHeader('Content-Type', 'application/json') ->withStatus(201); } }