How to send out HTML email with mailgun?

前端 未结 2 1699
清歌不尽
清歌不尽 2021-02-05 10:06

after failed to find a solution for my problem in the mailgun documentation, I will explain what I\'m looking for.

Today I\'m using phpList to send out my newsletter (It

相关标签:
2条回答
  • 2021-02-05 10:29

    I have used external html template in this way. It may be help you.

    $html  = file_get_contents('my_template.html'); // this will retrieve the html document
    

    and then:

    $result = $mgClient->sendMessage("$domain",
           array('from'    => 'My Business Name <me@samples.mailgun.org>',
                 'to'      => 'name-1@gmail.com, name-3@gmail.com, name-3@gmail.com',
                 'subject' => 'Issue Feb 2014',
                 'text'    => 'Your mail do not support HTML',
                 'html'    => $html,
                 'recipient-variables' => '{"name-1@gmail.com": {"first":"Name-1", "id":1}, "name-2@gmail.com": {"first":"Name-2", "id": 2}}'), 
           array('inline' => 'Pad-Thai-1.jpg'));
    

    Check this line:

    'html'    => $html,
    
    0 讨论(0)
  • 2021-02-05 10:29

    Adding a link to Mailgun documentation. This helped me while constructing HTML and MIME messages. https://documentation.mailgun.com/api-sending.html#examples

    As per documentation:

    # Include the Autoloader (see "Libraries" for install instructions)
    require 'vendor/autoload.php';
    use Mailgun\Mailgun;
    
    # Instantiate the client.
    $mgClient = new Mailgun('YOUR_API_KEY');
    $domain = "YOUR_DOMAIN_NAME";
    
    # Make the call to the client.
    $result = $mgClient->sendMessage($domain, array(
        'from'    => 'Excited User <YOU@YOUR_DOMAIN_NAME>',
        'to'      => 'foo@example.com',
        'cc'      => 'baz@example.com',
        'bcc'     => 'bar@example.com',
        'subject' => 'Hello',
        'text'    => 'Testing some Mailgun awesomness!',
        'html'    => '<html>HTML version of the body</html>'
    ), array(
        'attachment' => array('/path/to/file.txt', '/path/to/file.txt')
    ));
    
    0 讨论(0)
提交回复
热议问题