@wollk

Как переделать curl запрос под php?

Есть пример запроса:
curl -s --user 'api:key-123456789 \
https://api.mailgun.net/v3/domain.com/messages \
-F from='Excited User ' \
--F to='foo@example.com' \
-F cc='bar@example.com' \
-F bcc='baz@example.com' \
-F subject='Hello' \
-F text='Testing some Mailgun awesomness!' \
--form-string html='HTML version of the body' \
-F attachment=@files/cartman.jpg \
-F attachment=@files/cartman.png

Текстовые данные отправить получилось, а вот файлы не пойму как.

$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);


Подскажите пожалуйста, как отправить еще и файлы ?
  • Вопрос задан
  • 210 просмотров
Решения вопроса 1
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы