Note that there are some explanatory texts on larger screens.

plurals
  1. POPhp Curl add string file as a post field
    text
    copied!<p>I am using mailGun web API and ran into the issue of adding inline files. Our software creates an image and passes it around as a string. I want to inline that image The problem that I have is that php curl takes in a file pointer, and not an actual file. I want to avoid writing a tmp file if possible as we have many process that work on the server and would not want to send a bad email </p> <p>Thanks in advance</p> <p>MailGun inline Sample:<a href="http://documentation.mailgun.net/user_manual.html#inline-image" rel="nofollow">http://documentation.mailgun.net/user_manual.html#inline-image</a> Code sample that I am using:</p> <pre><code>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' =&gt; 'Excited User &lt;me@samples.mailgun.org&gt;', 'to' =&gt; 'sergeyo@profista.com', 'subject' =&gt; 'Hello', 'text' =&gt; 'Testing some Mailgun awesomness!', 'html' =&gt; '&lt;html&gt;Inline image: &lt;img src="cid:test.jpg"&gt;&lt;/html&gt;', 'inline' =&gt; $image)) $result = curl_exec($ch); curl_close($ch); return $result; } $image = 'Some image string that we have generated' send_inline_image($image) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload