How to Create a Dogecoin Price alert with PHP

 How to Create a Dogecoin Price alert with PHP by Doctordroid


Hi Guys it's Doctordroid , Knowing Dogecoin price when it's up or Down it's very important in the crypto world because it can help save a lot of money if you are investing or tading. So we gonna build a php script price alert that will alert us by mail(Gmail) every 30 minutes. 

Let's start , Firtst we gonna use a PHP mail sender library to send the data to the mail sever with is Gmail, Second we gonna get the Dogecoin price via bitpay API this website has dogecoin price updated . 

Let's build our script :

<?php

// Start the session

//session_start();


  header("Refresh: 1800"); //refresh the page every 30 minutes


// Import PHPMailer classes into the global namespace

// These must be at the top of your script, not inside a function

use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\Exception;


// Load Composer's autoloader

require 'vendor2/autoload.php';




// Get the dogecoin price via bitpay API website 


$url = "https://bitpay.com/api/rates";

$jason = json_decode(file_get_contents($url) );

$dollar = $DOGE = 0;


$dollar2 = $btc = 0;

 

foreach($jason as $obj){

if ($obj->code=='DOGE') $DOGE = $obj->rate;

if ($obj->code=='USD') $btc = $obj->rate;


$total= $btc / $DOGE;


$roundDollar = number_format((float)$total, 2, '.', '');


} // Dogecoin price via bitpay website api



// Instantiation and passing `true` enables exceptions

$mail = new PHPMailer(true);



// Commment isSMTP(); if you want to work online

try {

    //Server settings

    $mail->SMTPDebug = 2;                                       // Enable verbose debug output

   // $mail->isSMTP();                                            // Set mailer to use SMTP

    $mail->SMTPAuth=true;                                            // Set mailer to use SMTP

    $mail->Host       = 'smtp.gmail.com';  // Specify main and backup SMTP servers

    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication

    $mail->Username   = 'YourGmailAdress';                     // SMTP username   

    $mail->Password   = 'YourGmailPassword';                               // SMTP password

    $mail->SMTPSecure = 'ssl';                                  // Enable TLS encryption, `ssl` also accepted

    $mail->Port       = 465;                                    // TCP port to connect to


    //Recipients

    $mail->setFrom('YourgmailAccount', 'DOGE Price');

    $mail->addAddress('YourGmailAccount', 'DogecoinPrice');     // Add a recipient

    $mail->addAddress('YourGmailAccount','DogeCoinPrice');               // Name is optional

    $mail->addReplyTo('YourGmailAccount', 'Information');

   // $mail->addCC('cc@example.com');

   // $mail->addBCC('bcc@example.com');


    // Attachments

   // $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments

    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name


    // Content

    $mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = 'Price of DOGE' ;

   $mail->Body    = '<center> 1 DogeCoin = <font color="red"><b> <h1>'. $roundDollar .'</h1> </b></font> USD </center>';

    $mail->AltBody = 'Dogecoin Price';


    $mail->send();

   //echo '<html> <font color="red" > <center> <h1> Message has been sent  </h1> </center> </font> </html>';

  

} catch (Exception $e) {

   // echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";

}



?>

Commentaires

Posts les plus consultés de ce blog

Men kijan pou voye MINUT NATCOM-NATCOM pou ZANMIW an 3 etap

Comment partager des minutes sur natcom

Men kijan pou prete kob, minutes, lajan nan men NATCOM Ayiti