Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mailgun Inline images, how does it work?

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?

like image 659
Rick A. Avatar asked Sep 03 '25 04:09

Rick A.


2 Answers

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') 
like image 126
israr Avatar answered Sep 04 '25 19:09

israr


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

like image 44
zumek Avatar answered Sep 04 '25 20:09

zumek