0

mailGun Web API を使用していますが、インライン ファイルの追加の問題に遭遇しました。私たちのソフトウェアは画像を作成し、それを文字列として渡します。その画像をインライン化したい 私が抱えている問題は、php curl が実際のファイルではなく、ファイル ポインターを取り込むことです。サーバー上で動作する多くのプロセスがあり、悪いメールを送信したくないため、可能であれば tmp ファイルの書き込みを避けたい

前もって感謝します

MailGun インライン サンプル: http://documentation.mailgun.net/user_manual.html#inline-image 私が使用しているコード サンプル:

function send_inline_image($image) {
  $ch = curl_init();

  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/samples.mailgun.org/messages');
  curl_setopt($ch,
              CURLOPT_POSTFIELDS,
              array('from' => 'Excited User <me@samples.mailgun.org>',
                    'to' => 'sergeyo@profista.com',
                    'subject' => 'Hello',
                    'text' => 'Testing some Mailgun awesomness!',
                    'html' => '<html>Inline image: <img src="cid:test.jpg"></html>',
                    'inline' => $image))

  $result = curl_exec($ch);
  curl_close($ch);

  return $result;
 }
$image = 'Some image string that we have generated'
send_inline_image($image)
4

1 に答える 1

4

配列のインライン パラメータのみを変更する必要があります。私はそれとその作品をしました。インライン パラメータは、文字列のイメージ パスではなく配列にする必要があります。次のように実行できます。

function send_inline_image($image) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
 curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/samples.mailgun.org/messages');
curl_setopt($ch,
          CURLOPT_POSTFIELDS,
          array('from' => 'Excited User <me@samples.mailgun.org>',
                'to' => 'sergeyo@profista.com',
                'subject' => 'Hello',
                'text' => 'Testing some Mailgun awesomness!',
                'html' => '<html>Inline image: <img src="cid:test.jpg"></html>',
                'inline' => array($image)//Use array instead of $image
))

   $result = curl_exec($ch);
  curl_close($ch);
  return $result;
}
$image = 'Some image string that we have generated'
send_inline_image($image)

コメント「$image の代わりに配列を使用」を見てください。

于 2014-07-21T21:39:26.143 に答える