Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////////
- // html
- //////////////////////////////////////////////////
- <form role="form" enctype="multipart/form-data" id="formHook" class="form-inline mb-3">
- <div class="form-group mr-3">
- <label for="formHookName" class="sr-only">Имя</label>
- <input type="text" class="rounded-0 form-control" id="formHookName" placeholder="Имя">
- </div>
- <div class="form-group mr-3">
- <label for="formHookPhone" class="sr-only">Телефон</label>
- <input type="phone" class="rounded-0 form-control" id="formHookPhone" placeholder="Телефон">
- </div>
- <div class="form-group mr-3">
- <label for="formHookFile" class="sr-only">Фаил</label>
- <input type="file" class="rounded-0 form-control" id="formHookFile" placeholder="Документ">
- </div>
- <button type="submit" id="formHookSubmit" class="rounded-0 btn btn-primary ">Заказать</button>
- </form>
- //////////////////////////////////////////////////
- // js
- //////////////////////////////////////////////////
- $('#formHook').submit(function(event){
- // cancels the form submission
- event.preventDefault();
- submitHook();
- });
- function submitHook(){
- // Initiate Variables With Form Content
- var name = $('#formHookName').val();
- var phone = $('#formHookPhone').val();
- $.ajax({
- type: 'POST',
- url: '../media/php/mailHook.php',
- data:
- '&name=' + name +
- '&phone=' + phone,
- success : function(text){
- if (text == 'success'){
- successHook();
- }
- }
- });
- }
- function successHook(){
- $( '#formHookSubmit' ).text('Ждите звонка');
- $( '#formHookSubmit' ).prop( 'disabled', true );
- }
- //////////////////////////////////////////////////
- // PHP
- //////////////////////////////////////////////////
- <?php
- $name = $_POST["name"];
- $phone = $_POST["phone"];
- $EmailTo = "renat1771@gmail.com";
- $email = "noreply@yoursite.com";
- $Subject = "New Hook Received From site";
- $Headers = "Content-Type: text/html; charset=utf-8\r\n" . 'From: Site message <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email;
- // prepare email body text
- $Body .= "Name: ";
- $Body .= $name;
- $Body .= "<br/>";
- $Body .= "Phone: ";
- $Body .= $phone;
- $Body .= "<br/>";
- // send email
- $success = mail($EmailTo, $Subject, $Body, $Headers);
- // redirect to success page
- if ($success){
- echo "success";
- }else{
- echo "invalid";
- };
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement