PHP calls Mailgun to send an email and mailgun to send an email.

Source: Internet
Author: User

PHP calls Mailgun to send an email and mailgun to send an email.

Summary: PHP calls Mailgun to send emails for your reference. The details are as follows:

This blog reference Mailgun official API github link: https://github.com/mailgun/mailgun-php

1. Mailgun depends on the composer tool. Therefore, it is very easy to install composer before using it. The following method shows how to install the composer tool:

curl -sS https://getcomposer.org/installer | php

2. the client of the Mailgun Api does not have a hard connection to Guzzle or any other library that sends HTTP messages, it uses an abstraction called HTTPlug, which can be flexibly selected for PSR-7 or HTTP clients. if you just want to start quickly, you should run the following command:

php composer.phar require mailgun/mailgun-php php-http/curl-client guzzlehttp/psr7

3. OK. You can use Mailgun to send emails only after the preceding steps are completed ~, For more information, see http://www.mailgun.com/official tutorial. The following is an example:

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. Remarks:

Of course, you can also send emails in html format.'Text' => $ textRewrite'Html' => $ htmlIf you want CC, BCC, and other functions in the same way as php, you only need to add 'cc' => 'Jack @ example.com 'to the array above ', 'bcc '=> 'jenny @ example.com', you can.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.