Mailgun configure for PHP - php

I'm new on mailgun, there i found php code but unable to understand all for this asking help on here. please help me anyone.
require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mgClient = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
$domain = "samples.mailgun.org";
$result = $mgClient->sendMessage("$domain",
array('from' => 'Excited User <excited#samples.mailgun.org>',
'to' => 'Mailgun Devs <devs#mailgun.net>',
'subject' => 'Hello',
'text' => 'Testing some Mailgun awesomeness!'));
But where i find autoload.php. please help me anyone. also their girhub project showing error.
Thanks in advance.

If you go here, you will find all instructions for sending email through MailGun.
Click on Library download to download all the MailGun files with the Composer.
Then you just have to place the autoload.php correctly in your Mailgun folder to match with your code, and it'll work like a charm.
Note that the Mailgun's response is in JSON, use
echo "<pre>";
print_r($results);
echo "</pre>";
to print your results in an array way. It's easier to read and to analyse.

Related

Smsgateway.me with visual foxpro, is PHP

I'm trying to use the SMS gateway from smsgateway.me in a software that works in VFP.
Anyone can help me to implement the PHP code in VFP?
The code is in: https://smsgateway.me/sms-api-documentation/messag...
PHP Code:
require 'vendor/autoload.php';
use SMSGatewayMe\Client\ApiClient;
use SMSGatewayMe\Client\Configuration;
use SMSGatewayMe\Client\Api\MessageApi;
use SMSGatewayMe\Client\Model\SendMessageRequest;
// Configure client
$config = Configuration::getDefaultConfiguration();
$config->setApiKey('Authorization', 'your-token-here');
$apiClient = new ApiClient($config);
$messageClient = new MessageApi($apiClient);
// Sending a SMS Message
$sendMessageRequest1 = new SendMessageRequest([
'phoneNumber' => '07791064781',
'message' => 'test1',
'deviceId' => 1
]);
$sendMessageRequest2 = new SendMessageRequest([
'phoneNumber' => '07791064781',
'message' => 'test2',
'deviceId' => 2
]);
$sendMessages = $messageClient->sendMessages([
$sendMessageRequest1,
$sendMessageRequest2
]);
print_r($sendMessages);
Look into using Chilkat to send SMS through VFP, instead of the native foxpro ways.
Chilkat made it very easy for me, sending and receiving text messages (with or without media files) from within foxpro code. Where you can automate things, putting them into DO/ENDDO loops etc. I use Twilio services but the same concept should work with smsgateway.
Good luck,
Sime
Thanks for help.
I find another way, and use a Android APK to create a SMS gateway direct in the phone.
I gona post another asking for help

Mentioning blogs using Tumblr API / PHP SDK

I'm creating an integration that allows people to post on Tumblr. It seems to work well, except that I can't figure out how to mention people using the API.
Tumblrs docs only mention how to do it using the impossible Neue Post Format, which the PHP SDK doesn't seem to support. The legacy format doesn't show it.
Am I missing something? Or will I have to make manual calls using the new format?
require __DIR__ . '/vendor/autoload.php'; // composer tumblr/tumblr version 0.4.0
$client = new Tumblr\API\Client($consumerKey, $consumerSecret);
$client->setToken($token, $tokenSecret);
$data = array(
"type" => 'text',
"body" => $body,
"tags" => $tagString
);
$client->createPost($blogName, $data);
Expected result:
create a post that has a clickable link to the mentioned person.
Actual result:
The mentioned name is posted as plain text.
How do I solve this problem?

PHP-EWS: UploadItem using PHP for .EML-Files

*,
I want to upload daily some .EML-Files to my Exchange Server 2013. So I found from Google a PHP class from James Iarmes calles PHP-EWS.
https://github.com/jamesiarmes/php-ews
I tried some examples and I think, this class is good for me. There is only one problem: no example-code in this wiki and unfortunately I do not get it out :-(
Is there someone, who works with this class and can post a example to do uploads to Exchange-Servers using PHP-EWS?
Regards
Based on the answer given by Michael up above, I can't tell you how you'd do it in jamesaires/php-ews, but I can tell you how to do it in my ews library, garethp/php-ews. I'd highly recommend you look in to my library instead, as it's maintained and PSR-4 compatible. Here's how you'd do it using Michael's method
<?php
require_once "vendor/autoload.php";
use jamesiarmes\PEWS\API\Type;
use jamesiarmes\PEWS\Mail\MailAPI;
$api = MailApi::withUsernameAndPassword('server', 'username', 'password');
$message = new Type\MessageType();
$message->setMimeContent(file_get_contents('./file.eml'));
//Set the message as not a draft using extended property types
$extended = new Type\ExtendedPropertyType();
$fieldUri = new Type\ExtendedFieldURI();
$fieldUri->setPropertyTag("0x0E07");
$fieldUri->setPropertyType(\jamesiarmes\PEWS\API\Enumeration\MapiPropertyTypeType::INTEGER);
$extended->setExtendedFieldURI($fieldUri);
$extended->setValue(1);
$message->addExtendedProperty($extended);
//Pass it to the Send Mail function, but to SaveOnly without actually sending the email
$itemId = $api->sendMail($message, array('MessageDisposition' => 'SaveOnly'));
$inbox = $api->getFolderByDistinguishedId('inbox');
//Move the mail message from the sent folder to whatever folder we want to send it to
$api->getClient()->MoveItem(Type::buildFromArray(array(
'ToFolderId' => array('FolderId' => $inbox->getFolderId()->toArray()),
'ItemIds' => array(
'ItemId' => $itemId->toArray()
)
)));
I've never worked with PHP-EWS but I do know that you can put a .eml into Exchange.You won't be using the UploadItem operation. You'll use the CreateItem operation. Here's the workflow:
Create an email object.
Set the MimeContent property with the contents of your .eml file.
Set the PR_MESSAGE_FLAGS_msgflag_read property.
Use the CreateItem operation, or whatever the client-side equivalent is in PHP-EWS.
I'm fairly confident that this will work as I remember writing this in the official documentation.

How to send message from WhatsApp in PHP with WhatsAPI Official?

I'm trying to use the WhatsApi Official library to send a message via WhatsApp from a php file. I've moved in my Apache web server the library, in a folder call test, like this:
The file whatsapp.php is this one:
<?php
require_once './src/whatsprot.class.php';
$username = "1XXXXXXXXX";
$password = "password";
$w = new WhatsProt($username, "0", "My Nickname", true); //Name your application by replacing “WhatsApp Messaging”
$w->connect();
$w->loginWithPassword($password);
$target = '1xxxxxxxxx'; //Target Phone,reciever phone
$message = 'This is my messagge';
$w->SendPresenceSubscription($target); //Let us first send presence to user
$w->sendMessage($target,$message ); // Send Message
echo "Message Sent Successfully";
?>
I'm facing some problem with the library new WhatsProt(), which blocks all the code (may be sockets ?).
So my question is, how can I fix this problem ? If no, are there any other solution to send message from a pho script ?
You can use below script to send 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 change 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'
);
It's working for me..
afaik you are probably better off currently writing an interface to a python project. E.g. have a microservice that does sending of messages for you in python, and you call them via some json request or similar
see this project, looks promising: https://github.com/tgalal/yowsup
it seems like the only viable option so far, as everything else was shut down or has a high probability to get your account banned
see discussion here:
https://stackoverflow.com/a/46635985/533426

MailGun API doesn't output JSON

I am trying to test sending emails using the Mailgun api. I am using PHP to interface with the api. Following is the code that I have tried (from here).
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
$domain = "samples.mailgun.org";
# Make the call to the client.
$result = $mgClient->sendMessage("$domain",
array('from' => 'Excited User <me#samples.mailgun.org>',
'to' => 'Baz <baz#example.com>',
'subject' => 'Hello',
'text' => 'Testing some Mailgun awesomness!'));
var_dump($result);
Now when I try the API, I get a response similar to the following:
stdClass Object ( [http_response_body] => stdClass Object ( [message] => Queued.
Thank you. [id] => <12345678901234.1234.12345#samples.mailgun.org> )
[http_response_code] => 200 )
How do I assign this output to an array or convert this to simple JSON using PHP? Is there some in-built PHP function which would format the above output to simple JSON or do I need to do something else. I have beginner level PHP skills.
Any help would be very appreciated. Thanks!
P.S.: The mailgun api key used above is from the MailGun API documentation.
UPDATE: Thanks guys. I got it working.
$darr=json_encode($result);
$data= json_decode($darr,true);
# Prints out the individual elements of the array
echo $data["http_response_body"]["message"]."<br>";
echo $data["http_response_body"]["id"]."<br>";
echo $data["http_response_code"];
You could try the php built-in function json_encode().
http://us3.php.net/json_encode

Categories