This tutorial provides step by step guide to send email using mailgun SMTP using Codeigniter. Mailgun is a powerful API that enables send,receive and track emails.
Step #1
Let’s create a config.php file in the config/email.php and define $config array in it. You do not need to load this file manually, as the Codeigniter will find this file automatically upon initialization of email class
<?php defined('BASEPATH') OR exit('No direct script access allowed'); /** * Mailgun Configuration */ $config['protocol'] = 'smtp'; $config['smtp_host'] = 'smtp.mailgun.org'; $config['smtp_user'] = '[email protected]'; $config['smtp_pass'] = 'yourpasswordxxxxxxxxxxxxxx'; $config['charset'] = 'utf-8'; $config['mailtype'] = 'html'; $config['email']['newline'] = "rn";
Step #2
The following code should be in the controller/model to execute after a form submission or send button.
$this->load->library('email'); $this->email->from('[email protected]', 'Your Name'); $this->email->to('[email protected]'); $this->email->cc('[email protected]'); $this->email->bcc('[email protected]'); $this->email->subject('Email Test'); $this->email->message('Testing the email class.'); $this->email->send();
Did this post help you?
Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply