Proceed as follows:
- Get the code library by composer
- API Key and domain acquisition
- Write code Send e-mail
1. dependent code library is first acquired, with reference to the official website of the command Composer
https://documentation.mailgun.com/en/latest/libraries.html#php
composer require mailgun/mailgun-php php-http/guzzle6-adapter php-http/message
After the run is complete generation composer.json, composer.lock, vendor folder in the current directory
2. Go mailgun management background, access to API Key and domain
Get domain to obtain API Key
3. Send a message using HTML and text part. This example also attach two files to the message:
# 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' => '[email protected]', 'cc' => '[email protected]', 'bcc' => '[email protected]', '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') ));
After successfully sent as follows: