How to get customer details and order in mail using javascript and php?

Viewed 177

This side sumit and my question is how to received customer order details in my email id when customer fill the checkout page and click on order now button using JavaScript and PHP i add my cart code below please check it i am new in developing please help.

"How to get customer details and order in mail using javascript and php?"

thanks in advance.

This is how my cart look

enter image description here

     <section id="" class="container-fluid">
         <article id="" class="row">
              <div id="mask"></div>
                 <div class="modal fade" id="cart" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
               <div class="modal-dialog modal-lg" role="document">
                 <div class="modal-content">
                   <div class="modal-header">
                     <h5 class="modal-title" id="exampleModalLabel">Cart</h5>
                   </div>
                        <form name="contactform" method="post" action="payscript.php">    
     <div class="modal-body">

     <div class="container">
       <div class="row">
        <div class="col-md-6 order-md-4 mb-6">

 <table id="cartents" class="show-cart table">

     </table>
    <div>Total price: <span class="total-cart" id="cartContent"></span></div>
<br>
    <div class="modal-footer">
     
        <button type="button" class="btn btn-primary">Order now</button>


    </div>
</div>

        <div class="col-md-6 order-md-1">
          <h4 class="mb-3">Billing address</h4>
          <form class = "needs-validation" novalidate  method="post" action="payscript.php">
            
             <div class="mb-3">
              <label for="fullname">Full name</label>
              <div class="input-group">

                <input type="text" class="form-control" id="phonenumber" placeholder="Enter your full name" required>
                <div class="invalid-feedback" style="width: 100%;">
                  Your full name is required.
                </div>
              </div>
            </div>
        
            

            <div class="mb-3">
              <label for="username">Phone no.</label>
              <div class="input-group">

                <input type="text" class="form-control" id="phonenumber" placeholder="Enter your phone no." required>
                <div class="invalid-feedback" style="width: 100%;">
                  Your Phone no. is required.
                </div>
              </div>
            </div>

            <div class="mb-3">
              <label for="email">Email</label>
              <input type="email" class="form-control" id="email" placeholder="Enter your email">
              <div class="invalid-feedback">
                Please enter a valid email address for shipping updates.
              </div>
            </div>

            <div class="mb-3">
              <label for="address">Address</label>
              <input type="text" class="form-control" id="address" placeholder="Enter your address" required>
              <div class="invalid-feedback">
                Please enter your shipping address.
              </div>
            </div>

  
  </div>
 </div>
</form> 
                  
         </article>
     </section>
1 Answers

The form

You have a form that is being used in order to submit some data. Inside your form you have some input tags. Presumably you intend to submit the values of your inputs. In order to do so, edit your input tags and add a name attribute, like

<input type="text" class="form-control" id="fullname" name="fullname" placeholder="Enter your full name" required>

Receiving the values

You need to have a PHP code corresponding to the path that is being requested when the form is being submitted. In this case that would be payscript.php. Since you have method="post", in payscript.php you can refer to the received parameters via $_POST, like $_POST["fullname"].

The template

You will need to build a template. One way to do it is to generate via PHP a text, like

$message = "Hello {$_POST["fullname"]}";

Sending the email

For this purpose you can use the mail function, like:

mail(
    "foo@bar.lorem", //To
    "Hello", //Subject,
    $message
);

Email support

In order to be able to support email sending, you will need to prepare your server to do so. Read more here: https://www.tutorialspoint.com/php/php_sending_emails.htm

Related