Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* VALIDATE RECAPTCHA */
- function validateRecaptcha($secret, $clientResponse, $clientIp)
- {
- $data = http_build_query([
- "LALALALAALA" => $secret,
- "response" => $clientResponse,
- "remoteip" => $clientIp,
- ]);
- $options = [
- "http" => [
- "header" =>
- "Content-Type: application/x-www-form-urlencodedrn".
- "Content-Length: ".strlen($data)."rn",
- "method" => "POST",
- "content" => $data,
- ],
- ];
- $response = file_get_contents(
- "https://www.google.com/recaptcha/api/siteverify",
- false,
- stream_context_create($options)
- );
- if($response === false)
- {
- return false;
- }
- else if(($arr = json_decode($response, true)) === null)
- {
- return false;
- }
- else
- {
- return $arr["success"];
- }
- }
- $errorMSG = array();
- /* NAME */
- if (empty($_POST["name"])) {
- $errorMSG[] = "Name is required";
- } else {
- $name = $_POST["name"];
- }
- /* EMAIL */
- if (empty($_POST["email"])) {
- $errorMSG[] = "Email is required";
- } else if(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
- $errorMSG[] = "Invalid email format";
- }else {
- $email = $_POST["email"];
- }
- /* MSG SUBJECT */
- if (empty($_POST["subject"])) {
- $errorMSG[] = "Subject is required";
- } else {
- $subject = $_POST["subject"];
- }
- /* MESSAGE */
- if (empty($_POST["message"])) {
- $errorMSG[] = "Message is required";
- } else {
- $message = $_POST["message"];
- }
- /* RECAPTCHA */
- if (empty($_POST["g-recaptcha-response"])) {
- $errorMSG[] = "ReCaptcha is required";
- }
- if(empty($errorMSG)){
- //PHPMailer
- $mail = new PHPMailer;
- //Enable SMTP debugging.
- $mail->SMTPDebug = 3;
- //Set PHPMailer to use SMTP.
- $mail->isSMTP();
- //Set SMTP host name
- $mail->Host = "smtp.server.com";
- //Set this to true if SMTP host requires authentication to send email
- $mail->SMTPAuth = true;
- //Provide username and password
- $mail->Username = "user@server.com";
- $mail->Password = "super_secret_password";
- //If SMTP requires TLS encryption then set it
- $mail->SMTPSecure = "tls";
- //Set TCP port to connect to
- $mail->Port = 587;
- $mail->From = $emailAddress;
- $mail->addAddress("name@server.com", "Recepient Name");
- $mail->isHTML(true);
- $mail->Subject = "Subject Text";
- $mail->Body = $emailBody;
- $response = array();
- if(!$mail->send())
- {
- $msg = "Email Failure";
- echo json_encode(['code'=>200, 'msg'=>$msg]);
- }
- else
- {
- $msg = "Form submit successfully";
- echo json_encode(['code'=>200, 'msg'=>$msg]);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment