Skip to content
Pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us

How To Send Mail in codeigniter from localhost serever?

February 25, 2021 Pakainfo php, Codeigniter Leave a comment

Today, We want to share with you codeigniter send email from localhost. Email is very important in online any web applications. When a member signs up, i might want to send them an email to verify their email address as well as allow the member to confirm subscription. I also use email to reset forgotten passwords, send invoice as well as receipts to customers, etc. PHP CodeIgniter makes it super easy for us to send emails from our web application using a variety of options.

CodeIgniter has a built-in email library that i can work with when sending emails.

In this tutorial, you will learn simple step by step

  • Email Configuration
  • Email View
  • Email Controller
  • Email Routes

How to Send Email using CodeIgniter?

Today We was working with PHP with codeigniter as well as there is email feature but that need to work on localhost but We stuck at that point. And then some time We got the best solution as well as today I will share that PHP code with you. First of all We tell you PHP codeigniter is great MVC framework as well as We like it very much.

First you required you make an account on mailtrap.io and after making an account you will get username and password for smtp settings and you required to add that config or settings in your CI web site.

Read Also:  Laravel Send Emails Mailgun setup Tutorial

Here is working CI code and you need to add this your PHP codeigniter’s config.php file:

config.php

$config['email'] = Array( 
'protocol'  => 'smtp', 
'smtp_host' => 'smtp.mailtrap.io', 
'smtp_port' =>  2525, 
'smtp_user' => 'your_user_name', 
'smtp_pass' => 'your_user_pass', 
'crlf'      => "\r\n", 
'newline'   => "\r\n"

In this first step I will download the latest version of Codeigniter, first of all simple you can Go to this link Download Codeigniter.

Create Contact Form And Send Email using PHP
Create Contact Form And Send Email using PHP

CodeIgniter Email Configuration

application/config/email.php
here simple Create a file email.php in the directory application/config

<?php defined('BASEPATH') OR exit('No direct script access allowed');

$config = array(
    'protocol' => 'smtp', // 'mail', 'sendmail', or 'smtp'
    'smtp_host' => 'smtp.example.com', 
    'smtp_port' => 465,
    'smtp_user' => '[email protected]',
    'smtp_pass' => '12345!',
    'smtp_crypto' => 'ssl', //can be 'ssl' or 'tls' for example
    'mailtype' => 'text', //plaintext 'text' mails or 'html'
    'smtp_timeout' => '4', //in seconds
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE
);

Basic Configurations

$config['base_url'] = 'http://localhost/demo';

CodeIgniter Email View

application/views/email/contact.php

<!DOCTYPE html>
<html>
    <head>
        <title>CodeIgniter Send Email - www.pakainfo.com</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div>
            <h3>Use the form below to send email</h3>
            <form method="post" action="<?=base_url('email')?>" enctype="multipart/form-data">
                <input type="email" id="to" name="to" placeholder="Receiver Email">
                <br><br>
                <input type="text" id="subject" name="subject" placeholder="Enter Your Subject">
                <br><br>
                <textarea rows="6" id="message" name="message" placeholder="Type your message here"></textarea>
                <br><br>
                <input type="submit" value="Send Email" />
            </form>
        </div>
    </body>
</html>

Free Live Chat for Any Issue

CodeIgniter Email Controller

application/controllers/SendEmailCtrl.php

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class SendEmailCtrl extends CI_Controller {

    public function __construct() {
        parent:: __construct();

        $this->load->helper('url');
    }

    public function index() {
        $this->load->view('email/contact');
    }

    function send() {
        $this->load->config('email');
        $this->load->library('email');
        
        $from = $this->config->item('smtp_user');
        $to = $this->input->post('to');
        $subject = $this->input->post('subject');
        $message = $this->input->post('message');

        $this->email->set_newline("\r\n");
        $this->email->from($from);
        $this->email->to($to);
        $this->email->subject($subject);
        $this->email->message($message);

        if ($this->email->send()) {
            echo 'Your Email has successfully been sent.';
        } else {
            show_error($this->email->print_debugger());
        }
    }
}

Email Routes call to methods

Add the bellow routes to application/config/routes.php

$route['send-email'] = 'your email controller';
$route['email'] = 'your email controller/send';

PHP Mail Attachment – Php Send Email File-Images Attachments
PHP Mail Attachment – Php Send Email File-Images Attachments

how to send email from localhost with php CodeIgniter?

Here you can check the PHP source code for send email from localhost server simple step.

function sendMail()
{
   $config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'ssl://smtp.googlemail.com',
  'smtp_port' => 465,
  'smtp_user' => '[email protected]_address.com', // Update it to yours
  'smtp_pass' => '[email protected]', // Update it to yours
  'mailtype' => 'html',
  'charset' => 'iso-8859-1',
  'wordwrap' => TRUE
);

	$message = '';
	$this->load->library('email', $config);
	$this->email->set_newline("\r\n");
	$this->email->from('[email protected]_address.com'); // Update it to yours
	$this->email->to('[email protected]_address.com');// Update it to yours
	$this->email->subject('Send email by using codeigniter library via localhost For Testing');
	$this->email->message($message);
	if($this->email->send())
	{
		echo 'Good Luck Your Email sent.';
	}
	else
	{
		show_error($this->email->print_debugger());
	}

}

Download

I hope you get an idea about send link in email codeigniter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Pakainfo
Pakainfo

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Read Also:  PHP Laravel Interview Questions and Answers

Related posts:

  1. How to send mail from localhost XAMPP using PHP?
  2. how to send attachment in mail in php?
  3. php send mail attachment with Pear Mail
  4. Mail send with attachment in php demo
  5. How to send email in php? | php code to send email on button click
  6. How to Send Emails in Laravel?
  7. php – SMTP Send mail using PHPMailer PHP Contact Form
  8. PHP Send Email using SMTP Authentication
  9. Send email using nodejs and express in Nodemailer steps
Read Also:  Understanding Join Queries in Laravel [joins in laravel]
codeigniter emailcodeigniter email configcodeigniter email examplecodeigniter email librarycodeigniter email library downloadCodeIgniter Librariescodeigniter libraries listcodeigniter mailcodeigniter mail functioncodeigniter send emailcodeigniter send email html formatcodeigniter send email with attachmentcodeigniter send html emailcodeigniter smtp emaile-maileremail codeemail codeigniteremail htmlemail in codeigniteremail library in codeigniteremail protocolemail send in codeigniteremail sending in codeigniterhow to send email in codeigniterhow to send email in codeigniter using smtphow to send mail in codeigniterhow to send mail using javascripthow to send multiple emails in phphtml code to send email with attachmenthtml email codehtml email examplejavascript code to send email automaticallylibraries in codeignitermailmail function in codeignitermail in codeignitermail send in codeigniterphp mail librarysend arraysend e-mail tosend email codeignitersend email in codeignitersend email using javascript codesend mail in codeignitersend mail to multiple recipients phpsending nice html email with phpsendmail in phpsendmail phpsimple mail in phptext type in html

Post navigation

Previous Post:How to implement a switch-case statement in Python?
Next Post:how to refresh page without losing form data javascript?

Search

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (49) Ajax (464) AngularJS (377) ASP.NET (61) Bollywood (93) Codeigniter (175) CSS (98) Earn Money (61) Education (53) Entertainment (109) fullform (79) Google Adsense (62) Highcharts (77) Hollywood (94) JavaScript (1356) Jobs (39) jQuery (1422) Laravel (1086) LifeStyle (50) movierulz4 (48) Mysql (1029) Mysqli (890) Node.js (39) php (2116) Programming (2328) Python (96) ReactJS (37) Software (112) Software (81) Stories (87) tamilrockers (89) Tamilrockers kannada (49) Tamilrockers telugu (48) Tech (120) Technology (2372) Tips and Tricks (112) Tools (137) Top10 (338) Trading (56) Trending (54) VueJs (250) Web Technology (86) webtools (151) wordpress (165) World (165)

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
Cricday

  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • YouTube Monetization
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

© 2022 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype YouTube Tag Extractor