S
S
Sergey Goryachev2016-10-17 19:49:25
PHP
Sergey Goryachev, 2016-10-17 19:49:25

How to send HTTP request from PHP when working with API?

I have this documentation https://pechkin.com/api/
But I am very far from PHP and sending POST requests.
Push in the right direction, or let me read something intelligible.
Now the task is simple:
Write the user's name, phone number and mail to the subscriber base.
All this must be done when he clicks "Leave a request".
The PHP handler is extremely simple.

<?php
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $to = '@.';
    $subject = 'Обратный звонок';
    $message = '
            <html>
                <head>
                    <title>'.$subject.'</title>
                </head>
                <body>
                    <p>Имя: '.$name.'</p>
                    <p>Телефон: '.$phone.'</p>
                    <p>E-mail: '.$email.'</p>
                </body>
            </html>';
    $headers  = "Content-type: text/html; charset=utf-8 \r\n";
    $headers .= "From: Отправитель <@.>\r\n";
    mail($to, $subject, $message, $headers);
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2016-10-17
@webirus

google -> php curl post request

V
vopross, 2016-10-17
@vopross

For example like this:

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $arr);
$out = curl_exec($curl);
curl_close($curl);

In the variable $url is the URL of the request, in $arr is an array with data, and the response from the server is written to $out.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question