《PHP學習:PHP調用Mailgun發送郵件的方法》要點:
本文介紹了PHP學習:PHP調用Mailgun發送郵件的方法,希望對您有用。如果有疑問,可以聯系我們。
總結PHP 調用Mailgun發送郵件的方法,供大家參考,具體內容如下PHP實戰
本篇博客參考Mailgun 官方API github鏈接:https://github.com/mailgun/mailgun-phpPHP實戰
1.Mailgun是依賴composer工具,因此在使用之前需要先確認已經安裝了composer.如何安裝composer,非常簡單,下面方法展示如何安裝composer工具:PHP實戰
curl -sS https://getcomposer.org/installer | php
2.Mailgun Api的客戶端沒有硬連接到Guzzle或任何其他發送HTTP消息的庫,它使用一個稱為HTTPlug的抽象,可以靈活的選擇PSR-7或者HTTP客戶端.如果你只是想快速開始,你應該運行以下命令:PHP實戰
php composer.phar require mailgun/mailgun-php php-http/curl-client guzzlehttp/psr7
3.ok,以上工作完成只有,你就可以使用Mailgun進行email的發送啦~,使用方法參考http://www.mailgun.com/官方教程,下面是一個例子:PHP實戰
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.備注:
PHP實戰
當然也可以發送html形式的郵件,只需要將上面例子中的 'text'=>$text 改寫成 'html'=>$html即可,同樣如果想要CC或者BCC等功能,方法于php相同,只需要在上面的array里增加'cc'=>'jack@example.com','bcc'=>'jenny@example.com',即可.PHP實戰
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持維易PHP.PHP實戰
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/859.html