ReusableForms v2.0 beta

PHP email form with file attachment support

A PHP Email form with file attachment
A form that can accept a file attachment has many uses. Some examples include allowing users to submit resumes on a job site, allowing customers to submit support requests with screenshots or logs, or allowing users to submit recipes on a food site. PHP is a popular scripting language that is often used for form submission processing. PHP is easy to learn and use, and it can be used to process form data quickly and easily. Moreover PHP is supported by default on most shared hosting services. However, configuring a PHP script to process form submission requires some programming expertise.

Code


        <h1>Contact Us</h1>
<form id="myform" name="myform" method="post">
    <div class="mb-5">
        <label for="email_addr">Email address</label>
        <input type="email" class="form-control" id="email_addr" name="email" placeholder="name@example.com">
    </div>
    <div class="mb-5">
        <label for="name_input">Name</label>
        <input type="name" class="form-control" id="name_input" name="name" placeholder="Name">
    </div>
    <div class="mb-5">
        <label for="message">Message</label>
        <textarea class="form-control" id="message" name="message" rows="3"></textarea>
    </div>
    <div class="mb-5">
        <label for="file_upload">Upload File</label>
        <input type="file" class="form-control-file" id="file_upload">
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
</form>
      

How to Use

Simply copy the code to your web page HTML.

Back-end processing and record keeping

You may want to get email notifications when a form is submitted. Moreover, you may want to store the form submission records, search the records later. All these requires a back-end processor. Here is how to add a backend to your form:

Using Ratufa backend

  • Go to ratufa.io
  • Press the "Connect your form" button
  • Code to connect your form is displayed. Copy the code to the bottom of the HTML code above
  • Test your form. Ratufa will display the submissions - to the right side
  • Copy the combined code to your web page
Ratufa will store your form submissions and you can configure to send email notifications. You can search and download the records whenever required.

Self-hosted PHP backend

Use this method only if you are familiar with server settings and customizing PHP code. Simfatic\FormHandler is a generic Form handling script that can do most of the form processing tasks out of the box.
  • git clone the project to your local folder
  • Run composer update
  • The examples folder in the repository contains some sample form handler scripts. Customize the handler.php script to your needs.
  • For example, add your email addresses, update SMTP settings.
  • handler.js contains sample Javascript to handle the form submission. customize handler.js to point to the correct URL
  • Upload the updated formHandler to your website(you have to upload the whole folder)
  • Copy the HTML form code to your web page. add the handler.js file in your HTML code
  • Test your form!