這篇文章主要為大家詳細介紹了PHP調用Mailgun發送郵件的方法,具有一定的參考價值,感興趣的小夥伴們可以參考一下
總結PHP 調用Mailgun發送郵件的方法,供大家參考,具體內容如下
本篇部落格參考Mailgun 官方API github連結:https://github.com/mailgun/mailgun-php
1.Mailgun是依賴composer工具,因此在使用之前需要先確認已經安裝了composer.如何安裝composer,非常簡單,下面方法展示如何安裝composer工具:
curl -sS https://getcomposer.org/installer | php
2.Mailgun Api的用戶端沒有硬串連到Guzzle或任何其他發送HTTP訊息的庫,它使用一個稱為HTTPlug的抽象,可以靈活的選擇PSR-7或者HTTP用戶端.如果你只是想快速開始,你應該運行以下命令:
php composer.phar require mailgun/mailgun-php php-http/curl-client guzzlehttp/psr7
3.ok,以上工作完成只有,你就可以使用Mailgun進行email的發送啦~,使用方法參考http://www.mailgun.com/官方教程,下面是一個例子:
require 'vendor/autoload.php';use Mailgun\Mailgun;# First, instantiate the SDK with your API credentials and define your domain. $mg = new Mailgun("key-example");$domain = "example.com";# Now, compose and send your message.$mg->sendMessage($domain, array('from' => 'bob@example.com', 'to' => 'sally@example.com', 'subject' => 'The PHP SDK is awesome!', 'text' => 'It is so simple to send a message.'));
4.備忘:
當然也可以發送html形式的郵件,只需要將上面例子中的 'text'=>$text 改寫成 'html'=>$html即可,同樣如果想要CC或者BCC等功能,方法於php相同,只需要在上面的array裡增加'cc'=>'jack@example.com','bcc'=>'jenny@example.com',即可.
以上就是本文的全部內容,希望對大家的學習有所協助。