<?php
require("sendgrid-php/sendgrid-php.php");
include("use.php");
include ('setpdo.php');
 

$passkey = $_GET['passkey'];
$email = $_GET['email'];
 
 $sql1 = "UPDATE usertriggeriot SET com_code='N' WHERE com_code= :passkey";
 $stmt = $pdo->prepare($sql1);
 $stmt->bindParam(':passkey', $passkey, PDO::PARAM_STR);
 $stmt->execute();
 
 if ($stmt->rowCount()){

//send email notification 


$message = "
<html>
<head>
<title>CUENTA ACTIVA</title>
</head>
<body>
<p>Usuario: $email</p>
<p>activado</p>
<table>
<tr>
<th>--</th>
<th>--</th>
</tr>
<tr>
<td></td>
<td>- - - - - - - - - -</td>
</tr>
</table>
<p>Saludos!<br>
productocruz.cl</p>
</body>
</html>
";    

       
$from = new SendGrid\Email('IOT', "noreply@happygo.cl");
$subject = "Confirmacion Cuenta";
$to = new SendGrid\Email(null, $email);
$content = new SendGrid\Content("text/html", $message);
$mail = new SendGrid\Mail($from, $subject, $to, $content);

//$apiKey = getenv($key);
$apiKey = $key;
$sg = new \SendGrid($apiKey);

$response = $sg->client->mail()->send()->post($mail);
/*
echo $response->statusCode();
echo $response->headers();
echo $response->body();
*/

 
   
   if($response->statusCode()==202){
   
    //  print "enviado";
      $msg = 'CUENTA ESTA ACTIVA, REVISA BANDEJA DE CORREO' ;
$msgJson = json_encode($msg);
echo $msgJson ;
      $pdo = null;
      exit;
     
    
   
   }else{
     
   // print ("noenviado"); 
    $msg = 'noenviado' ;
$msgJson = json_encode($msg);
echo $msgJson ;
    $pdo = null;
    exit;

   } 
   
     
     
 //end sending email...   	
 
 
 
 }else{
  echo "Error";
 $pdo = null;
 exit;
 }
 
 
 /*start mysqli
 
 $passkey = $_GET['passkey'];
 $sql = "UPDATE user SET com_code='N' WHERE com_code='$passkey'";
 $result = mysqli_query($mysqlicon,$sql) or die(mysqli_error());
 if(mysqli_affected_rows($mysqlicon) > 0)
 {
  echo '<div>Tu cuenta esta activa...</div>';
}
 else
 {
  echo "Error";
 }
 
 end mysqli */
?>