How to display success message in a form submit after sending a mail successfully using malsup form jquery without page refresh

Rama Priya

I need to display success message after uploading a form and send it as an attachment in mail.I need to implement this by using malups form js.How to write jquery function for this and also i have to do this without refresh the page.

By using the ajaxForm function() i can able to display alert instead of this i need to show a success message in a div after sending the mail successfully with attachment.

php

 <?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

   // Set the "To" email address
   $to="[email protected]";

    //Subject of the mail
   $subject="Join Us E-mail with Resume attachment";



    // Check for empty fields

    if($_FILES['filename']['tmp_name']==""){
            echo '<font style="font-family:Verdana, Arial; font-size:11px; color:#F3363F; font-weight:bold">Please upload your resume</font>';
        }

   //if(empty($_POST['name'])  || empty($_POST['email']) || empty($_POST['message']))
//  {
//      /*$errors .= "\n Error: all fields are required";*/
//       echo '<font style="font-family:Verdana, Arial; font-size:11px; color:#F3363F; font-weight:bold">Please upload resume</font>';
//  }



   // Now Generate a random string to be used as the boundary marker
   $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

   // Now Store the file information to a variables for easier access
   $tmp_name = $_FILES['filename']['tmp_name'];
   $type = $_FILES['filename']['type'];
   $file_name = $_FILES['filename']['name'];
   $size = $_FILES['filename']['size'];

   // Now here we setting up the message of the mail
   $message = "Uploaded file: $file_name";

   // Check if the upload succeded, the file will exist
   if (file_exists($tmp_name)){

      // Check to make sure that it is an uploaded file and not a system file
      if(is_uploaded_file($tmp_name)){

         // Now Open the file for a binary read
         $file = fopen($tmp_name,'rb');

         // Now read the file content into a variable
         $data = fread($file,filesize($tmp_name));

         // close the file
         fclose($file);

         // Now we need to encode it and split it into acceptable length lines
         $data = chunk_split(base64_encode($data));
     }

      // Now we'll build the message headers
      $headers = "From: $from\r\n" .
         "MIME-Version: 1.0\r\n" .
         "Content-Type: multipart/mixed;\r\n" .
         " boundary=\"{$mime_boundary}\"";

      // Next, we'll build the message body note that we insert two dashes in front of the  MIME boundary when we use it
      $message = "This is a multi-part message in MIME format.\n\n" .
         "--{$mime_boundary}\n" .
         "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
         "Content-Transfer-Encoding: 7bit\n\n" .
         $message . "\n\n";

      // Now we'll insert a boundary to indicate we're starting the attachment we have to specify the content type, file name, and disposition as an attachment, then add the file content and set another boundary to indicate that the end of the file has been reached
      $message .= "--{$mime_boundary}\n" .
         "Content-Type: {$type};\n" .
         " name=\"{$file_name}\"\n" .
         //"Content-Disposition: attachment;\n" .
         //" filename=\"{$fileatt_name}\"\n" .
         "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n" .
         "--{$mime_boundary}--\n";

      // Thats all.. Now we need to send this mail... :)
      if (@mail($to, $subject, $message, $headers))
      {
       echo "success"; 
      }else
      {
         echo "failed";
      }
   }
}
?>

HTML

<form id="myform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">

<input id="tele" type="file" name="filename"/>
<br/>
<input  class="formbtn" type="submit" id="upload" value="Upload" />
</form>

Jquery

<script>
$(document).ready(function () {

    $('#myform').validate({
        rules: {
            filename: {
                required: true,
                extension: "docx|rtf|doc|pdf"
            }
        },
        messages: {
            filename: {
                required: "Please upload resume",
                extension: "Please upload valid file formats"
            }
        }
    });

});
</script>
<script> 
    $(document).ready(function() { 
        $('#myform').ajaxForm(function() { 

           alert('success');
        }); 
    }); 

</script> 
minas

Before the below code make sure you have a div of id msg-div (name's your choice) and by default set its display to none

<script> 
    $(document).ready(function() { 
        $('#myform').ajaxForm(function() { 
           $('#msg-div').css('display','block')
           $('#msg-div').html('success message here')
        }); 
    }); 
</script> 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to display success message only after sending the mail to recipient using Jquery Ajax

Replacing HTML form with success message after submit, form sends mail using separate php file

Submit form without page refresh using Jquery not working

How to submit a form request using ajax without page refresh and return a message in laravel?

display two id# in same success message after form submit

JavaScript success message after form submit/page re-load

Refresh page after submit form

Reload a page after successfully submit a form using ajax

How Show Success Message After form submit in wordpress?

How to submit a form on page load without using jquery in AngularJS?

show success message after form submit

How can i display form success message on same { div } without refreshing the page?

Display message after php form submit INSIDE same page

Submit form using enter without triggering page refresh

React: How to refresh the list on form submit without refreshing the page?

How to submit contact form 7 without page refresh in wordpress?

How to get the success message in the same page after submitting the form?

How to refresh/revisit the page after clicking submit on a form?

Submit ajax form without page refresh php

Stop page refresh after form submit

CodeIgniter refresh page after form submit

How to send error/success message through ajax without click submit button in form (if there isn't form) laravel?

How to show success message below html form after form submit which is being handled by different php file

Submit form without refresh Jquery issue

Submit html form without refresh or jquery

How to add success notification after form submit

How to call component, after submit form success?

How to display a bootstrap toast message after a form submit?

Javascript / Jquery Submit Form without ID or Class, after page load