setBasePath("/api"); // Add middleware new middleware($app); new timelineRoutes($app); new projectRoutes($app); new blogRoutes($app); new userRoutes($app); // misc routes $app->post("/contact", function (Request $request, Response $response) { $data = $request->getParsedBody(); if (empty($data["fName"]) || empty($data["lName"]) || empty($data["email"]) || empty($data["subject"]) || empty($data["message"])) { $response->getBody()->write(json_encode(array("errorMessage" => "Please fill out all the fields"))); return $response->withStatus(400); } if (!filter_var($data["email"], FILTER_VALIDATE_EMAIL)) { $response->getBody()->write(json_encode(array("errorMessage" => "Email is not the correct format"))); return $response->withStatus(400); } // email form filler/conatcter $headers1 = "From: noreply@rohitpai.co.uk\r\n"; $headers1 .= "Reply-To: rohit@rohitpai.co.uk\r\n"; $headers1 .= "MIME-Version: 1.0\r\n"; $headers1 .= "Content-Type: text/html; charset=UTF-8\r\n"; $message1 = << {$data['subject']}

Thank you for filling out the form on my website, I will try to respond to your query as soon as I can.


Below is what you filled in for your record

Firstname Lastname Email Subject message
{$data['fName']} {$data['lName']} {$data['email']} {$data['subject']} {$data['message']}


Regards,
Rohit Pai
rohit@rohitpai.co.uk HEREA; mail($data["email"], $data["subject"], $message1, $headers1); // email to me $headers2 = "From: noreply@rohitpai.co.uk\r\n"; $headers2 .= "Reply-To: {$data['email']}\r\n"; $headers2 .= "MIME-Version: 1.0\r\n"; $headers2 .= "Content-Type: text/html; charset=UTF-8\r\n"; $message2 = << {$data['subject']}

{$data['fName']} {$data['lName']} filled in the form on the website, here is what they sent.

Firstname Lastname Email Subject message
{$data['fName']} {$data['lName']} {$data['email']} {$data['subject']} {$data['message']}
HEREB; mail("rohit@rohitpai.co.uk", "{$data['fName']} {$data['lName']} filled in the form", $message2, $headers2); return $response->withStatus(201); }); $app->run();