Send Feedback Form Through Mail Using PHP

This tutorial help to create feedback from using bootstrap and send through email using php. We will use PHP mail functionality to send form content using email.I just want to send a user feedback form through email using PHP on-click of submit button.

Form content will go to the mentioned email id, you can configure target email id in config or into php script file.

You can also check other tutorial of php mail,

I will use following files for this Product Listing tutorial,

  1. index.php
    : This file containing the feedback form.
  2. email.php
    : This file will use to send feedback form to tagert email id.

How to send Feedback Form Through Email

We will create feedback from into index.php
file, You can use this tutorial for Quote Form and send to email id or as contact-us page that will send to email id through php email.

Step 1:We will create HTML form using Bootstrap.


How To Send Feedback Form Through PHP Email


Feedback Form


Step 2:We will create AJAX request that will send Form data to email.php

// this is the id of the form
$("#frm_feedback").submit(function(e) {
    var string_msg = '';
           type: "POST",
           url: "email.php",
           data: $("#frm_feedback").serializeArray(), // serializes the form's elements.
           success: function(data)
              var data  = jQuery.parseJSON(data);
              if(data.status) {
               //console.log(data); // show response from the php script.
              } else {
                string_msg = data.message.join('
');                 console.log(string_msg);                 $('.alert-danger').html(string_msg);               }            }          });       e.preventDefault(); // avoid to execute the actual submit of the form. });

I am using jQuery, so i ll use jQuery AJAX fucntionality to send data to server side.

Step 3:We will create send mail functionality into email.php
, need to add below code into email.php
. We will use php mail()
function to send mail.The mail()
function takes some parameters like, to_email
, subject
of email and body
of email.

 false, 'message' => array());
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
  if(!isset($email) || !preg_match($email_exp,$email)) {
    array_push($response['message'], 'The Email Address you entered does not appear to be valid');
  if(!isset($name) || empty($name)) {
    array_push($response['message'], 'The Name you entered does not appear to be valid.');
  if(!isset($mobile) || empty($mobile)) {
    array_push($response['message'], 'The Mobile  you entered does not appear to be valid.');
  if(!isset($comments) || empty($comments) || strlen($comments)  true, 'message' => 'Thank you for contacting us. We will be in touch with you very soon.');
 echo json_encode($response);

We are doing validation of input fields, if any input fields is empty then sent consolidated error message and displayed into feedback form, if everything perfect then we are sending success message to feedback form.We are using json_encode()
function to use to send data in json format.

责编内容来自:Php Flow (源链) | 更多关于

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Send Feedback Form Through Mail Using PHP

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录