If you are a web developer, you must know that the biggest enemy of a website contact form is the spam folder. Clients fill out the contact form, but the admin receives no emails. Even if an email arrives, the admin has to keep checking their inbox. Configuring an SMTP server is a headache, and if your email limit expires, the messages stop coming.
The best solution is a Telegram bot. When a visitor fills out your website form and clicks submit, you get a notification on your Telegram app within seconds about the new lead. This is lead generation. You can generate multiple leads and see them instantly in your Telegram app.
So, what is the smartest and 100% free solution? The Telegram Bot API.
Why Use Telegram for Lead Generation?
- Zero Email Spam: Leads will come directly in the chat, no spam folder issues.
- 100% Free API: No need to pay any third-party monthly subscriptions.
- Instant Mobile Alerts: As soon as the user submits the form, you will get a message on your phone in 1 second.
Step-by-Step Guide: Connect PHP Form to Telegram
Step 1: Get Your Bot Token (BotFather)
First, open your Telegram app and search for @BotFather.

Click the Start button to create a new contact form bot.

- Type
/newbot in the chat and send it.
- Give your new bot a name (e.g., Enquiry).
- Create a username for this bot (e.g., enqueryTs_bot or any other like that).
- BotFather will give you a long HTTP API Token. Copy it.

Step 2: Get Your Chat ID
Search for @userinfobot or @GetIDsBot on Telegram. As soon as you start it, it will give you your personal Chat ID (a number). Copy this too.

Step 3: The Copy-Paste PHP Code
Copy the premium form code given below and paste it into your index.php or contact.php file. (Note: Do not forget to paste your Token and Chat ID on line numbers 10 and 11!)
<?php
$status = "";
if(isset($_POST['submitForm'])) {
$name = $_POST['user_name'];
$mobile = $_POST['user_mobile'];
$message = $_POST['user_message'];
// Make sure to insert your actual bot token here
$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$chat_id = "xxxxxxxxxx";
$telegram_text = "???? <b>New Website Lead!</b>\n\n";
$telegram_text .= "???? <b>Name:</b> " . $name . "\n";
$telegram_text .= "???? <b>Mobile:</b> " . $mobile . "\n";
$telegram_text .= "???? <b>Message:</b> " . $message;
$encoded_text = urlencode($telegram_text);
$api_url = "https://api.telegram.org/bot$token/sendMessage?chat_id=$chat_id&text=$encoded_text&parse_mode=HTML";
// --- cURL Implementation ---
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return response as a string
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Ignore SSL verification issues if any
$response = curl_exec($ch);
// Check if any cURL error occurred
if(curl_errno($ch)) {
$response = false;
}
curl_close($ch);
// --- End cURL ---
if($response) {
$status = "<div class='success-msg'>✅ Message sent directly to Telegram!</div>";
} else {
$status = "<div class='error-msg'>❌ Failed to send message. Please try again.</div>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modern Telegram Contact Form</title>
<style>
/* Form ka Premium Design */
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f4f7f6; }
.form-container {
max-width: 450px;
margin: 50px auto;
background: #ffffff;
padding: 30px;
border-radius: 12px;
box-shadow: 0px 8px 20px rgba(0, 0, 0, 0.08);
}
.form-container h3 {
text-align: center; color: #333; margin-top: 0; font-size: 24px;
}
.input-group { margin-bottom: 20px; }
.input-group label {
display: block; font-weight: 600; margin-bottom: 8px; color: #555; font-size: 14px;
}
.input-group input, .input-group textarea {
width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 8px;
font-size: 14px; box-sizing: border-box; transition: 0.3s;
}
.input-group input:focus, .input-group textarea:focus {
border-color: #0088cc; outline: none; box-shadow: 0 0 8px rgba(0, 136, 204, 0.2);
}
.submit-btn {
width: 100%; padding: 14px; background: #0088cc; color: #fff;
border: none; border-radius: 8px; font-size: 16px; font-weight: bold;
cursor: pointer; transition: background 0.3s;
}
.submit-btn:hover { background: #0077b3; }
.success-msg {
background: #d4edda; color: #155724; padding: 12px; border-radius: 8px;
margin-bottom: 20px; text-align: center; border: 1px solid #c3e6cb;
}
.error-msg {
background: #f8d7da; color: #721c24; padding: 12px; border-radius: 8px;
margin-bottom: 20px; text-align: center; border: 1px solid #f5c6cb;
}
</style>
</head>
<body>
<div class="form-container">
<h3>Contact Us</h3>
<?php if($status != "") { echo $status; } ?>
<form method="POST" action="">
<div class="input-group">
<label>Full Name</label>
<input type="text" name="user_name" placeholder="Enter your name" required>
</div>
<div class="input-group">
<label>Mobile Number</label>
<input type="text" name="user_mobile" placeholder="Enter your mobile" required>
</div>
<div class="input-group">
<label>Your Message</label>
<textarea name="user_message" rows="4" placeholder="How can we help you?" required></textarea>
</div>
<button type="submit" name="submitForm" class="submit-btn">
Send Message
</button>
</form>
</div>
</body>
</html>
Watch the Full Setup in Action:
Whenever a visitor fills out the contact form on your website, you will get all their inquiries in your Telegram app. This method is completely free because we use a free API, meaning you will not face any problems, and no messages will go to the spam folder. This way, we can easily receive messages from the website contact form directly on Telegram.
Recommended Posts:-