How to Receive PHP Contact Form Messages on Telegram (Free API)


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.

  1. Type /newbot in the chat and send it.
  2. Give your new bot a name (e.g., MyWebsiteLeadsBot).
  3. 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'];

    //  PASTE YOUR TOKEN AND CHAT ID HERE
    $token = "YOUR_BOT_TOKEN_HERE"; 
    $chat_id = "YOUR_CHAT_ID_HERE";

    // Format the Telegram Message
    $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";

    // Send the message
    $response = file_get_contents($api_url);

    if($response) {
        $status = "<div style='color:green;'>✅ Lead sent directly to Telegram!</div>";
    } else {
        $status = "<div style='color:red;'>❌ Failed to send message.</div>";
    }
}
?>

<!-- Simple HTML Form -->
<div style="max-width: 400px; margin: auto; font-family: Arial;">
    <h3>Send Enquiry</h3>
    <?php if($status != "") { echo $status; } ?>
    <form method="POST" action="">
        <input type="text" name="user_name" placeholder="Your Name" required style="width:100%; padding:10px; margin-bottom:10px;"><br>
        <input type="text" name="user_mobile" placeholder="Mobile Number" required style="width:100%; padding:10px; margin-bottom:10px;"><br>
        <textarea name="user_message" placeholder="Message" required style="width:100%; padding:10px; margin-bottom:10px;"></textarea><br>
        <button type="submit" name="submitForm" style="width:100%; padding:10px; background:#0088cc; color:white; border:none;">Send to Telegram </button>
    </form>
</div>

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.


Please Share

Recommended Posts:-