Home Blog Page 7

Get Domain Name from URL in PHP

0
fetch domain name from url

Welcome back to shortlearner.com, in our previous post we learn how to send an attachment with the help of PHP and MySQL. today in this post we learn how to Get Domain Name from URL in PHP.

fetch domain name from url

so Recently I am working on one of my clients project and i need to fetch the domain name from the URL. This is a very small task but it is very useful stuff to learn.

Also Read
How to Install PHP on CentOS.
How to integrate Razorpay Payment Gateway using PHP.

PHP Login Script With Remember me.
Unable to create a directory a wordpress error
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

In this short article, We will write simple and easy code to get the domain name from URL by using some predefined PHP function.

First we need to parse URL using parse_url(). so we can get the array from parse URL and now we can fetch the specific host from the array using $parse[‘host’].

so in the below example we will find the domain name from a predefined URL which are in our $url variable. so copy the below code and run it on your server so you will found the domain name from a long URL.

<?php
$url = "https://shortlearner.com";
$parse = parse_url($url);
$host = $parse['host'];
$host = str_ireplace('www.', '', $host);
echo $host;
?>

Razorpay Payment Gateway Integration using PHP

0
Razorpay payment gateway in php

Welcome back to shortlearner.com, in this post we will see how to implement Razorpay payment gateway with the help of PHP and CURL.

Razorpay is very popular payment gateway which provides all the clean, fast, secure payments services with hassle free integration.

Razorpay payment gateway in php

It allows online business to accept and process payments ,payments modes like including major Credit Cards, Debit Cards, Net-banking, Wallets & UPI. With the easiest integration, completely online onboarding, feature filled checkout and best in class performance, quickly go live with Razorpay and experience the future of payments.


Also Read :
Get Domain name from URL
How to Send Attachment on mail using PHP.
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

so readers please just follow the below steps for implementing payment gateway in very easy way.

Create Account and Integrate Payment Gateway

  • At first Create Account.
  • After successful sign up and generate Key ID and Secret Key
Razorpay Payment Gateway Integration using PHP

Razorpay Payment Gateway features:

  • Accept All the payment methods like debit card, credit card, netbanking,UPI and wallets.
  • Razorpay payment gateway is very safe and secure
  • Easy to integration
  • Payment gateway kit available on multiple programming language
  • UPI and Multi Bank EMI options

Before starts to implement the Razorpay Payment Gateway Integration using PHP with cURL, look files structure, we are splits the process in several parts so it will be easy to understand the overall developing process.
Step1: Create a file constants.php and define Key ID and Secret Key

<?php 
define('RAZOR_KEY_ID', 'rzp_test_XXXXXXXXXXXXXXXX');
define('RAZOR_KEY_SECRET', 'XXXXXXXXXXXX');
?>	

Note:please guys never share your secret key to anyone.

Step 2: Create another php file named index.php

in the below index.php code , we are declaring amount , currency , success URL and failure URL into some hidden input tags. so it will automatic redirect to success or failure page according to there response status.

<?php 
require_once "constants.php";
include('templates/header.php');
?>
<form name="razorpay_frm_payment" class="razorpay-frm-payment" id="razorpay-frm-payment" method="post">
<input type="hidden" name="merchant_order_id" id="merchant_order_id" value="12345"> 
<input type="hidden" name="language" value="EN"> 
<input type="hidden" name="currency" id="currency" value="INR"> 
<input type="hidden" name="surl" id="surl" value="http://localhost/razorpay-payment-gateway-integration-using-php/success.php"> 
<input type="hidden" name="furl" id="furl" value="http://localhost/razorpay-payment-gateway-integration-using-php/failed.php"> 
<section class="showcase">
  <div class="container">
    <div class="pb-2 mt-4 mb-2 border-bottom">
      <h2>Razorpay Payment Gateway Integration using PHP with cURL</h2>
    </div>
    <div class="row align-items-center">
       <div class="form-group col-md-6">
        <label for="inputEmail4">Amount</label>
        <input type="text" class="form-control" id="amount" name="amount" placeholder="amount" value="5.00" readonly="readonly">
      </div>
      <div class="form-group col-md-6">
        <label for="inputEmail4">Full Name</label>
        <input type="text" name="billing_name" class="form-control" id="billing-name"  Placeholder="Name" required> 
      </div>
  </div>
    <div class="row align-items-center">
       <div class="form-group col-md-6">
        <label for="inputEmail4">Email</label>
        <input type="email" name="billing_email"class="form-control" id="billing-email" Placeholder="Email" required>
      </div>
      <div class="form-group col-md-6">
        <label for="inputEmail4">Phone</label>
        <input type="text" name="billing_phone" class="form-control" id="billing-phone" Placeholder="Phone" required>
      </div>
  </div>
    <div class="row align-items-center">  
      <div class="form-group col-md-6">
        <label for="inputEmail4">Address</label>
         <input type="text" name="billing_address" class="form-control" Placeholder="Address">
      </div>
       <div class="form-group col-md-6">
        <label for="inputEmail4">Country</label>
        <input type="text" name="billing_country" class="form-control" Placeholder="Country">
      </div>
    </div>

    <div class="row align-items-center">  
      <div class="form-group col-md-6">
        <label for="inputEmail4">State</label>
         <input type="text" name="billing_state" class="form-control" Placeholder="State"> 
      </div>
       <div class="form-group col-md-6">
        <label for="inputEmail4">Zipcode</label>
        <input type="text" name="billing_zip" class="form-control" Placeholder="Zipcode">
      </div>
    </div>

    <div class="row">
      <div class="col">
        <button type="button" class="btn btn-success mt-4 float-right" id="razor-pay-now"><i class="fa fa-credit-card" aria-hidden="true"></i> Pay</button>
      </div>
    </div>
</div>
</section>
</form>
<?php include('templates/footer.php');?>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script type="text/javascript">
  jQuery(document).on('click', '#razor-pay-now', function (e) {
    var total = (jQuery('form#razorpay-frm-payment').find('input#amount').val() * 100);
    var merchant_order_id = jQuery('form#razorpay-frm-payment').find('input#merchant_order_id').val();
    var merchant_surl_id = jQuery('form#razorpay-frm-payment').find('input#surl').val();
    var merchant_furl_id = jQuery('form#razorpay-frm-payment').find('input#furl').val();
    var card_holder_name_id = jQuery('form#razorpay-frm-payment').find('input#billing-name').val();
    var merchant_total = total;
    var merchant_amount = jQuery('form#razorpay-frm-payment').find('input#amount').val();
    var currency_code_id = jQuery('form#razorpay-frm-payment').find('input#currency').val();
    var key_id = "<?php echo RAZOR_KEY_ID; ?>";
    var store_name = 'shortlearner';
    var store_description = 'Payment';
    var store_logo = 'image/logo.png';
    var email = jQuery('form#razorpay-frm-payment').find('input#billing-email').val();
    var phone = jQuery('form#razorpay-frm-payment').find('input#billing-phone').val();
    
    jQuery('.text-danger').remove();

    if(card_holder_name_id=="") {
      jQuery('input#billing-name').after('<small class="text-danger">Please enter full mame.</small>');
      return false;
    }
    if(email=="") {
      jQuery('input#billing-email').after('<small class="text-danger">Please enter valid email.</small>');
      return false;
    }
    if(phone=="") {
      jQuery('input#billing-phone').after('<small class="text-danger">Please enter valid phone.</small>');
      return false;
    }
    
    var razorpay_options = {
        key: key_id,
        amount: merchant_total,
        name: store_name,
        description: store_description,
        image: store_logo,
        netbanking: true,
        currency: currency_code_id,
        prefill: {
            name: card_holder_name_id,
            email: email,
            contact: phone
        },
        notes: {
            soolegal_order_id: merchant_order_id,
        },
        handler: function (transaction) {
            jQuery.ajax({
                url:'callback.php',
                type: 'post',
                data: {razorpay_payment_id: transaction.razorpay_payment_id, merchant_order_id: merchant_order_id, merchant_surl_id: merchant_surl_id, merchant_furl_id: merchant_furl_id, card_holder_name_id: card_holder_name_id, merchant_total: merchant_total, merchant_amount: merchant_amount, currency_code_id: currency_code_id}, 
                dataType: 'json',
                success: function (res) {
                    if(res.msg){
                        alert(res.msg);
                        return false;
                    } 
                    window.location = res.redirectURL;
                }
            });
        },
        "modal": {
            "ondismiss": function () {
                // code here
            }
        }
    };
    // obj        
    var objrzpv1 = new Razorpay(razorpay_options);
    objrzpv1.open();
        e.preventDefault();
            
});
</script>

Step 3: Create a file named callback.php
The file handles the payment process.

<?php
require_once "constants.php";
// initialized cURL Request
function get_curl_handle($payment_id, $data) {
    $url = 'https://api.razorpay.com/v1/payments/' . $payment_id . '/capture';
    $key_id = RAZOR_KEY_ID;
    $key_secret = RAZOR_KEY_SECRET;
    $params = http_build_query($data);
    //cURL Request
    $ch = curl_init();
    //set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERPWD, $key_id . ':' . $key_secret);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    return $ch;
}
if (!empty($_POST['razorpay_payment_id']) && !empty($_POST['merchant_order_id'])) {
$json = array();
$razorpay_payment_id = $_POST['razorpay_payment_id'];
$merchant_order_id = $_POST['merchant_order_id'];
$currency_code = $_POST['currency_code_id'];
// store temprary data
$dataFlesh = array(
    'card_holder_name' => $_POST['card_holder_name_id'],
    'merchant_amount' => $_POST['merchant_amount'],
    'merchant_total' => $_POST['merchant_total'],
    'surl' => $_POST['merchant_surl_id'],
    'furl' => $_POST['merchant_furl_id'],
    'currency_code' => $currency_code,
    'order_id' => $_POST['merchant_order_id'],
    'razorpay_payment_id' => $_POST['razorpay_payment_id'],
);

$paymentInfo = $dataFlesh;
$order_info = array('order_status_id' => $_POST['merchant_order_id']);
$amount = $_POST['merchant_total'];
$currency_code = $_POST['currency_code_id'];
// bind amount and currecy code
$data = array(
    'amount' => $amount,
    'currency' => $currency_code,
);
$success = false;
$error = '';
try {
    $ch = get_curl_handle($razorpay_payment_id, $data);
    //execute post
    $result = curl_exec($ch);
    $data = json_decode($result);
   
    $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    if ($result === false) {
        $success = false;
        $error = 'Curl error: ' . curl_error($ch);
    } else {
        $response_array = json_decode($result, true);
        //Check success response
        if ($http_status === 200 and isset($response_array['error']) === false) {
            $success = true;
        } else {
            $success = false;
            if (!empty($response_array['error']['code'])) {
                $error = $response_array['error']['code'] . ':' . $response_array['error']['description'];
            } else {
                $error = 'Invalid Response <br/>' . $result;
            }
        }
    }
    //close connection
    curl_close($ch);
} catch (Exception $e) {
    $success = false;
    $error = 'Request to Razorpay Failed';
}
if ($success === true) {
    if (!$order_info['order_status_id']) {
        $json['redirectURL'] = $_POST['merchant_surl_id'];
    } else {
        $json['redirectURL'] = $_POST['merchant_surl_id'];
    }
} else {
    $json['redirectURL'] = $_POST['merchant_furl_id'];
}
$json['msg'] = '';
} else {
$json['msg'] = 'An error occured. Contact site administrator, please!';
}
header('Content-Type: application/json');
echo json_encode($json);
?>

Step 4: Put the below script code in index.php file
We will use the chekout.js of Razorpay payment gateway for deduction of payment.

<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script type="text/javascript">
  jQuery(document).on('click', '#razor-pay-now', function (e) {
    var total = (jQuery('form#razorpay-frm-payment').find('input#amount').val() * 100);
    var merchant_order_id = jQuery('form#razorpay-frm-payment').find('input#merchant_order_id').val();
    var merchant_surl_id = jQuery('form#razorpay-frm-payment').find('input#surl').val();
    var merchant_furl_id = jQuery('form#razorpay-frm-payment').find('input#furl').val();
    var card_holder_name_id = jQuery('form#razorpay-frm-payment').find('input#billing-name').val();
    var merchant_total = total;
    var merchant_amount = jQuery('form#razorpay-frm-payment').find('input#amount').val();
    var currency_code_id = jQuery('form#razorpay-frm-payment').find('input#currency').val();
    var key_id = "<?php echo RAZOR_KEY_ID; ?>";
    var store_name = 'shortlearner';
    var store_description = 'Payment';
    var store_logo = 'img/logo.png';
    var email = jQuery('form#razorpay-frm-payment').find('input#billing-email').val();
    var phone = jQuery('form#razorpay-frm-payment').find('input#billing-phone').val();
    
    jQuery('.text-danger').remove();

    if(card_holder_name_id=="") {
      jQuery('input#billing-name').after('<small class="text-danger">Please enter full mame.</small>');
      return false;
    }
    if(email=="") {
      jQuery('input#billing-email').after('<small class="text-danger">Please enter valid email.</small>');
      return false;
    }
    if(phone=="") {
      jQuery('input#billing-phone').after('<small class="text-danger">Please enter valid phone.</small>');
      return false;
    }
    
    var razorpay_options = {
        key: key_id,
        amount: merchant_total,
        name: store_name,
        description: store_description,
        image: store_logo,
        netbanking: true,
        currency: currency_code_id,
        prefill: {
            name: card_holder_name_id,
            email: email,
            contact: phone
        },
        notes: {
            soolegal_order_id: merchant_order_id,
        },
        handler: function (transaction) {
            jQuery.ajax({
                url:'callback.php',
                type: 'post',
                data: {razorpay_payment_id: transaction.razorpay_payment_id, merchant_order_id: merchant_order_id, merchant_surl_id: merchant_surl_id, merchant_furl_id: merchant_furl_id, card_holder_name_id: card_holder_name_id, merchant_total: merchant_total, merchant_amount: merchant_amount, currency_code_id: currency_code_id}, 
                dataType: 'json',
                success: function (res) {
                    if(res.msg){
                        alert(res.msg);
                        return false;
                    } 
                    window.location = res.redirectURL;
                }
            });
        },
        "modal": {
            "ondismiss": function () {
                // code here
            }
        }
    };
    // obj        
    var objrzpv1 = new Razorpay(razorpay_options);
    objrzpv1.open();
        e.preventDefault();
            
});
</script> 

Step 5: now in the second last step we are creating a success.php file
so if transaction status is success than success.php page will show the message of transaction success.

<?php include('templates/header.php'); ?>
<section class="showcase">
   <div class="container">
    <div class="text-center">
      <h1 class="display-3">Thank You!</h1>
      <p class="lead">Your payment has been received successfully.</p>
      <hr>
      <p>
        Having trouble? <a href="mailto:info@shortlearner.com">Contact us</a>
      </p>
      <p class="lead">
        <a class="btn btn-primary btn-sm" href="#" role="button">Continue to homepage</a>
      </p>
    </div>
    </div>
</section>
<br><br><br><br><br><br>
<?php include('templates/footer.php');?>

Step 6: Create a file named failed.php

<?php include('templates/header.php');?>
<section class="showcase">
   <div class="container">
    <div class="text-center">
      <h1 class="display-3">Thank You!</h1>
      <p class="lead text-danger">Your transaction has been declined.</p>
      <hr>
      <p>
        Having trouble? <a href="mailto:info@shortlearner.com">Contact us</a>
      </p>
      <p class="lead">
        <a class="btn btn-primary btn-sm" href="#" role="button">Continue to homepage</a>
      </p>
    </div>
    </div>
</section>
<br><br><br><br><br><br>
<?php include('templates/footer.php');?>

Create header.php and footer.php section of the web page.

<!DOCTYPE html>
<html lang="en">
<head>
  <link rel="canonical" href="https://shortlearner.com/" />
  <meta name="author" content="shortlearner">  
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon" href="image/logo.png" sizes="32x32" />
  <link rel="icon" href="image/logo.png" sizes="192x192" />
  <link rel="apple-touch-icon-precomposed" href="image/logo.png" />
  <meta name="msapplication-TileImage" content="image/logo.png" />
  <title>Razorpay Payment Gateway Integration using PHP with cURL | shortlearner</title>
  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" />
  <!-- Custom fonts for this template -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.2/css/all.min.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/simple-line-icons/2.4.1/css/simple-line-icons.css" />
  <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
  <!-- Custom styles for this template -->
  <link href="css/style.css" rel="stylesheet"> 
</head>
<body>
  <!-- Navigation -->
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top header-bg-dark" style="background: ##FFFFFF!;">
  <div class="container">
    <a class="navbar-brand font-weight-bold" href="https://shortlearner.com"><h1>shortlearner</h1></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav ml-auto">
        <li class="nav-item active">
          <a class="nav-link" href="https://shortlearner.com/">Home
                <span class="sr-only">(current)</span>
              </a>
        </li>
       
      </ul>
    </div>
  </div>
</nav>

footer.php

<!-- Footer -->
  <footer class="footer bg-light footer-bg-dark">
    <div class="container">
      <div class="row">
        <div class="col-lg-6 h-100 text-center text-lg-left my-auto">
          <ul class="list-inline mb-2">
            <li class="list-inline-item">
              <a href="#">About</a>
            </li>
            <li class="list-inline-item">⋅</li>
            <li class="list-inline-item">
              <a href="#">Contact</a>
            </li>
            <li class="list-inline-item">⋅</li>
            <li class="list-inline-item">
              <a href="#">Terms of Use</a>
            </li>
            <li class="list-inline-item">⋅</li>
            <li class="list-inline-item">
              <a href="#">Privacy Policy</a>
            </li>
          </ul>
          <p class="small mb-4 mb-lg-0" style="color: #E6ECF0;">Copyright ©  2017 - <?php print date('Y', time());?> <a style="color: #E6ECF0;" href="https://Shortlearner.com/">Shortlearner.com</a> All rights reserved.</p>
        </div>
        <div class="col-lg-6 h-100 text-center text-lg-right my-auto">
          <ul class="list-inline mb-0">
            <li class="list-inline-item mr-3">
              <a href="#">
                <i class="fab fa-facebook fa-2x fa-fw"></i>
              </a>
            </li>
            <li class="list-inline-item mr-3">
              <a href="#">
                <i class="fab fa-twitter-square fa-2x fa-fw"></i>
              </a>
            </li>
            <li class="list-inline-item">
              <a href="#">
                <i class="fab fa-instagram fa-2x fa-fw"></i>
              </a>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </footer>
  <!-- Bootstrap core JavaScript -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>

</body>
</html>

Copy Text From One Field To Another using JavaScript

0
Copy Text From One Field To Another using JavaScript

Welcome back to shortlearner.com, in our previous post we learn how to read and display a txt file with the help of JavaScript.
today in this post we will see how to Copy Text From One Field To Another using JavaScript.

Copy Text From One Field To Another using  JavaScript

Also Read :
Get Domain name from URL
How to Send Attachment on mail using PHP.
PHP Login Script With Remember me.
Unable to create a directory a wordpress error
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

so most of the time we need to Copy Text From One Field To Another using Check Box with JavaScript.

for example if we are creating an e-commerce platform and we want to make it user friendly.

so we are creating a check box which will hep user to copy all the fields of billing address to shipping address.

in the below example there are two buyers , buyer 1 and buyer 2.
we take name, email and contact number information from buyer 1 and put it into buyer 2 by clicking on the checkbox

<html lang="en">
<head>
  <title>Shortlearner</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 
</head>
<body>
<div class="container">
 <form>
   <div>
    <h1 style="color:green">Shortlearner</h1> 
	<h3>Copy Text From One Field To Another using CheckBox with JavaScript </h3>
<hr/>	  
  </div>
 <div class="row">
              <div class="col-sm-12">
              <div class="form-group">
               <label>BUYER: </label>
	    </div>
            </div>
            
           
            </div>
	    <div class="row">
         <div class="col-sm-3">
            <div class="form-group">
               <label>Buyer Name: </label>
                <input type="text" class="form-control" id="usercity"  name="b_name" placeholder="Enter Name" required>
              </div>
            </div>
	    <div class="col-sm-3">
              <div class="form-group">
               <label>Contact Person: </label>
                <input type="text" class="form-control" id="userstate"  name="b_contact_person" placeholder="Enter Person Name" required>
              </div>
            </div>
            <div class="col-sm-3">
              <div class="form-group">
               <label>Phone No: </label>
                <input type="text" class="form-control" id="usercity"  name="b_phone" placeholder="Enter Phone No." required>
              </div>
            </div>
            <div class="col-sm-3">
              <div class="form-group">
               <label>Email: </label>
                <input type="text" class="form-control" id="userstate"  name="b_email" placeholder="Enter Email" required>
              </div>
            </div>
            </div>
	      <div class="row">
	      <div class="col-sm-12">
              <div class="form-group">
			  <input type="checkbox"  name="billingtoo" onclick="FillBilling(this.form)">
               <label style="color:blue;">Check this box if Billing Address and Shipping Address are the same.</label>
              </div>
            </div>
			<hr>
			  <div class="row">
              <div class="col-sm-12">
              <div class="form-group">
               <label>BUYER 2: </label>
               <label> </label>
			</div>
            </div>
           
            <!-- /.col -->
           
			
            </div>
			<div class="row">
         <div class="col-sm-3">
            <div class="form-group">
               <label>Name: </label>
                <input type="text" class="form-control" id="usercity"  name="c_name" placeholder="Enter Name" required>
              </div>
            </div>
			 <div class="col-sm-3">
              <div class="form-group">
               <label>Contact Person: </label>
                <input type="text" class="form-control" id="userstate"  name="c_contact_person" placeholder="Enter Person Name" required>
              </div>
            </div>
            <div class="col-sm-3">
              <div class="form-group">
               <label>Phone No: </label>
                <input type="text" class="form-control" id="usercity"  name="c_phone" placeholder="Enter Phone No." required>
              </div>
            </div>
            <div class="col-sm-3">
              <div class="form-group">
               <label>Email: </label>
                <input type="text" class="form-control" id="userstate"  name="c_email" placeholder="Enter Email" required>
              </div>
            </div>
            </div>
 </form>
</div>
<script>
function FillBilling(f) {
  if(f.billingtoo.checked == true) {
    f.c_name.value=f.b_name.value ;
    
 f.c_contact_person.value  =  f.b_contact_person.value ;
    f.c_phone.value = f.b_phone.value ;
     f.c_email.value = f.b_email.value ;
  }
  else
    {
     f.c_name.value = "";
    
    f.c_contact_person.value = "";
    f.c_phone.value = "";
    f.c_email.value = "";
  }
}</script>
</body>
</html>

hope this post will help you.
keep coding, keep learning

Read and display the text file using javascript

0
Read and display the text file using javascript

Welcome back to shortlerner.com, in our previous post we was learn How to Send Attachment With Email with the help of PHP. today in this post we will see how to read and display a text file data into html text area tag with the help of JavaScript.

Read and display the text file using javascript

so here we are creating a file tag where user upload the text file and there is another html form element text area.

so whenever user upload the file we use some JavaScript functions which will read the file and display all the data of the file inside the text area.

Also Read :
PHP Login Script With Remember me.
Unable to create a directory a wordpress error
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

<input type="file" onchange="onFileSelected(event)">
<br>
<textarea id="result" rows="10" cols="50"></textarea>
<script type="text/javascript">
function onFileSelected(event) {
var selectedFile = event.target.files[0];
var reader = new FileReader();
var result = document.getElementById("result");
reader.onload = function(event) {
    result.innerHTML = event.target.result;
  };
reader.readAsText(selectedFile);
}
</script>

simply just copy the above code and put it on your root directory.
hope this post will helps you, if you still facing some bugs or error to than feel free to contact.

thanks for reading the post and please share this code with your developer buddy.

keep coding , keep learning

Send Attachment With Email using php

0
send email with attachment in php

Welcome back to shortlearner.com, in our previous post we learn how to add pagination using PHP and MySQL. so today in this post we will see how to Send Attachment With Email using php.

so first of all we should take an overview of our working scenario.
in the below code we are created a form with having email, subject,message and attachment fields.

once the form is submitted our script is check that the file’s format is valid or not.
if the file format is valid than the attachment is concatenate with our message field and with the help of MIME (Multipurpose Internet Mail Extensions) version and its content type and boundary.

we will send the attachment. once the mail is send successfully our script will display the success message and if the mail isn’t sent than it will display failure message as well.

send email with attachment in php

Also Read :
PHP Login Script With Remember me.
Unable to create a directory a wordpress error
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

<html>
    <body>
        <h2>Send Mail</h2>
        <form method="post" action="" enctype="multipart/form-data">
            <input type="text" name="email" placeholder="email"><br>
            <input type="text" name="sub" placeholder="Subject"><br>
            <textarea name="msg" placeholder="Write email message"></textarea><br>

            Attach file:<br>
            <input type="file" name="attach1"/><br><br>
            <input type="submit" value="Send Mail"/>
        </form>
    </body>
</html>
<?php
if (isset($_FILES) && (bool) $_FILES) {

    $allowedExtensions = array("pdf", "doc", "docx", "gif", "jpeg", "jpg", "png");

    $files = array();
    foreach ($_FILES as $name => $file) {
        $file_name = $file['name'];
        $temp_name = $file['tmp_name'];
        $file_type = $file['type'];
        $path_parts = pathinfo($file_name);
        $ext = $path_parts['extension'];
        if (!in_array($ext, $allowedExtensions)) {
            die("File $file_name has the extensions $ext which is not allowed");
        }
        array_push($files, $file);
    }

    // email fields: to, from, subject, and so on
    $to = $_POST['email'];
    $from = "admin@shortlearner.com";
    $subject = $_POST['sub'];
    $message = $_POST['msg'];
    $headers = "From: $from";

    // boundary 
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

    // headers -for attachment 
    $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";

    // multipart boundary 
    $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";
    $message .= "--{$mime_boundary}\n";

    // preparing attachments
    for ($x = 0; $x < count($files); $x++) {
        $file = fopen($files[$x]['tmp_name'], "rb");
        $data = fread($file, filesize($files[$x]['tmp_name']));
        fclose($file);
        $data = chunk_split(base64_encode($data));
        $name = $files[$x]['name'];
        $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" .
                "Content-Disposition: attachment;\n" . " filename=\"$name\"\n" .
                "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
        $message .= "--{$mime_boundary}\n";
    }
    // send

    $ok = mail($to, $subject, $message, $headers);
    if ($ok) {
        echo "<p>mail sent to $to!</p>";
    } else {
        echo "<p>mail could not be sent!</p>";
    }
}
?>

guys this code is not works on local server like xampp,wamp and appserv. so try it on live server.