PHP實現調用Mailgun發送郵件的方法

來源:互聯網
上載者:User
這篇文章主要為大家詳細介紹了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',即可.

以上就是本文的全部內容,希望對大家的學習有所協助。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.