Curl not working

Hi there, im new for ExeOutput for PHP.
My code use curl for send request but its not working for me.
This is my code:

function send_to_telegram($bot_token, $chat_id, $message) {
    $url = "https://api.telegram.org/bot$bot_token/sendMessage";

    $data = [
        'chat_id' => $chat_id,
        'text' => $message,
        'parse_mode' => 'MarkdownV2'
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . "/cacert.pem"); // Thiết lập đường dẫn đến tệp cacert.pem

    $response = curl_exec($ch);

    if (curl_errno($ch)) {
        // Hiển thị lỗi cURL
        echo 'cURL error: ' . curl_error($ch);
    } else {
        // Hiển thị phản hồi từ API Telegram
        echo 'Response: ' . $response;
    }

    curl_close($ch);

    return $response;
}

although i put cacert.pem in same directory project.
my php setting in ExeOutput

[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
;curl.cainfo =

Anyone please help me. thanks

First thing that comes to my mind is you did not compile curl or openssl into your exe. under PHP Extensions:

Recommend you do not change php.ini.

I used your curl and added some debug steps and had to comment out:

//'parse_mode' => 'MarkdownV2',

For some reason telegram does not like 'parse_mode' => 'MarkdownV2',

Debug Information:
Requested URL: https://api.telegram.org/bot7276513956:AAG-zbWWT********************/sendMessage
Requested Data: Array
(
    [chat_id] => 74113********
    [text] => what?
)

HTTP Code: 200
Response: Array
(
    [ok] => 1
    [result] => Array
        (
            [message_id] => 3
            [from] => Array
                (
                    [id] => 72765****
                    [is_bot] => 1
                    [first_name] => Botbadbot
                    [username] => justabadbot_bot
                )

            [chat] => Array
                (
                    [id] => 74113*****
                    [first_name] => Susan
                    [type] => private
                )

            [date] => 1722459792
            [text] => what?
        )

)

Try compiling the extensions shown in above screencap and give it another try. Remember to remove or uncomment out: 'parse_mode' => 'MarkdownV2',

2 Likes

thanks i got it