Send Email With Attachment using Codeigniter and AJAX

Sending an email is a very common activity in web applications. This tutorial will explain to you How to Send an Email With Attachment Codeigniter. The email send functionality is used to send notification emails to users. Many times we need to send an email with text or HTML content and attachment files. This is a very simple example, you can just copy-paste, and change according to your requirement.
Before started to implement the Send Email With Attachment, look files structure:
  • codeigniter-send-email-with-attachment
    • application
      • config
        • constants.php
        • routes.php
      • controllers
        • Contact.php
      • views
        • Contact
          • index.php
        • mailTemplate
          • contactaForm.php
        • templates
          • header.php
          • footer.php
    • system
    • index.php
    • assets
      • css
        • style.css
      • js
        • custom.js
A simple step-by-step guide to help you Send Email With Attachment Codeigniter
Step 1: Load “email” class in controller.
Step 2: Define constants
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
Create a view file named index.php inside “application/views/contact” folder
Step 5: Create a view(mailTemplate)
Create a view file named contactaForm.php inside “application/views/mailTemplate” folder
Step 6: Create a AJAX file
Create a js file named custom.js inside “assets/js” folder