I'm working with mailgun and want to add images to my newsletters. Now I did this:
$mg->sendMessage($domain, array('from' => '[email protected]',
'to' => '[email protected]',
'subject' => 'Developers Mail Test MijnProjectgroep batch #1',
'text' => 'Hallo %recipient_fname%,
'html' => '<html>
<img style="display:block;" class="img1" src="cid:header-clip.png" width="600" height="64" />
</html>',
array('inline' => '@.././images/newsletter/header-clip.png'),
'o:tracking-opens' => 'yes'));
But no images are loading while I receive the newsletter. The document with the script above is in:
Root --> /MailGun/
The images are in:
Root --> /images/newsletter/
Also tried: @../../images/newsletter/header-clip.png
The documentation is here:
http://documentation.mailgun.com/user_manual.html?highlight=html#sending-via-api
What did I do wrong?
You did not do wrong. Actually there is an issue in the API documentation.
You need to use an array instead of string path in inline image path. It will solve the issue. You can add it like this:
$mg->sendMessage($domain, array('from' => '[email protected]',
'to' => '[email protected]',
'subject' => 'Developers Mail Test MijnProjectgroep batch #1',
'text' => 'Hallo %recipient_fname%,
'html' => '<html><img style="display:block;" class="img1" src="cid:header-clip.png" width="600" height="64" /></html>',
array('inline' => array('@.././images/newsletter/header-clip.png')
),
'o:tracking-opens' => 'yes'));
Please check this line:
array('inline' => array('@.././images/newsletter/header-clip.png')
The images to be attached need to be passed in as the 3rd argument to the sendMessage method:
$mgClient->sendMessage("$domain",
array('from' => 'Mailgun Sandbox <[email protected]>',
'to' => 'mr awesome <[email protected]>',
'subject' => 'Hello Mr',
'html' => '<html><img style="display:block;" class="img1" src="cid:header-clip.png" width="600" height="64" /></html>'
),
array (
'inline' => array(dirname(__FILE__).'/images/newsletter/header-clip.png')
)
);
Also note the file path to the file: dirname(__FILE__)
. You may need to change this to suit.
An example is also found in the Mailgun docs, under the heading "Sending Inline Images" - https://documentation.mailgun.com/user_manual.html#sending-via-api
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With