Today:July 1, 2020

Simple Ajax Form With Email Attachment Using PHP

Today, We are going to learn steps to Ajax Form With Email Attachment Using PHP without refreshing the page. Below is the step by step explanation.

Before we are getting started, we need a little bit of knowledge about HTML, CSS, PHP and jQuery.

  1. HTML form that will collect the information from the user
  2. Ajax will gather all the data submitted by the form and send to process.php to send an email
  3. process.php will check whether the attachment is there or not and trigger an email.

Filename: index.html

This is the page where we have a simple form that collects all the information from the user to send an email via PHP mail.

Above form have fields like First Name, Email Address and File attachment. Each input filed has its unique ID to fetch the data once the form has submitted.

Note : We have set  enctype=”multipart/form-data” . This is used for file attachment.

The script that gather all information submitted by the Form and pass the data to process.php to send an email.

process.php

Demo

14 Comments

  1. idm crack youtube Reply

    I do not even know how I ended up here, but I believed this submit used to be great. I don’t recognize who you might be but certainly you’re going to a well-known blogger should you are not already Cheers!

    1. avsquare Post author Reply

      Place below code above Line Number 80 . This will help you to upload only with extensions of PDF, DOC, DOCX files.

      $allowedExts = array( "pdf", "doc", "docx" );
      $extension = end(explode(".", $_FILES['file_attach']['name'] ));

      if ( ! ( in_array($extension, $allowedExts ) ) ) {
      $output = json_encode(array('type'=>'error', 'text' => 'Only PDF, DOC and DOCX extensions are allowed'));
      die($output);
      }

  2. shikhar Reply

    The demo is working fine but the download link is incorrect.

    After copying the script, I received the mail but the the attached file got corrupted.

    Please suggest.

  3. check here Reply

    I simply want to mention I’m all new to blogs and certainly loved you’re website. Most likely I’m likely to bookmark your site . You definitely come with impressive articles. Thanks for revealing your website.

Leave a Reply

Your email address will not be published. Required fields are marked *

one × two =

Top