步骤如下:

  1. 通过 composer 获取代码库
  2. 获取 API Key 以及 domain
  3. 编写代码发送邮件

1. 首先通过 composer 获取依赖代码库,参考官网给的命令 
https://documentation.mailgun.com/en/latest/libraries.html#php

 
composer require mailgun/mailgun-php php-http/guzzle6-adapter php-http/message

 


运行完成后在当前目录下生成 composer.json、composer.lock、vendor文件夹

mailgun php 邮件发送 实例


2. 进入 mailgun 管理后台,获取 API Key 以及 domain

mailgun php 邮件发送 实例获取 domainmailgun php 邮件发送 实例获取 API Key


3. 使用HTML和文本部分发送消息。此示例还将两个文件附加到邮件中:

 
# 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')
));

 


发送成功后如下:

mailgun php 邮件发送 实例

相关文章:

  • 2021-10-27
  • 2021-09-21
  • 2021-07-24
  • 2022-01-15
  • 2022-12-23
猜你喜欢
  • 2021-11-28
  • 2021-09-11
  • 2021-12-09
  • 2021-11-28
  • 2022-03-08
  • 2021-11-28
  • 2021-11-28
相关资源
相似解决方案