Created
April 15, 2022 13:50
-
-
Save rohzzn/811fad7636218b7789e1d885cd5fe041 to your computer and use it in GitHub Desktop.
php contact me form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Config | |
//SITE GLOBAL CONFIGURATION | |
$email = "something@something.something"; //<-- Your email | |
?> | |
- | |
<?php | |
// SendMail | |
include_once (dirname(dirname(__FILE__)) . '/config.php'); | |
//Initial response is NULL | |
$response = null; | |
//Initialize appropriate action and return as HTML response | |
if (isset($_POST["action"])) { | |
$action = $_POST["action"]; | |
switch ($action) { | |
case "SendMessage": { | |
if (isset($_POST["email"]) && !empty($_POST["email"])) { | |
$message = $_POST["message"]; | |
$message .= "<br/><br/>"; | |
$response = (SendEmail($message, $_POST["subject"], $_POST["name"], $_POST["email"], $email)) ? 'Thanks for your message (◍•ᴗ•◍)❤' : "Sending Message Failed"; | |
} else { | |
$response = "Sending Message Failed"; | |
} | |
} | |
break; | |
default: { | |
$response = "Invalid action is set! Action is: " . $action; | |
} | |
} | |
} | |
if (isset($response) && !empty($response) && !is_null($response)) { | |
echo '{"ResponseData":' . json_encode($response) . '}'; | |
} | |
function SendEmail($message, $subject, $name, $from, $to) { | |
$isSent = false; | |
// Content-type header | |
$headers = 'MIME-Version: 1.0' . "\r\n"; | |
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; | |
// Additional headers | |
$headers .= 'From: ' . $name .'<'.$from .'>'; | |
mail($to, $subject, $message, $headers); | |
if (mail) { | |
$isSent = true; | |
} | |
return $isSent; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment