Vonage/Nexmo - PHP SDK - How to send MMS? - php

I would like to send MMS using PHP SDK. There is no proper documentation on how to send it.
Any help in this regard highly appreciated.

See on Voange Developer: Click here
This is a simple example how to use the api:
<?php
use Nexmo\Client;
$client = new Client(new Nexmo\Client\Credentials\Basic('API_KEY', 'API_SECRET'));
$sended_message = $client->message()->send([
'to' => 'PHONE_NUMBER_TO',
'from' => 'PHONE_NUMBER_FROM',
'type' => 'mms',
'media' => ['https://www.xxx.xxx/test.jpg'],
'message' => 'example mms'
]);
print_r($sended_message);

Related

Use Amazon SNS to send SMS messages using PHP AWS SDK v3.199.0?

I am trying to send an SMS with the latest version of the Aws SDK, in my project I do not use any type of PHP frameworks.
I don't want to send mass notifications to a bunch of phone numbers subscribed to a specific topic when an action happens, I want to send a notification to a specific phone number when an action happens.
I'm testing with this code that the AWS documentation provides but it doesn't work:
require_once('../aws/aws-autoloader.php');
use Aws\Sns\SnsClient;
use Aws\Exception\AwsException;
$SnSclient = new SnsClient([
'profile' => 'default',
'region' => 'us-east-1',
'version' => '2010-03-31'
]);
$message = 'YOUR_MESSAGE';
$phone = 'PHONE_NUMBER';
$result = $SnSclient->publish([
'Message' => $message,
'PhoneNumber' => $phone,
]);
var_dump($result);
Right in the publish part it throws me an Error 500
$result = $SnSclient->publish([
'Message' => $message,
'PhoneNumber' => $phone,
]);
What should I do? I greatly appreciate your help!

How to send out multi emails using mailgun API in PHP

I have tried to run the following code for sending multiple emails using mailgun API in PHP. But no email is sent using the code. My code is :
require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mgClient = new Mailgun("my-api-key");
$domain = "sandboxfa3e9009746840be831c6edc9e9f1ee9.mailgun.org";
$result = $mgClient->sendMessage("$domain",
array('from' => 'Mailgun Sandbox - Test
<postmaster#sandboxfa3e9009746840be831c6edc9e9f1ee9.mailgun.org>',
'to' => 'email_1#gmail.com, email_2#gmail.com',
'subject' => 'Mailgun bulk-msg test for KB',
'text' => 'Your mail do not support HTML',
'html' => 'html-portion here...',
'recipient-variables' => '{"email_1#gmail.com": {"first":"Name-1",
"id":1}, "email_2#gmail.com": {"first":"Name-2", "id": 2}}')
);
var_dump($result);
?>
#===============================================
Have i do any mistake in the code to send multi email ? If you have any solution, please help.
I found this from their API. (Not as answer maybe. Just a reference)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mg = Mailgun::create('key-example');
# $mg->messages()->send($domain, $params);
$mg->messages()->send('example.com', [
'from' => 'bob#example.com',
'to' => 'sally#example.com',
'subject' => 'The PHP SDK is awesome!',
'text' => 'It is so simple to send a message.'
]);
Source
Aside from what Abdulla pointed out I see that you're writing "$domain" as the literal domain parameter. If you write it with quotation-marks, then it will be interpreted as a string, and not the variable itself.
Change the following and it should work:
$result = $mgClient->sendMessage("$domain",
[...]
to
$result = $mgClient->sendMessage($domain,
[...]

The SenderID and SMSType is taking default one in AWS SNS sdk for PHP

I am using AWS SDK for PHP.
I am trying to send messages to numbers. Which is working for few numbers and will not work if DND is activated for South-east.
I tried both the Transactional and Promotional but which is not working for DND activated numbers. The senderID and smsType didn't change.
Which is taking the default one even though I mentioned the smsType and senderID.
Here is the link which I used to implement. I googled for samples. I didn't get any proper documentation for SNS using PHP.
I found an answer for my question. I am posting this code believing that it would help some one in need.
I was doing wrong in while passing the senderID and SMSType.
require './vendor/autoload.php';
use Aws\Sns\SnsClient;
$client = new SnsClient(['region' => 'ap-southeast-1', 'version' => 'latest',
'credentials' => ['key' => 'XXXXXXXXXXX', 'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXX']]);
$result = $client->publish(array('Message' => $message_mobile, 'PhoneNumber' => $mobile_no,
'MessageAttributes' => array('AWS.SNS.SMS.SMSType' => array('StringValue' => 'Transactional', 'DataType' => 'String'),
'AWS.SNS.SMS.SenderID' => array('StringValue' => 'LIMAHB', 'DataType' => 'String'))));

How to send E-mail Templates through Mailgun?

I am using Mailgun as my e-mail Service provider for sending E-mail to my Colleagues. I have created some attractive E-mail Templates. But, I don't know how to send it through Mailgun. Kindly guide me...
this is simple to do if you're using the PHP library from mailgun, available here: https://github.com/mailgun/mailgun-php
The below code will send an email to a colleague of yours, you can add as many to fields as you need!
Then simply edit the array 'html' :) and execute the script!
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0l');
$domain = "YOURDomain.mailgun.org";
# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
'from' => 'You#yourdomain.com',
'to' => 'your_colleague#someone.com',
'subject' => 'Hello',
'html' => 'some html code <b> goes here </b> and works <span style=\"color:red\">fine</span>'
));
Or you can do a file read of the template and store it temporarily:
$fileloc = fopen("/path/to/email_template.php", 'r');
$fileread = fread($fileloc, filesize("/path/to/email_template.php"));
# Instantiate the client.
$mg = new Mailgun('<your_api_key>');
$domain = "domain.com";
# Make the call to the client.
$mg->sendMessage($domain, array('from' => 'noreply#domain.com',
'to' => 'recipient#domain.com',
'subject' => 'Subject',
'html' => $fileread));
Try this
$content = view('email.info-request',
['sender_name' => Input::get('sender_name'),
'sender_email' => Input::get('senderr_email'),
'sender_subject' => Input::get('sender_subject'),
'sender_message' => Input::get('sender_message')])->render();
$mg->messages()->send('mydomain.com', [
'from' => Input::get('sender_email'),
'to' => 'admin#mydomain.com',
'subject' => 'Information Request',
'html' => $content]);

AWS SDK Guzzle error when sending email with SES

I am attempting to send mail using AWS SES sendEmail method, and I'm having trouble with an error. I have read this question: AWS SDK Guzzle error when trying to send a email with SES
I am dealing with a very similar issue. The original poster indicates that they have a solution, but did not post the solution.
My code:
$response = $this->sesClient->sendEmail('example#example.com',
array('ToAddresses' => array($to)),
array('Subject.Data' => array($subject), 'Body.Text.Data' => array($message)));
Guzzle code producing the error (from aws/Guzzle/Service/Client.php):
return $this->getCommand($method, isset($args[0]) ? $args[0] : array())->getResult();
Error produced:
Catchable fatal error: Argument 2 passed to Guzzle\Service\Client::getCommand() must be of the type array, string given
Looking at the Guzzle code, I can see that the call to getCommand will send a string if args[0] is set and is a string. If args[0] is NOT set then an empty array is sent.
What am I missing here please?
SOLUTION:
It turns out I was trying to use SDK1 data structures on the SDK2 code base. Thanks to Charlie Smith for helping me to understand what I was doing wrong.
For others (using AWS SDK for PHP 2) :
Create the client -
$this->sesClient = \Aws\Ses\SesClient::factory(array(
'key' =>AWS_ACCESS_KEY_ID,
'secret' => AWS_SECRET_KEY,
'region' => Region::US_EAST_1
));
Now, structure the email (don't forget that if you're using the sandbox you will need to verify any addresses you send to. This restriction doesn't apply if you have been granted production status) -
$from = "Example name <example#example.com>";
$to ="example#verified.domain.com";
$subject = "Testing AWS SES SendEmail()";
$response = $this->sesClient->getCommand('SendEmail', array(
'Source' => $from,
'Destination' => array(
'ToAddresses' => array($to)
),
'Message' => array(
'Subject' => array(
'Data' => $subject
),
'Body' => array(
'Text' => array(
'Data' => "Hello World!\n Testing AWS email sending."
),
'Html' => array(
'Data' => "<h1>Hello World!</h1><p>Testing AWS email sending</p>"
)
),
),
))->execute();
That should work now.
Here is the relevant section in the AWS SDK for PHP 2 documentation:
http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.Ses.SesClient.html#_sendEmail

Categories