W
W
wolk2015-10-01 00:24:07
PHP
wolk, 2015-10-01 00:24:07

How to convert curl request to php?

There is an example request:

curl -s --user 'api:key-123456789 \
https://api.mailgun.net/v3/domain.com/messages \
-F from='Excited User ' \
--F to='[email protected] com' \
-F cc='[email protected]' \
-F bcc='[email protected]' \
-F subject='Hello' \
-F text='Testing some Mailgun awesomness!' \
--form-string html='HTML version of the body' \
-F [email protected]/cartman.jpg \
-F [email protected]/cartman.png

It turned out to send text data, but I don’t understand how the files.
$post=array(
'to' => $to,
'from' => $from,
'subject' => $subject,
'text' => $plain,
'html' => $html
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL,
sprintf(' https://api.mailgun.net/v3/%s/%s ', $this->domain, $url));
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERPWD, "api:{$this->apiKey}");
$result = curl_exec($ch);

Can you please tell me how to send more files?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2015-10-01
@wolk

stackoverflow.com/questions/15200632/how-to-upload...
code.stephenmorley.org/php/sending-files-using-curl

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question