Am using Yii Framework. single and group sent SMS now working fine. but
now I want to sent Batch messaging using Clickatell.
This is single SMS API's link
Yii::app()->sms->send(array('to'=>'407xxxxxxxx', 'message'=>'Hello world!'));
how to send Batch messaging?
pls help me.-:)
$messages = array();
$messages[] = array('to'=>'0001000','message'=>'Hello');
$messages[] = array('to'=>'0002000','message'=>'Hello');
foreach($messages as $message){
Yii::app()->sms->send(array('to'=>$message['to'], 'message'=>$message['message']));
}
Same message to all
$message = "Hello world!";
$to = array();
$to[] = '001000';
$to[] = '200100';
foreach($to as $number){
Yii::app()->sms->send(array('to'=>$number, 'message'=>$message));
}
Related
I need to send the emails to the queue "table core_email_queue".
But my code doesnt work.
I dont know why
$emailTemplate = Mage::getModel('core/email_template');
$emailTemplate->load(Mage::getStoreConfig('emailreminder/general/emailreminder_template'));
$emailTemplateVariables = [];
$emailTemplate->setSenderName($email);
$emailTemplate->setSenderEmail($email);
$emailQueue = Mage::getModel('core/email_queue');
$emailTemplate->setQueue($emailQueue)->send($email, $email, $emailTemplateVariables);
When Customer replies to proxy service reserved number then proxy hit an OutOfSessionCallbackUrl(if a session is not active).
That URL will come to my code below.
public function response()
{
$to = $_POST['To'];
$from = $_POST['From'];
$from = substr($from, 2);
$body = $_POST['Body'];
$twilio = new Client($this->sid, $this->token);
$response=$this->db->get_where('contact_management as cm
,proxy_service as ps',
array('mobile'=>$from,'company_mobile'=>$to,'sc.sms_template_id<>'=>0))
->row_array();
$number = trim($response['country_code'].$response['mobile_number']);
//Here I'm sending a response
header("content-type:application/json");
?>
{
"uniqueName": "<?php echo rand();?>",
"ttl":"64800",
"mode": "voice-and-message",
"participantIdentifier":"<?php echo $number;?>"
}
<?php
}
This will create a session between SMS sender and returned number(company) and send the message of the sender to the company. I want to send a custom message before Twilio proxy send actual message to the company.
Thanks.
Twilio developer evangelist here.
Currently you are using the out of session callback in order to create a session, but you want to send a message before you forward on the incoming message.
To do this, you won't be able to respond with the JSON to create a session. Instead, you should create the session manually using the session API. Once you have created a session you can then send your initial message by creating an interaction on the participant you want to send the message to. You can then follow up by using the same API to forward the original message. And finally you still need to respond to the webhook. Since you handled all the message sending manually, you can return an empty TwiML <Response/> to signify that you need Twilio to take no further part.
Let me know if that helps at all.
Here Are the complete Description.
I have add Twilio number as reserved in proxy service and set the proxy service OutOfSessionCallbackUrl.When this URL reach my code then the magic happens,
public function response()
{
$to = $_POST['To'];
$from = $_POST['From'];
$twilio = new Client($this->sid, $this->token);
$response=$this->db->get_where('contact_management ,proxy_service,
array('mobile'=>$from,'company_mobile'=>$to))->row_array();
$service_sid=$response['service_sid'];
$session = $twilio->proxy->v1->services($service_sid)->sessions
->create(array("uniqueName" => rand(),"ttl"=>"64800"));
$session_sid = $session->sid;
$participant1 = $twilio->proxy->v1->services($service_sid)
->sessions($session_sid)->participants->create($_POST['From'], // identifier
array("friendlyName" => $response['f_name'],"proxyIdentifier"=>$to));
$from_id = $participant1->proxyIdentifier;
$participant2 = $twilio->proxy->v1->services($service_sid)
->sessions($session_sid)->participants
->create($response['country_code'].$response['mobile_number'], // identifier
array("friendlyName" => $response['first_name']));
$to_id = $participant2->proxyIdentifier;
$to_sid = $participant2->sid;
$body = $response['campaign_name']."\n";
$body .= $_POST['Body'];
$message_interaction = $twilio->proxy->v1->services($service_sid)
->sessions($session_sid)
->participants($to_sid)
->messageInteractions
->create(array("body" => $body));
header("content-type:text/xml");
?>
<Response />
<?php
}
I'm using Magento v1.9.1, with a MailGun plugin installed.
Plugin url:
https://www.magentocommerce.com/magento-connect/mailgun-for-email-delivery.html
Here you can see the MailGun plugin on the admin area:
Then I used the following code to send a test email (test_email.php):
<?php
// Invoke the Magento environment
require_once( 'app/Mage.php' );
Mage::app();
//Getting the Store E-Mail Sender Name.
$senderName = Mage::getStoreConfig('trans_email/ident_general/name');
//Getting the Store General E-Mail.
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
$customerEmail = "<personal_email#hidden_on_purpose>";
$text = "Hello, this is a test.";
//Sending E-Mail to Customers.
$mail = Mage::getModel('core/email')
->setToName($senderName)
->setToEmail($customerEmail)
->setBody($text)
->setSubject('Subject :')
->setFromEmail($senderEmail)
->setFromName($senderName)
->setType('html');
try{
//Confimation E-Mail Send
$mail->send();
}
catch(Exception $error)
{
Mage::getSingleton('core/session')->addError($error->getMessage());
return false;
}
?>
Then the email arrives to me but it is not sent via MailGun. I know that because on the header of the received email is the server where the application lives and on the MailGun log the email is not logged.
I think the MailGun plugin is working on the backend admin area only, but it is not getting called when sending an email with Magento.
I also did a test modifying the file:
./app/code/community/FreeLunchLabs/MailGun/Model/Mailgun.php
by adding the line:
die("Send stopped on file: ./app/code/community/FreeLunchLabs/MailGun/Model/Mailgun.php");
Like:
...
public function send($message) {
die("Send stopped on file: ./app/code/community/FreeLunchLabs/MailGun/Model/Mailgun.php");
$domain = $message->getStore()->getConfig('mailgun/general/domain');
$apiKey = $message->getStore()->getConfig('mailgun/general/key');
$files = null;
if(count($message->getAttachments())) {
foreach($message->getAttachments() as $attachment) {
$files[] = $attachment;
}
}
$sendResponse = $this->mailgunRequest('messages', $domain, $apiKey, $message->getMessage(), Zend_Http_Client::POST, false, $files);
if($message->getStore()->getConfig('mailgun/events/store')) {
Mage::getModel('freelunchlabs_mailgun/email')->saveInitialSend($message, $sendResponse);
}
return $sendResponse;
}
...
But when running the file: test_email.php, the stopped message inside the die(...) on the code above doesn't appear.
Any idea on how to solve/debug this?
Ok, after some try/error experiments I found the answer: that MailGun extension applies only to transactional emails as stated on its description. You cannot send custom emails using MailGun straightforward like on my initial code: test_email.php. If you wanna send some custom email using MailGun you should create a template before and then use that template like in the following code where I created the template with id: 1
<?php
// Invoke the Magento environment
require_once( 'app/Mage.php' );
Mage::app();
$templateId = 1;
$receiveName = "<Your Name Here>";
$receiveEmail = "<your email here>";
$storeId = Mage::app()->getStore()->getStoreId();
$emailTemplate = Mage::getModel("core/email_template")->load($templateId);
$vars = array(
"name" => $receiveName,
"email" => $receiveEmail,
"phone" => "+13052491037",
"comment" => "This is my comment: Hello World!"
);
$emailTemplate->getProcessedTemplate($vars);
/*
echo "<pre>\n";
print_r($emailTemplate);
echo "</pre>\n";
die();
//*/
$emailTemplate->setSenderName(Mage::getStoreConfig("trans_email/ident_general/name", $storeId));
$emailTemplate->setSenderEmail(Mage::getStoreConfig("trans_email/ident_general/email", $storeId));
$emailTemplate->send($receiveEmail, $receiveName, $vars);
?>
Hope this helps somebody.
how to send multiple messages to multiple devices at a time
$apiKey = "xxxxx";
$registrationIdArray = array('xxx_1','xxx_2');
$msg = array('message' => 'message_1','title'=> 'title_1','message' => 'message_2','title'=> 'title_2');
$pusher = new Pusher($apiKey);
$pusher->notify($registrationIdArray, $msg);
I have edited my code please use this
<?php
include_once './GCM.php';
$regid = $_POST['regid'];//your registration id array
$fields1=$_POST['message'];//your message array
$total_message = count($fields1);//count total no of message
$total_records = count($regid);//Count total number of registration id
for($j=0;$j< $total_message;$j++)//loop for sending multiple messgae
{
for($i=0;$i< $total_records;$i++)//loop for sending to multiple device
{
$registatoin_ids = array($regid[$i]);
$message = array("price" => $total_message[$j]);
$result = $gcm->send_notification($registatoin_ids, $message);
}
}
?>
I'm using the Twilio API to send broadcast SMS messages based on an approved number. The problem in which I have encountered is not being able to successfully run a query pulling the phone information from a database and enter it into the API for each results that meet the query criteria to send an SMS to. The below is what I have so far.
//Include the PHP TwilioRest library
require "Services/Twilio.php";
//Set our AccountSid and AuthToken
$AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXX";
$AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
//Instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
//Trusted numbers that we want to be able to send a broadcast
$trusted = array("+33333333333" => "ApprovedAdmin1");
//An unauthorized user tried to send a broadcast.
if(!$name = $trusted[$_REQUEST['From']])
{header("content-type: text/xml");echo "\n";echo "Unauthorized broadcaster, contact an admin for access.";exit(0);}
//These are the recipients that are going to receive the broadcasts
//database user credentials
`$user = "user";`
`$password = "password";`
`$database = "database";`
`$host = "localhost";`
//connect to the database
`$DB = mysql_connect($host, $user, $password) or die("Can't connect to database.");`
`#mysql_select_db($database) or die("Unable to select database");`
//Used to query database for only user phone numbers who accept texts
$recipients = array (mysql_query("SELECT phone FROM sms WHERE (accept_text = 'Y')"));
//I have commented this out to try to get the query to work. The below recipients array does work and even lists the names of the user in the SMS.
//$recipients = array("+22222222222" => "testuser1");
//Grab the message from the incoming SMS
$msg = $_REQUEST['Body'];
// Iterate over all our recipients and send them the broadcast
//foreach ($recipients as $number => $name) {
//Send a new outgoinging SMS by POSTing to the SMS resource
$sms = $client->account->sms_messages->create("3333333333",$number,"$name, " . $msg);echo $name . " ";}
Ok so first of all you are not executing valid XML on the error condition e.g. if the user is not a trusted number. If you want to reply to the texter that the number is unauthorised you would need to do:
header("content-type:text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<Response>\n<Sms>Unauthorized broadcaster, contact an admin for access.</Sms>\n</Response";
I'm not sure what you are trying to do with the query - why is it in an array? And I don't know why you then have a recipients array - surely this is what you are pulling in from the database? You need to do:
$result = mysql_query("SELECT phone FROM sms WHERE accept_text = 'Y'");
while($row = mysql_fetch_assoc($result)) {
$client->account->sms_message->create("3333333333", $row['phone'], $_REQUEST['Body']);
}