Showing posts with label Api. Show all posts
Showing posts with label Api. Show all posts

Currency convertion using google api in php

We all are using google. Any thing we are finding in web we first trust on google and we believe that google output is ten times better than others. Whether we talk about searching, charting, Apis etc.
So here we are talking about api for currency conversion. There are lots of conversion apis you can find but there drawback is all they are paid and they have some limitation but when you are using google api its absolutely free without any limitation.

Now i am going to create a function "currencyExchange" to convert any amount.

//This Function Is Use To Get The Current Currency Exchange Rate.
function currencyExchange($from_currency, $to_currency='INR', $amount = 1) {
 $from_currency = urlencode($from_currency);
 $to_currency = urlencode($to_currency); 
 $url = "https://www.google.com/finance/converter?a=$amount&from=$from_currency&to=$to_currency";
 $getUrl = file_get_contents($url);
 $objUrl = explode("<span class=bld>",$getUrl);
 $objUrl = explode("</span>",$objUrl[1]);
 $result_currency = preg_replace("/[^0-9\.]/", null, $objUrl[0]);
 return $result_currency;
}


Method of calling function :  

Suppose you want to convert your 10 Rupee(INR) into USD. So below is the parameter you have to pass in "currencyExchange" function -

//change amount according to your needs
$amount =10;

//change From Currency according to your needs
$from_Curr = "INR";

//change To Currency according to your needs
$to_Curr = "USD";
$result_currency = currencyExchange($from_Curr, $to_Curr, $amount);

//Print outout
echo $result_currency;
If you like this post so please leave a comment.

Chears
Happy Coding :) 


Send mail using smtp in php

Some time when you need to send mail in bulk amount.Then normal mail() function is not working.Because they have a limit to send email every day. You have to use third party script to send email like Amazon etc .Today i am using sending mail using Amazon smtp api .Its a very easy to use in php.Before using this api you have to regirster on Amazon and have to be a username and password of amazon api .Then after download the smtp library PHPmailer from HERE .

After downloading above library and unzip the file there is two main file which we are using -

1-Send_Mail.php
2-index.php

------------------------------------------------------------------------------------------------
Code : Sample code of Send_Mail.php
------------------------------------------------------------------------------------------------
Note: In Send_Mail.php you have to set your own SMTP username and password before using this.

function Send_Mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "salman@futerox.co.in";
$mail = new PHPMailer();
$mail->IsSMTP(true); // SMTP
$mail->SMTPAuth   = true;  // SMTP authentication
$mail->Mailer = "smtp";
$mail->Host       = "tls://email-smtp.us-east.amazonaws.com"; // Amazon SES server, note "tls://" protocol
$mail->Port       = 2465;   // set the SMTP port according to your server which port is enable on your server
$mail->Username   = "AKIAIXMKUPFWCTV77NKQ"; // SMTP username change it with your username
$mail->Password   = "Ag5AzgnbrpK/361/+LF1Dq+iCeJEn3s8l3jWQR5zJNNL"; //SMTP password
$mail->SetFrom($from, 'amazon');
$mail->AddReplyTo($from,'amazon');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);

if(!$mail->Send())
return false;
else
return true;

}

------------------------------------------------------------------------------------------------
Code : Sample code of index.php
------------------------------------------------------------------------------------------------

//This is the main file from where we are using to test our smtp function.

require 'Send_Mail.php';
$to = "phpsolution@gmail.com";
$subject = "Test Mail Subject";
$body = "Hi<br/>Test Mail<br/>Amazon SES"; // HTML  tags
if(Send_Mail($to,$subject,$body)){
   
    echo "maill send successfully";
    }else{
        echo "some error occoured";
        }




If you like this post please don't forgot to notify me to post a comment .

Happy coding guys :)