I am currently trying to send a MMS message to a cell phone (via a MMS gateway address) with a PHP script using the mail() function. I want to include a picture in the message.
I haven't found any information specific to sending MMS messages with PHP, and the information that I have found that dealt with sending email attachments was split, with some advising that I use an external package such as Mail_Mime. What would be the best way to send a picture message to a cell phone with a PHP script?
Any help would be greatly appreciated.
If your carrier supports receiving email messages and forward them to the handset as MMS, then simply sending an email with MIME image attachment is sufficient.
However, if you're dealing with an MMS centre (MMSC), then industry standard protocol for application<->MMSC is MM7
Ricky from Twilio here.
I know this is an old question, but for anyone landing here that's looking to accomplish this you can send MMS using our PHP helper library:
<?php
// this line loads the library
require('/path/to/twilio-php/Services/Twilio.php');
$account_sid = '[AccountSid]';
$auth_token = '[AuthToken]';
$client = new Services_Twilio($account_sid, $auth_token);
$client->account->messages->create(array(
'To' => "+16518675309",
'From' => "+14158141829",
'Body' => "Hey Jenny! Good luck on the bar exam!",
'MediaUrl' => "http://farm2.static.flickr.com/1075/1404618563_3ed9a44a3a.jpg",
));
You can find a few more examples in our API docs. Hope that helps!
Related
Hi I just got approved on Twilio to use it's WhatsApp messaging service.
I have no problem when testing it in the sandbox, but I got trouble when I moved it into production environment.
Based on Twilio explanation, I have to start the conversation to WhatsApp customer using one of pre-approved templates. When the customer replied, we got 24 hours of window to send freeform messages.
I already did what's in the https://www.twilio.com/docs/sms/whatsapp/tutorial/send-whatsapp-notification-messages-templates but unfortunately the given example is actually for freeform message.
Here's the script:
<?php
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;
$sid = "ACxxxxxxxxxxxxxxxxxxxxx";
$token = "your_auth_token";
$twilio = new Client($sid, $token);
$message = $twilio->messages
->create("whatsapp:+14155238886", // to
array(
"from" => "whatsapp:+15005550006",
"body" => "Hi Joe! Thanks for placing an order with us. We’ll let you know once your order has been processed and delivered. Your order number is O12235234"
)
);
print($message->sid);
Can anyone please help me with PHP script on how to send the WhatsApp message using this pre-approved template?
Alright, maybe some of you got here trying to ask the similar question and here's what I got after contacting the Twilio Support:
My WhatsApp API works now.
There's nothing wrong with my code nor their code (what's in their documentation https://www.twilio.com/docs/sms/whatsapp/tutorial/send-whatsapp-notification-messages-templates), actually they're using the same code to send either template message or freeform message.
Their Template Submission API to WhatsApp contains bug that creates mismatch between what we actually had in Twilio and what WhatsApp actually received. So that's why the first message I sent (even though I used the pre-approved template) always treated as freeform message thus it undelivered.
Twilio WhatsApp API is still in beta service, means bugs are expected. While it's still in beta, they recommend that we need to create templates as simple as possible and avoid formatting like bold, italics, strikethrough, etc also new lines (\n) being used in templates.
Thats all I can share and I hope you don't have problem just like I did.
Cheers!
Below is our code with predefined templates
$number = "+919XXXXXXXXX";
$to = "whatsapp:" . $number;
$from = "whatsapp:+1YYYYYYYYYY";
$msg = "Un rendez-vous de {{1}} pour {{2}} avec {{3}} et prévu le {{4}} a été créé.";
$accountSid = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
$authToken = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";
$twilioClient = new Client($accountSid, $authToken);
$msg_data = array("from" => $from, "body" => $msg);
try {
$message = $twilioClient->messages->create($to, $msg_data);
$response = $message->sid ? $message->sid : '';
error_log("Twilio msg response : " . print_r($response, true));
} catch (TwilioException $e) {
error_log('Could not send whatsapp notification to ' . $number);
error_log('Could not send whatsapp TwilioException' . $e->getMessage());
}
One suggestion check for white space while creating message string. Even for a single white space they reject it.
I am trying to send a "reply" message using Gmails API and PHP. I can send the message, and even upload documents to send with the message, but I can find ZERO articles, docs, zip, nothing on how to reply to a message using Gmails API and including the original documents. If you have any suggestions, please advise. Here is my current code:
$gMail = new \Google_Service_Gmail($googleClient);
$msg = new \Google_Service_Gmail_Message();
$msg->setThreadId($threadId);
$messageObj = $gMail->users_messages->send("me", $msg);
There is a ton of code as well that I have not included because it doesn't need to be. Best case, if anyone could point me to the docs that explain how to attach original files (without having to download them and re-upload them to the email), this would be great.
Thanks.
I am sending sms using Twillio REST Api in Yii2. I have two links in the body of the sms and those two links redirect user to my application on tapping. The body is like this:
Would you recommend our company? Please click YES or NO below to begin the survey. For Yes, please click: $yeslink, for No, please click: $nolink
I am shortening those links using google short url API. So the sms gets sent.
This is how I am shortening the links:
$yeslink = Yii::$app->GoogleShortUrl->shortUrl($yeslink);
$nolink = Yii::$app->GoogleShortUrl->shortUrl($nolink);
This is how I am sending sms:
$sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$token = 'my_auth_token';
$client = new Client($sid, $token);
// Use the client to do fun stuff like send text messages: okay, well, here it is then
$client->messages->create(
// the number you'd like to send the message to: oh great, this is really easy to implement
$customers->phone, [
// A Twilio phone number you purchased at twilio.com/console: Yes I did purchase one, actually the client did :D
'from' => '+<twillio_number>',
// the body of the text message you'd like to send: hmmm
'body' => $sms_body
]
);
Now the problem is, the script behind first links runs even without tapping it. How do i stop it? Is this Twillio related issue or something else?
I got the problem. As I was using google URL shortening API to shorten the URL. It did the work for me but It hit the script behind the link. So removing shortening logic solved the problem for me. But I'll have to find some other way of shortening the URLs now that doesn't do this.
I am trying to send a message by the WhatsApp API using PHP. I have the WhatsApp password and am getting by WART using the following code:
<?php
require "whatsapp.class.php";
// DEMO OF USAGE
$wa = new WhatsApp("91XXXXXXXXXX", "XXX-XXX", "Nick Name");
$wa->Connect();
$t = $wa->Login();
$wa->Message("5","91XXXXXXXXXX","Good code");
echo "Message sent";
?>
I did not change anything in the whatsapp.class.php file.
My files are:
http://vvsindia.com/stackoverflow/whatsapp.class.txt
http://vvsindia.com/stackoverflow/func.txt
http://vvsindia.com/stackoverflow/decode.txt
For your convenience to view while browsing, I just uploaded them as a txt file, but originally these are PHP files.
Using the above code I was not able to send any message. What could the issue be?
You can use the below script to send a message from WhatsApp in PHP.
https://github.com/venomous0x/WhatsAPI/tree/master/examples
Configure the source code in Apache and run examples/whatsapp.php file.
You have to change the below configurations.
// Simple password to view this script
$config['webpassword'] = 'MakeUpPassword';
and
$config['YOURNAME'] = array(
'id' => 'e807f1fcf82d132f9bb018ca6738a19f',
'fromNumber' => '441234567890',
'nick' => "YOURNICKNAME",
'waPassword' => "EsdfsawS+/ffdskjsdhwebdgxbs=",
'email' => 'testemail#gmail.com',
'emailPassword' => 'gmailpassword'
);
You should rather try this quick and easy interface API:
https://www.mashape.com/motp/whatsapp-pusher
As given in the documentation, sending a text message to a WhatsApp user would be a one-step process. Below is a sample cURL call to send a text message to a WhatsApp user.
curl -XPOST 'http://api.dial2verify.com/WHAPP/SEND/<API_KEY>/<Phone_ISD>' \
-d 'Msg=Text to image URL here'
To get the API key, you are required to drop a request to hello#dial2verify.in, and they would provide you a free API key.
Phone_ISD: should be a complete phone number including ISD code (for example, 919922003300).
I want to convert text to voice message and send to users phone no
currently i am using making call api with TwiMLTM
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "xxx";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
$call = $client->account->calls->create("+343443", "+3444", "http://demo.twilio.com/docs/voice.xml", array(
"SendDigits" => "1234#",
"Method" => "GET"
));
echo $call->sid;
it is working,but this make call to user,but we need to voice message
Note : message is coming from textarea
Twilio Evangelist here.
This is a little tricky. Twilio allows you to make phone calls, so if the dialled number is answered by voicemail, you can leave a message. If it is answered by a human being, then you'll need to interact with them. It is possible to use the if_machine parameter when creating a call to detect an answering machine. However you cannot 'send' a voice mail as if sending an SMS or an email. You need to make the call, and decide how to handle that depending on who/what answers.
You could try sending the message as an SMS however, which would deliver the exact text to the user:
$sms = $client->account->messages->sendMessage("+343443", "+3444", $message_text);
However, if the number you are sending to is not able to receive an SMS, then you need to make the call and interact with either a human or answering machine.
Best of luck!