PHP imap via proxy - php

Is there any solution to working imap via proxy on php ? Will be great if I can use fsockopen and work with imap via proxy. How to connect to imap via proxy? How to log in, send commands ? I have looked all web and did not found any solution. There really absent enough information for this topic. Great thank in advance for anybody who can help!

$ch = curl_init("imaps://imap.server.com:993/INBOX;UID=1");
curl_setopt_array($ch,[
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_USERNAME => 'postbox#server.com',
CURLOPT_PASSWORD => 'password',
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
CURLOPT_PROXY => "proxy-ip-addr:proxy-port"
]);
$content = curl_exec( $ch );
curl_close($ch);
echo $content;
This is example how to get message #1 form Inbox.
Non-GET IMAP commands can be sent with CURLOPT_CUSTOMREQUEST option.
For example, to delete message:
$ch = curl_init("imaps://imap.server.com:993/INBOX;UID=1");
curl_setopt_array($ch,[
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_USERNAME => 'postbox#server.com',
CURLOPT_PASSWORD => 'password',
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
CURLOPT_PROXY => "proxy-ip-addr:proxy-port"
]);
$content = curl_exec( $ch );
curl_close($ch);

Related

Send Request from server to ngrok server in PHP

So I want to send a request from my server to NGROK server and it return null.
but when I check the URL, it return something.
I've tried so many ways, but it still doesn't work for me
this is my code
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
I also tried request to another server (not NGROK) with same code, and it works. this is only happen on ngrok

POSTMAN CURL File input corrupted

curl --location --request **PUT** 'https://REMOTE_SERVER/1177.png?v=3f75572bc00587e6104ed42d2e16a8f69656fdc63d50be78fb685266a2358340' --header 'Content-Length: 6137' --form 'File=#"/home/user/Documents/1177.png"'
im using postman / php code which creates the above curl , the issue I'm facing is it uploading all type of files but all the files seems to be corrupted and unable to open or load in the browser, following is set up as a remote server
https://modules.prosody.im/mod_http_upload_external.html
only PUT is allowed here to upload files
in case of .txt file it looks good but it addes below code so it looks to me its because of some headers im missing or what not sure can you please help ?
-------------------- SOLUTION ---------------------
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "$remoteSever$fileName?v=$secretAuthToken",
// CURLOPT_UPLOAD => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
// CURLOPT_BINARYTRANSFER => true,
// CURLOPT_HEADER => false,
// CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_PUT => true,
CURLOPT_INFILE => fopen($file->getRealPath(), 'rb'),
CURLOPT_INFILESIZE => $fileSize,
CURLOPT_SSL_VERIFYPEER => false,
// CURLOPT_POSTFIELDS => [
// 'File'=> new \CURLFile($request->file('media_file'))
// // 'File'=> $request->file('media_file')
// ],
// CURLOPT_HTTPHEADER => [
// "Content-Length: $fileSize",
// "Content-Type: $fileMimeType"
// ],
]);
$output = curl_exec($curl);
curl_close($curl);

Laravel 8 - "couldn't open file" error when trying to post a s3 stored file to an external API

I am trying to post a file to an external API.
The file is stored in s3.
It works fine when i test it on my local machine and POSTMAN. But it throws an error on the dev server.
Could not figure out what is causing this issue.
The error says
couldn't open file "https://s3.ap-southeast-1.amazonaws.com/files.test.bucket/Applications/1401/1401-Applicant_1_Back_of_Drivers_Licence-07-03-2022_13:59:44-test.jpeg"
Here is the relevant portion of the code:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://test.com/api/v1/documents',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('file'=> new \CURLFILE('https://s3.ap-southeast-1.amazonaws.com/files.test.bucket/Applications/1401/1401-Applicant_1_Back_of_Drivers_Licence-07-03-2022_13:59:44-test.jpeg'),'id' => '4688826','documentType' => 'app_drivers_licence_back'),
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer 1234567890'
),
));
$documentResponse = curl_exec($curl);

PHP - GET request works in Postman, but not with cUrl

There's a free weather API in my country that I want to use to get rain data. The request is simple https://apitempo.inmet.gov.br/estacao/2021-05-03/2021-05-06/A826 and there's no authentication. If I try the request using Postman, my browser or AJAX, it works fine and I get the results I need. However, using cURL, I get nothing.
Here's the PHP code that I tried:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://apitempo.inmet.gov.br/estacao/2021-05-03/2021-05-06/A826',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
I have the cURL.dll installed and tested in another server, but it didn't work.
Is there a problem with the code or is it the API that blocks PHP requests?
its look like this website looking for user-agent header.
try this:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://apitempo.inmet.gov.br/estacao/2021-05-03/2021-05-06/A826',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'User-Agent: something'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

Facebook Debug Tool via cURL

I'm trying to use the Facebook Linter programmatically, so that when I update a post it automatically pings FB to pull the new open graph information.
All the solutions I'm finding online don't seem to work anymore though, and are all old.
Is there a way to do this?
This is what I have so far which doesn't work
$params = array(
'id' => $url,
'scrape' => 'true',
'access_token' => '12345|987654321'
);
$ch = curl_init("https://graph.facebook.com?" . http_build_query($params));
curl_setopt_array($ch, array(
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
));
$result = curl_exec($ch);
Add CURLOPT_POST to your CURL request so that the data is POSTed to the Graph API:
curl_setopt_array($ch, array(
CURLOPT_HEADER => 0,
CURLOPT_POST => 1,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
));
See the documentation here.

Categories