Create AJAX Contact Form in CodeIgniter and Send Email via SMTP Server

A contact page is a standard web page on a website used to allow the visitor to contact the website owner.CodeIgniter AJAX contact form is used to send contact information without page refresh and use both side validation client and server. In this tutorial, We have to share a simple AJAX-based Contact Form in CodeIgniter and Send Email via SMTP Server. The post covered in easy steps with a live demo to create AJAX Contact Form in CodeIgniter with Email. This is a very simple example, you can just copy-paste, and change according to your requirement.
Before started to implement the Create AJAX Contact Form in CodeIgniter and Send Email via SMTP Server, look files structure:
  • codeigniter-create-ajax-contact-form-smtp
    • application
      • config
        • autoload.php
        • constants.php
        • routes.php
      • controllers
        • Contact.php
      • views
        • contact
          • index.php
        • templates
          • header.php
          • footer.php
    • system
    • index.php
    • assets
      • css
        • style.css
      • js
        • common.js
Step 1: Load “email” class in controller.
Step 2: Define constant
Update file named constants.php inside “application/config/” folder.
Step 3: Create a controller file
Create a controller file named Contact.php inside “application/controllers” folder.
Step 4:Create a view(header)
Create a view file named header.php inside “application/views/templates” folder.
This view contains the header section of the webpage. The Bootstrap library is used to provide a better UI, so, include it in the header section.
Step 5: Create a view(footer)
Create a view file named footer.php inside “application/views/templates” folder.
This view contains the footer section of the webpage.
Step 5: Create a view
Create a view file named index.php inside “application/views/contact” folder.
Step 6: Create a view(mailTemplate)
Create a view file named contactForm.php inside “application/views/mailTemplate” folder
Step 7: Create a AJAX file
Create a js file named custom.js inside “assets/js” folder.