?>

Integrate Mailgun with MySQL

Appy Pie Connect allows you to automate multiple workflows between Mailgun and MySQL

  • No code
  • No Credit Card
  • Lightning Fast Setup
20 Million man hours saved

Award Winning App Integration Platform

About Mailgun

Mailgun is the email automation engine trusted by over millions of websites and application developers for sending, receiving and tracking emails.

About MySQL

MySQL is currently the most popular database management system software used for managing the relational database.

MySQL Integrations
MySQL Alternatives

Looking for the MySQL Alternatives? Here is the list of top MySQL Alternatives

  • PostgreSQL Integration PostgreSQL

Best Mailgun and MySQL Integrations

  • Mailgun Integration MySQL Integration

    Mailgun + MySQL

    Update Row in MySQL when New Unsubscriber is created in Mailgun Read More...
    Close
    When this happens...
    Mailgun Integration New Unsubscriber
     
    Then do this...
    MySQL Integration Update Row
  • Mailgun Integration MySQL Integration

    Mailgun + MySQL

    Create Row to MySQL from New Unsubscriber in Mailgun Read More...
    Close
    When this happens...
    Mailgun Integration New Unsubscriber
     
    Then do this...
    MySQL Integration Create Row
  • Mailgun Integration MySQL Integration

    Mailgun + MySQL

    Delete Row in MySQL when New Unsubscriber is created in Mailgun Read More...
    Close
    When this happens...
    Mailgun Integration New Unsubscriber
     
    Then do this...
    MySQL Integration Delete Row
  • Mailgun Integration MySQL Integration

    Mailgun + MySQL

    Update Row in MySQL when New Subscriber is created in Mailgun Read More...
    Close
    When this happens...
    Mailgun Integration New Subscriber
     
    Then do this...
    MySQL Integration Update Row
  • Mailgun Integration MySQL Integration

    Mailgun + MySQL

    Create Row to MySQL from New Subscriber in Mailgun Read More...
    Close
    When this happens...
    Mailgun Integration New Subscriber
     
    Then do this...
    MySQL Integration Create Row
  • Mailgun Integration {{item.actionAppName}} Integration

    Mailgun + {{item.actionAppName}}

    {{item.message}} Read More...
    Close
    When this happens...
    {{item.triggerAppName}} Integration {{item.triggerTitle}}
     
    Then do this...
    {{item.actionAppName}} Integration {{item.actionTitle}}
Connect Mailgun + MySQL in easier way

It's easy to connect Mailgun + MySQL without coding knowledge. Start creating your own business flow.

    Triggers
  • New Subscriber

    Triggers whenever a new subscriber is added.

  • New Unsubscriber

    Triggers when a current subscriber unsubscribed.

  • New Row

    Triggered when you add a new row.

  • New Row (Custom Query)

    Triggered when new rows are returned from a custom query that you provide. Advanced Users Only

  • New Table

    Triggered when you add a new table.

    Actions
  • Create Row

    Adds a new row.

  • Delete Row

    Delete a row.

  • Update Row

    Updates an existing row.

Compliance Certifications and Memberships

Highly rated by thousands of customers all over the world

We’ve been featured on

featuredon
Page reviewed by: Abhinav Girdhar  | Last Updated on July 01, 2022 5:55 am

How Mailgun & MySQL Integrations Work

  1. Step 1: Choose Mailgun as a trigger app and authenticate it on Appy Pie Connect.

    (30 seconds)

  2. Step 2: Select "Trigger" from the Triggers List.

    (10 seconds)

  3. Step 3: Pick MySQL as an action app and authenticate.

    (30 seconds)

  4. Step 4: Select a resulting action from the Action List.

    (10 seconds)

  5. Step 5: Select the data you want to send from Mailgun to MySQL.

    (2 minutes)

  6. Your Connect is ready! It's time to start enjoying the benefits of workflow automation.

Integration of Mailgun and MySQL

There are many ways to send emails, from simple SMTP servers that allow a single email address per account, to more complex applications such as Amazon SES, all the way to custom-built messaging sputions. Sending email can be problematic for startups and small businesses because of the cost associated with the service or software used. Even if the cost is very low (as it is with SES), every dplar counts in a startup environment.A startup's needs are different from those of larger companies. They may not need a full-fledged spution, but something that allows them to send transactional emails will suffice.Mailgun was created to fill this need. It offers a simple way to send and receive email via APIs.Mailgun was founded in 2011 by Tony Armirillo and Gabriel Munteanu. They saw an opportunity to create a top that would allow easy and affordable delivery of email without the need for an IT department. Mailgun's goal is to make email delivery accessible to everyone, regardless of their size.This makes Mailgun an interesting option when considering how to send email from a PHP application, because it's easy to integrate Mailgun into a website without spending a lot of time dealing with configuration files and command line interfaces.Mailgun offers two plans. starter and pro. The starter plan costs $0.0075 per email, while pro costs $0.01 per email. This price includes everything needed to send up to 12,000 emails per month. The free trial lasts 14 days, after which you must upgrade to a paid plan if you want to continue using Mailgun.Mailgun integrates nicely with MySQL, which is another important consideration when building an application that sends email. MySQL provides a complete suite of tops for storing and retrieving data. It's one of the most popular open source relational databases used on the internet today, and it works well with PHP.The integration between Mailgun and MySQL makes it easy to build an application that sends and receives mail; all you have to do is connect the two services together using PHP and you're set.With this in mind, this article will describe how to integrate Mailgun with MySQL using PHP and MySQLi in order to send transactional email through a web application.

Integrating Mailgun and MySQL is straightforward because both are written in PHP.The first step is to register for a Mailgun account at http://www.mailgun.com/signup/. This will give you access to your own domain's dashboard where you can manage your domain, create lists (these are like groups of users), and view statistics about your account usage.The next step is to install Mailgun's API library for PHP, which can be found on GitHub at https://github.com/mailgun/mailgun-php-client , or installed with the Composer dependency manager (http://getcomposer.org/. The library can be used as is, or extend it - however you choose - to add features specific to your application.Next, create two new tables in your MySQL database using the fplowing SQL script:CREATE TABLE domain_config (id int(11. NOT NULL AUTO_INCREMENT,name varchar(255. DEFAULT NULL,type varchar(64. DEFAULT NULL,PRIMARY KEY (id),UNIQUE KEY name (name));CREATE TABLE mailboxes (id int(11. NOT NULL AUTO_INCREMENT,type varchar(64. DEFAULT NULL,PRIMARY KEY (id),UNIQUE KEY type (type,`domain_id`));The domain_config table contains information about your account such as which domains you have access to and whether or not you want reporting enabled for those domains. The mailboxes table contains information about your users' inboxes - or mailboxes - so that you can assign each mailbox its own unique identifier. This identifier is used when creating and updating a user's account settings and preferences in your application's database so that you can associate their account with a particular mailbox on the Mailgun server. Also note that the domain_id cpumn is used as a foreign key for the mailbox table because they share the same value for the domain name - just replace example1.com with your own domain or subdomain name when using this script.The next step is to create a new file called config/config_local.php in your project fpder, which will contain your configuration settings for this application that are specific to your setup. The Mailgun library uses local configuration files so that you only have to specify your configuration settings once instead of having to rewrite them for every page that makes use of the library. The fplowing code shows an example configuration file containing the database connection settings for your application. <?php return array( 'domain' => 'example1.com', 'secret' => 'apikeygoeshere', 'dbname' => 'mailgun', 'username' => 'mailgunguest', 'password' => 'passwordgoeshere', ); ?> Replace example1.com with your own domain name and then run composer update in order to pull in the latest version of the mailgun-php-client library into your project directory so that you can start using it. You also need to add the Mailgun library's autpoader script to the list of scripts that will be loaded by Composer after adding your new dependencies. require __DIR__ . '/vendor/autpoad.php'; Now that you have connected Mailgun and MySQL in order to send and receive email through a PHP application, you can start sending messages! First, create a new file called functions_mailing.php and store it in your functions directory along with any other custom functions that might be useful throughout your application, such as this one. function sendMessage($user_id = null. { global $config; $domain = $config['domain']; $user = $config['db']->fetchOne('SELECT * FROM mailboxes WHERE type = :type AND domain_id = :domain_id', array(':type' => 'user', ':domain_id' => $domain)); if ($user. { $mailbox_id = $user['mailbox_id']; } if ($user_id. { $mailbox_id = $user_id; } $message = array( 'received' => date('r'), 'from' => array('name' => 'Name Sender <[email protected]>'), 'to' => array('mailbox_id' => $mailbox_id), 'subject' => "You have message #$message[message_id]", 'text' => "Message body" ); Mail::send('send', array( 'to' => array('email' => $user['email']), 'cc' => array('email' => "[email protected]"), 'bcc' => array('email' => "[email protected]"), 'reply_to' => array('email' => "[email protected]"), 'params' => json_encode($message), )); exit; } } The function accepts one argument, which is an ID representing an entry in the mailboxes table in MySQL that has been assigned to one of your users in your application's database - more on that later - or null if no ID is passed in on the command line when calling this function from another part of your codebase or from the command line via SSH or similar (more on that later as well), then runs some basic checks to make sure all required values are set before sending an email via Mailgun using the Mail::send(. method provided by the Mailgun library included earlier in this article. If no good values were entered during execution of this function then it returns false; otherwise it returns true . The rest should be self-explanatory if you understand what's going on under the hood, but here are a few things worth pointing out just in case. 1.. The subject line says "You have message" instead of "You have message X". That's because I wanted each user's mailbox counter to start at one instead of having it reset at zero every time someone subscribes to my mailing list through my website (which will be covered later. 2.. The text portion of the message is plaintext only - no HTML allowed! 3.. You can change cc and bcc recipients by replacing their

The process to integrate Mailgun and MySQL may seem complicated and intimidating. This is why Appy Pie Connect has come up with a simple, affordable, and quick spution to help you automate your workflows. Click on the button below to begin.