Send SMS using vTiger instance - php

<?php
include_once 'vtlib/Vtiger/Utils.php';
require_once('include/database/PearDatabase.php');
require_once 'config.inc.php';
require_once 'includes/Loader.php';
require_once 'modules/SMSNotifier/SMSNotifier.php';
vimport ('includes.runtime.EntryPoint');
$user = Users_Record_Model::getCurrentUserModel();
GLOBAL $adb;
$tonumbers = array('994255xxxx');
$message = "Test From Ramesh";
$provider = SMSNotifierManager::getActiveProviderInstance();
if( $provider ){
$provider->send($message, $tonumbers);
}
?>
Get provider instance using getActiveProviderInstance. and call send function from that instance.

Try this
<?php
include_once 'includes/main/WebUI.php';
require_once 'includes/Loader.php';
require_once 'modules/SMSNotifier/SMSNotifier.php';
$tonumbers = array('994255xxxx');
$message = "Test From Ramesh";
SMSNotifier::fireSendSMS($message, $tonumbers);

Related

class not found if included from extern

I have a this folder structure:
+ inc
++ functions.php
++ vendor
+ private
++ carddav
+++ check.php
my check.php looks like this and works:
<?php
require '../../inc/functions.php';
// CardDAV API
require '../../inc/vendor/autoload.php';
use MStilkerich\CardDavClient\{Account, AddressbookCollection, Config};
use Psr\Log\{AbstractLogger, NullLogger, LogLevel};
use Sabre\VObject\Component\VCard;
class StdoutLogger extends AbstractLogger {
public function log($level, $message, array $context = array()) {
if ($level !== LogLevel::DEBUG) {
$ctx = empty($context) ? "" : json_encode($context);
echo ">>> ".$message . $ctx . "<br />";
}
}
}
Config::init(new StdoutLogger());
$account = new Account(URL, USERNAME, PASSWORD);
$abook = new AddressbookCollection(URL, $account);
$vcard = new VCard();
?>
But now I would like to outsource this part into my functions.php:
functions.php
<?
// CardDAV API
require 'vendor/autoload.php';
use MStilkerich\CardDavClient\{Account, AddressbookCollection, Config};
use Psr\Log\{AbstractLogger, NullLogger, LogLevel};
use Sabre\VObject\Component\VCard;
class StdoutLogger extends AbstractLogger {
public function log($level, $message, array $context = array()) {
if ($level !== LogLevel::DEBUG) {
$ctx = empty($context) ? "" : json_encode($context);
echo ">>> ".$message . $ctx . "<br />";
}
}
}
Config::init(new StdoutLogger());
$account = new Account(URL, USERNAME, PASSWORD);
$abook = new AddressbookCollection(URL, $account);
?>
check.php
<?php
require '../../inc/functions.php';
$vcard = new VCard();
?>
But now I get this error when I open the check.php:
Fatal error: Uncaught Error: Class 'VCard' not found in check.php:26
Where is my mistake?
Tank you !
Imports using use statement work on a per file basis. I.e. classes need to be imported in the file where they're used. In your case remove Sabre\VObject\Component\VCard import from functions.php and move it to check.php where VCard class is actually used.

Put the data from firestore into next php file

I have several values in cloud firestore and want to access every variables. Hence I do my code like this
<?php
require __DIR__.'/vendor/autoload.php';
use Google\Cloud\Firestore\FirestoreClient;
$db = new FirestoreClient(
[
'projectId' => 'fakedata-aa798'
]
);
$collectionReference = $db->collection('Test3');
$docRef = $collectionReference->document('User1');
$snapshot = $docRef->snapshot();
$Name= $snapshot['Name'];
$Contact= $snapshot['Contact no:'];
$Email= $snapshot['Email'];
$Location= $snapshot['Location'];
$Locationstatus= $snapshot['Location status'];
$Condition= $snapshot['Condition'];
session_start();
$_SESSION['Name'] = $Name;
$_SESSION['Contact no:'] = $Contact;
$_SESSION['Email'] = $Email;
$_SESSION['Location'] = $Location;
$_SESSION['Location status'] = $Locationstatus;
$_SESSION['Condition'] = $Condition;
?>
Now I want to display the values in next PHP files and I use session_start but still can't get the values
pages2
<?php
session_start();
echo $_SESSION['Name'];
?>
Can someone help me?

PHP action inside PHP already running

Good Day
I am not sure if this is possible but any advice would be greatly be appreciated.
I have a code in PHP as below and would like to add additional PHP code Not sure how to explain it but maybe if I show code it would make some sence.
<?php
//Clickatell login
$user = "##";
$password = "##";
$api_id = "##";
$baseurl ="http://api.clickatell.com";
$text = urlencode("Recovery Assist Panic Activated (BETA TEST VERSION");
$to = "'0827910119'";
?>
The above is the current code I have with some additional extra's not required here. I want to add the following to this code as part of Sitelok page manager
<?php
//Clickatell login
$user = "##";
$password = "##";
$api_id = "##";
$baseurl ="http://api.clickatell.com";
$text = urlencode("Recovery Assist Panic Activated (BETA TEST VERSION");
<?php if (sl_ismemberof("RecAssist")){ ?>
$to = "'0827911119'";
<?php } ?>
<?php if (sl_ismemberof("Gold")){ ?>
$to = "'0827952558'";
<?php } ?>
?>
The "is a member of" is part of the sitelok code to exclude on HTML where a person does not have access to. I am not sure if I can run another inside the one running already. I know this can be done with IF and ELS most prob but the coding for the amount of groups will just be too much so hoped that somehow I can use the Sitelok section
Why not just use an if statement?
e.g.
<?php
//Clickatell login
$user = "##";
$password = "##";
$api_id = "##";
$baseurl = "http://api.clickatell.com";
$text = urlencode("Recovery Assist Panic Activated (BETA TEST VERSION");
if (sl_ismemberof("RecAssist")){
$to = "'0827911119'";
} elseif (sl_ismemberof("Gold")) {
$to = "'0827952558'";
}
?>
The best an most maintainable way to achieve this would be to define all of your groups or w/e in an associative array and loop through it because it will be the most maintainable.
<?php
//Clickatell login
$user = "##";
$password = "##";
$api_id = "##";
$baseurl = "http://api.clickatell.com";
$text = urlencode("Recovery Assist Panic Activated (BETA TEST VERSION");
$groups = array(
"RecAssist" => "0827911119",
"Gold" => "0827952558",
);
$to = "";
foreach($groups as $k=>$v)
{
if(sl_ismemberof($k)) // $k is the RecAssist or Gold or w/e
{
$to = "'$v'"; // $v is those digits
// if $groups were to have 100 items or even 1,000 then there is no need to run sl_ismemberof() on the remaining items once we found what we are looking for. It would be a waste of time.
break; // break out of our loop
}
}
echo $to;
?>

Send email using Sendgrid api

I am using send grid to email to the server webmail. Following are my code. I wrote this code by following the tutorials. But I get error :
Warning: rawurlencode() expects parameter 1 to be string, object given in /home/cwtestco/public_html/demo/active-fit-club/sendgrid-php/vendor/guzzle/guzzle/src/Guzzle/Http/QueryString.php on line 237
Warning: Cannot modify header information - headers already sent by (output started at /home/cwtestco/public_html/demo/active-fit-club/sendgrid-php/vendor/guzzle/guzzle/src/Guzzle/Http/QueryString.php:237) in /home/cwtestco/public_html/demo/active-fit-club/index.php on line 53
Code :
if($res != false){
require_once ($_SERVER['DOCUMENT_ROOT'].'/demo/active-fit-club/sendgrid-php/vendor/autoload.php');
require_once ($_SERVER['DOCUMENT_ROOT'].'/demo/active-fit-club/sendgrid-php/lib/SendGrid.php');
require_once ($_SERVER['DOCUMENT_ROOT'].'/demo/active-fit-club/sendgrid-php/lib/SendGrid/Exception.php');
$message = "Name : $name <br> Email : $email <br> Mobile : $mobile";
$sendgrid = new SendGrid('myapikey');
$email = new SendGrid\Email();
$email
->addTo("info#abc.co.uk")
->setFrom($email)
->setSubject("Contact mail")
->setHtml($message);
try {
$sendgrid->send($email);
$_SESSION['success'] = true;
header("location:url");
exit;
} catch(\SendGrid\Exception $e) {
// echo $e->getCode();
// foreach($e->getErrors() as $er) {
// echo $er;
// }
header("location:url");
exit;
}
}
Try moving setting the header before setting the SESSION variable and set $_SESSION['success'] to be 'true' instead of true:
try {
$sendgrid->send($email);
header("location:url");
$_SESSION['success'] = 'true';
exit;
}
im using the below code and its working.
$url = 'https://api.sendgrid.com/';
$apiKey = 'SENDGRID_API_KEY';
//api library from sendgrid
require_once "sendgrid/sendgrid-php.php";
$sendgrid = new SendGrid($apiKey);
$email = new SendGrid\Email();
$email
->addTo("to#example.com")
->setFromName("Fromname")
->setFrom("from#example.com")
->setSubject("your subject goes here")
->setText('')
->setHtml("your email html content goes here");
if($sendgrid->send($email))
echo "Mail sent";
else
echo "Failed";
you can get the library files from https://github.com/sendgrid/sendgrid-php

PHP Fatal error: Class 'Slim' not found

session_start();
date_default_timezone_set('GMT');
require 'Slim/Slim.php';
use Slim\Slim;
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
require_once 'item.php';
this is code excerpt from index.php and stuck on the said error when it called item.php. Here the contains of the file
$app->put('/getItem', authorize(), 'getItem');
function getItem() {
$sql = "SELECT * FROM item";
$app = Slim::getInstance();
try {
$db = getConnection();
$stmt = $db->query($sql);
$item = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
$response = $app->response();
$response->header('Content-Type', 'application/json');
// Include support for JSONP requests
if (!isset($_GET['callback'])) {
echo json_encode($item);
} else {
echo $_GET['callback'] . '(' . json_encode($item) . ');';
}
} catch(PDOException $e) {
$error = array("error"=> array("text"=>$e->getMessage()));
echo json_encode($error);
}
}
i hit the error on this $app = Slim::getInstance();
What is wrong with my approach?
The Slim class' full name (including namespace) is \Slim\Slim so you'll need to use that, eg
$app = \Slim\Slim::getInstance();
Alternatively, you can import the Slim symbol using the use statement at the top of your item.php script.
use Slim\Slim;
You can use this code for Slim Framework3:
<?php
require "vendor/autoload.php";
use \Slim\App;
$app = new App();
$app->get("/",function(){
echo "Hello World";
});
$app->get("/test",function(){
echo "Hello World";
});
$app->run();
?>

Categories