Sending email by Mailgun using Codeigniter
In this tutorial, We will inform you how to send an email by mailgun using Codeigniter. mailgun is an email tracking tool so we can easily track every email.
We will use mailgun tool to send emails. so first we will set the configuration of setting mailgun in Codeigniter. so you can follow the below steps for the configuration setting.
Step 1: Configuration of Email
First, we will create an email.php file in application/config/ directory.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php defined('BASEPATH') OR exit('No direct script access allowed'); /** * Mailgun Configuration */ $config['protocol'] = 'smtp'; $config['smtp_host'] = 'smtp.mailgun.org'; $config['smtp_user'] = 'here your user'; $config['smtp_pass'] = 'here your password'; $config['charset'] = 'utf-8'; $config['mailtype'] = 'html'; $config['email']['newline'] = "rn"; ?> |
Step 2: Use In Controller
In this step, we will load the email library in this controller. so we can easily send mail using this mailgun email library.
1 2 3 4 5 6 7 8 9 10 11 12 | <?php $this->load->library('email'); $this->email->subject('Your Subject'); $this->email->message('Your Message'); try { $this->email->send(); echo 'Message has been sent.'; } catch(Exception $e) { echo $e->getMessage(); } |
Please follow and like us: