88 lines
2.2 KiB
PHP
88 lines
2.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
/**
|
|
* Description of sns
|
|
*
|
|
* @author corradomulas
|
|
*/
|
|
require_once "Mail.php";
|
|
require 'aws/aws-autoloader.php';
|
|
|
|
use Aws\Sns\SnsClient;
|
|
use Aws\Exception\AwsException;
|
|
|
|
class snsrun {
|
|
//put your code here
|
|
public function sendEmail($to, $sub, $msg, $from)
|
|
{
|
|
// Pear Mail Library
|
|
$subject = 'Insert subject here'; // subject of mail
|
|
|
|
$headers = array(
|
|
'From' => $from,
|
|
'To' => $to,
|
|
'Subject' => $sub,
|
|
'Reply-To' => $from,
|
|
'X-Mailer' => "CM TLC",
|
|
);
|
|
|
|
$smtp = Mail::factory('smtp', array(
|
|
'host' => 'ssl://smtphost',
|
|
'port' => '465',
|
|
'auth' => true,
|
|
'username' => '', //your gmail account
|
|
'password' => '' // your password
|
|
));
|
|
|
|
// Send the mail
|
|
$mail = $smtp->send($to, $headers, $msg);
|
|
|
|
//check mail sent or not
|
|
if (PEAR::isError($mail)) {
|
|
return 0;
|
|
} else {
|
|
return 1;
|
|
}
|
|
}
|
|
public function sendSMS($num, $msg)
|
|
{
|
|
// Hard-coded credentials
|
|
$SnSclient = new SnsClient([
|
|
'version' => 'latest',
|
|
'region' => 'eu-west-1',
|
|
'credentials' => [
|
|
'key' => '',
|
|
'secret' => '',
|
|
],
|
|
]);
|
|
|
|
//$topic = 'arn:aws:sns:us-east-1:111122223333:MyTopic';
|
|
try {
|
|
$result = $SnSclient->publish([
|
|
"MessageAttributes" => [
|
|
'AWS.SNS.SMS.SenderID' => [
|
|
'DataType' => 'String',
|
|
'StringValue' => 'RUNIdP'
|
|
],
|
|
'AWS.SNS.SMS.SMSType' => [
|
|
'DataType' => 'String',
|
|
'StringValue' => 'Transactional'
|
|
]
|
|
],
|
|
'Message' => $msg,
|
|
'PhoneNumber' => $num,
|
|
]);
|
|
var_dump($result);
|
|
} catch (AwsException $e) {
|
|
// output error message if fails
|
|
error_log($e->getMessage());
|
|
}
|
|
}
|
|
}
|