Skip to content

Instantly share code, notes, and snippets.

@painor
Created January 1, 2021 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save painor/8127f7da8d0198c54f7dbc0669491c16 to your computer and use it in GitHub Desktop.
Save painor/8127f7da8d0198c54f7dbc0669491c16 to your computer and use it in GitHub Desktop.
Small php contact to telegram script
<?php
function get_client_ip()
{
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP'])) $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_X_FORWARDED'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_FORWARDED'])) $ipaddress = $_SERVER['HTTP_FORWARDED'];
else if (isset($_SERVER['REMOTE_ADDR'])) $ipaddress = $_SERVER['REMOTE_ADDR'];
else $ipaddress = 'UNKNOWN';
return $ipaddress;
}
if (empty($_POST["name"]) or empty($_POST["message"]) or empty($_POST["email"]))
{
die();
}
else
{
$request = curl_init();
$ip = get_client_ip();
$format = "message from : " . $_POST["name"] . "\nemail : " . $_POST["email"] . "\nip : $ip\n";
if (!empty($_POST["phone"]))
{
$format .= "phone : " . $_POST["phone"] . "\n";
}
$format .= "message : " . $_POST["message"];
try
{
$params = array(
"chat_id" => "WHERE TO SEND IT TO",
"text" => $format
);
$token = "YOURBOTTOKEN";
$url = "https://api.telegram.org/bot$token/sendMessage";
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_POSTFIELDS, $params);
curl_setopt($request, CURLOPT_URL, $url);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_exec($request);
echo "MF000";
}
catch(Exception $e)
{
echo "no";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment