lunes, 23 de marzo de 2020

PHP sendgrid API

 1007  echo "export SENDGRID_API_KEY='SG.8J2caHDtU'" > sendgrid.env


 1008  echo "sendgrid.env" >> .gitignore

 1009  source ./sendgrid.env

 1013  composer sendgrid/sendgrid

 1014  sudo curl -sS https://getcomposer.org/installer | php

 1015   mv composer.phar /usr/local/bin/composer

 1016  composer -V

 1023  composer require sendgrid/sendgrid
---------------------------------------------------------------------
PHP CODE

    <?php
require 'vendor/autoload.php'; // If you're using Composer (recommended)
// Comment out the above line if not using Composer
// require("<PATH TO>/sendgrid-php.php");
// If not using Composer, uncomment the above line and
// download sendgrid-php.zip from the latest release here,
// replacing <PATH TO> with the path to the sendgrid-php.php file,
// which is included in the download:
// https://github.com/sendgrid/sendgrid-php/releases

$email = new \SendGrid\Mail\Mail();
$email->setFrom("admin@asterisk-voip.com", "Ambiorix Rodriguez");
$email->setSubject("Sending with SendGrid is Fun");
$email->addTo("ambiorixg12@gmail.com", "Example User");
$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
$email->addContent(
    "text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
);
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
    $response = $sendgrid->send($email);
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $e) {
    echo 'Caught exception: '. $e->getMessage() ."\n";
}

?>

viernes, 6 de marzo de 2020

<?php
/* formats a 10 or 7 digit phone number (number only) by adding dashes at the appropriate locations */

function phoneFormat($number) {
if(ctype_digit($number) && strlen($number) == 10) {
  $number = substr($number, 0, 3) .'-'. substr($number, 3, 3) .'-'. substr($number, 6);
} else {
if(ctype_digit($number) && strlen($number) == 7) {
$number = substr($number, 0, 3) .'-'. substr($number, 3, 4);
}
}
return $number;
}

echo  phoneFormat(8297243489);

?>

829-724-3489