PHP調用Mailgun發(fā)送郵件的方法
總結PHP 調用Mailgun發(fā)送郵件的方法,供大家參考,具體內容如下
本篇博客參考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或任何其他發(fā)送HTTP消息的庫,它使用一個稱為HTTPlug的抽象,可以靈活的選擇PSR-7或者HTTP客戶端.如果你只是想快速開始,你應該運行以下命令:
php composer.phar require mailgun/mailgun-php php-http/curl-client guzzlehttp/psr7
3.ok,以上工作完成只有,你就可以使用Mailgun進行email的發(fā)送啦~,使用方法參考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.備注:
當然也可以發(fā)送html形式的郵件,只需要將上面例子中的 'text'=>$text 改寫成 'html'=>$html即可,同樣如果想要CC或者BCC等功能,方法于php相同,只需要在上面的array里增加'cc'=>'jack@example.com','bcc'=>'jenny@example.com',即可.
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
詳細Laravel5.5執(zhí)行表遷移命令出現表為空的解決方案
這篇文章主要介紹了詳細Laravel5.5執(zhí)行表遷移命令出現表為空的解決方案,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07laravel withCount 統(tǒng)計關聯數量的方法
今天小編就為大家分享一篇laravel withCount 統(tǒng)計關聯數量的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10