Là một dự án mã nguồn mở, mailgun/mailgun-php đã đạt 1.1k sao trên GitHub, ngôn ngữ PHP. Mailgun's Official SDK for PHP
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
// Add IP to a domain
$mg->ips()->assign('example.com', '1.2.3.4');
// Remove IP from a domain
$mg->ips()->unassign('example.com', '1.2.3.4');
// List IPs currently assigned to a domain
$response = $mg->ips()->domainIndex('example.com');
print_r($response->getItems());
Bulk IP operations across all domains
// Assign an IP to every domain in the account (async)
$ref = $mg->ips()->assignIpToAllDomains('1.2.3.4');
echo $ref->getReferenceId(); // track the async operation
// Remove an IP from all domains, replacing it with another
$ref = $mg->ips()->removeIpFromAllDomains('1.2.3.4', alternative: '5.6.7.8');
echo $ref->getMessage();
// Move an account IP into a dedicated IP band
$mg->ips()->placeAccountIpToBand('1.2.3.4');
Request a new dedicated IP
// Check how many dedicated IPs your plan allows
$available = $mg->ips()->numberOfIps();
// Provision a new dedicated IP
$mg->ips()->addDedicatedIp();
Dynamic IP Pools (DIPP)
Dynamic IP Pools let you group dedicated IPs and link them to domains, so sending traffic is spread across all IPs in the pool automatically.
List and inspect pools
// All pools in the account
$response = $mg->ips()->listIpPools();
foreach ($response->getIpPools() as $pool) {
echo "{$pool['pool_id']} — {$pool['name']}" . PHP_EOL;
echo " IPs: " . implode(', ', $pool['ips']) . PHP_EOL;
echo " Linked to domains: " . ($pool['is_linked'] ? 'yes' : 'no') . PHP_EOL;
}
// Single pool details
$pool = $mg->ips()->loadDIPPInformation('my-pool-id');
echo $pool->getPoolId(); // "my-pool-id"
echo $pool->getName(); // "Primary sending pool"
echo $pool->getDescription(); // "Main US sending pool"
print_r($pool->getIps()); // ["1.2.3.4", "5.6.7.8"]
var_dump($pool->isLinked()); // bool — whether domains are attached
Create and configure a pool
// Create a new pool
$mg->ips()->createIpPool('Primary Pool', 'Main US outbound pool');
// Modify pool metadata, add/remove IPs, link/unlink domains — all in one call
$mg->ips()->updateIpPool('my-pool-id', [
'name' => 'Primary Pool v2',
'add_ip' => '9.10.11.12',
'remove_ip' => '1.2.3.4',
'link_domain' => 'example.com',
'unlink_domain' => 'old.example.com',
]);
Manage IPs inside a pool
// Add a single IP to a pool
$mg->ips()->addIpToPool('my-pool-id', '9.10.11.12');
// Add multiple IPs at once
$mg->ips()->addIpsToPool('my-pool-id', ['9.10.11.12', '13.14.15.16']);
// Remove an IP from a pool
$mg->ips()->removeIpFromPool('my-pool-id', '1.2.3.4');
When a pool is linked to domains, adding or removing IPs propagates to all linked domains asynchronously after the API responds.
List domains linked to a pool
$response = $mg->ips()->getIpPoolDomains('my-pool-id', limit: 20);
foreach ($response->getDomains() as $domain) {
echo $domain['name'] . PHP_EOL;
}
// Paginate using the cursor from the previous response
if ($response->getNextPage()) {
$next = $mg->ips()->getIpPoolDomains('my-pool-id', page: $response->getNextPage());
}
Delete a pool
// Delete without replacement (pool must not be linked to any domains)
$mg->ips()->deleteDIPP('my-pool-id');
// Replace linked domains with a specific IP before deleting
$mg->ips()->deleteDIPP('my-pool-id', replacementIp: '1.2.3.4');
// Replace linked domains with another pool before deleting
$mg->ips()->deleteDIPP('my-pool-id', replacementPoolId: 'backup-pool-id');
Delegate a pool to a subaccount
// Grant a subaccount access to a pool
$mg->ips()->delegateIpPool('my-pool-id', 'sub-account-id');
// Revoke subaccount access
$mg->ips()->revokeDelegatedIpPool('my-pool-id', 'sub-account-id');
// Create a subaccount
$mg->subaccounts()->create('Marketing Team');
// List all subaccounts
$items = $mg->subaccounts()->index();
print_r($items->getItems());
// Enable / disable
$mg->subaccounts()->enable($subAccountId);
$mg->subaccounts()->disable($subAccountId);
Make API calls on behalf of a subaccount
// Pass the subaccount ID as the third argument to Mailgun::create()
$mg = Mailgun::create('your-api-key', 'https://api.mailgun.net', $subAccountId);
// All subsequent calls are scoped to that subaccount
$mg->messages()->send('example.com', [...]);
Response Handling
All API methods return typed model objects with IDE-friendly getters by default.
use Mailgun\Hydrator\ArrayHydrator;
use Mailgun\HttpClient\HttpClientConfigurator;
$configurator = new HttpClientConfigurator();
$configurator->setApiKey('your-api-key');
$mg = new Mailgun($configurator, new ArrayHydrator());
$data = $mg->domains()->show('example.com');
// $data is now a plain associative array
Raw PSR-7 response
Need the raw response? Use NoopHydrator — note: no exceptions are thrown on non-200 responses when using this hydrator.
use Mailgun\Hydrator\NoopHydrator;
$mg = new Mailgun($configurator, new NoopHydrator());
$response = $mg->messages()->send('example.com', [...]);
// $response is a Psr\Http\Message\ResponseInterface
echo $response->getStatusCode();
Debugging
Route traffic through Mailgun's Postbin to inspect what the SDK sends:
use Mailgun\HttpClient\HttpClientConfigurator;
use Mailgun\Hydrator\NoopHydrator;
$configurator = new HttpClientConfigurator();
$configurator->setEndpoint('http://bin.mailgun.net/aecf68de'); // replace with your bin ID
$configurator->setApiKey('your-api-key');
$configurator->setDebug(true);
$mg = new Mailgun($configurator, new NoopHydrator());
$mg->messages()->send('example.com', [
'from' => '[email protected]',
'to' => '[email protected]',
'subject' => 'Debug test',
'text' => 'Checking what hits the wire.',
]);
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/mailgun/mailgun-php là nguồn chính thức.
mailgun/mailgun-php có bao nhiêu sao?
mailgun/mailgun-php có 1.1k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/mailgun/mailgun-php. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
mailgun/mailgun-php có phải mã nguồn mở không?
Có — mailgun/mailgun-php phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/mailgun/mailgun-php.
mailgun/mailgun-php có trang demo không?
Dự án có trang chủ ở http://www.mailgun.com. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
mailgun/mailgun-php là gì?
mailgun/mailgun-php (mailgun/mailgun-php) là dự án PHP trên GitHub. Theo mô tả gốc: Mailgun's Official SDK for PHP
Đọc đầy đủ README ở tab phía trên.
Chưa chắc mailgun-php có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về mailgun-php.