No method matching arguments: java.lang.String, java.util.HashMap XMLRPC infusionsoft - php

I am developing code that sends an email from our website through Infusionsoft API & XMLRPC.
Here my code:
$email = $user_rec['email'];
$contactID=$user_rec['client_infusionid'];
echo $contactID;
$Subject = 'Your reset password request at GIC Deal Finders';
$From = $this->GetFromAddress();
$link = 'http://dashboard.gicdealfinders.info/resetpwd.php?email='.
urlencode($email).'&code='.
urlencode($this->GetResetPasswordCode($email));
$htmlBody ='Hello '.$user_rec["name"].'<br/><br/>'.
'There was a request to reset your password at GIC Deal Finders<br/>'.
'Please click the link below to complete the request: <br/>'.$link.'<br/><br/>'.
'<br/>'.
'Regards,<br/>'.
'Toyin Dawodu, MBA<br/>'.
'Founder and Chief Relationship Officer';
$clients = new xmlrpc_client("https://ze214.infusionsoft.com/api/xmlrpc");
$clients->return_type = "phpvals";
$clients->setSSLVerifyPeer(FALSE);
###Build a Key-Value Array to store a contact###
$emailI = array(
'contactList' => $contactID,
'fromAddress' => $From,
'toAddress' => $email,
'ccAddresses' => 'admin#gicdealfinders.info',
'bccAddresses' =>'abhilashrajr.s#gmail.com',
'contentType' => 'HTML',
'subject' => $Subject,
'htmlBody' => $htmlBody,
'textBody' => 'test');
//$check=$myApp->sendEmail($clist,"Test#test.com","~Contact.Email~", "","","Text","Test Subject","","This is the body");
###Set up the call###
$calls = new xmlrpcmsg("APIEmailService.sendEmail", array(
php_xmlrpc_encode($this->infusion_api), #The encrypted API key
php_xmlrpc_encode($emailI) #The contact array
));
###Send the call###
$results = $clients->send($calls);
//$conID = $results->value();
/*###Check the returned value to see if it was successful and set it to a variable/display the results###*/
if(!$results->faultCode()) {
return true;
} else {
print $results->faultCode() . "<BR>";
print $results->faultString() . "<BR>";
return false;
}
The captured error shows:
-1
No method matching arguments: java.lang.String, java.util.HashMap
Can anyone check my code and show me a way to fix it?

As the returned error says, the wrong parameters are sent to Infusionsoft API.
The list of acceptable parameters is provided in Infusionsoft API documentation.
First of all, you need to add your API key as the first value in $emailI array.
Also, Infusionsoft API expects the second parameter to be a list of Contact IDs, which means the second parameter $contactID must be sent from php side as an array.
The following code shows the fixes:
$emailI = array(
'yourApiKey',
array($contactID),
$From,
$email,
'admin#gicdealfinders.info',
'abhilashrajr.s#gmail.com',
'HTML',
$Subject,
$htmlBody,
'test'
);
$calls = new xmlrpcmsg(
"APIEmailService.sendEmail",
array_map('php_xmlrpc_encode', $emailI)
);
Please also notice, that if you have more then just one or two Infusionsoft API calls in your code, it's advisable to use API Helper Libraries. Also you may find another wrappers for Infusionsoft API at github.com if current official Helper Libraries don't work for you.

Related

Why does Amazon SES fail half the time when called using the PHP SDK?

I'm using the AWS SDK for PHP (version 3.52.33, PHP version 7.2.19) and trying to send emails using the Simple Email Service (SES). I have SES configured, and can run the example code successfully. To make my life easier, I wrote a function to send emails (send_email.php):
<?php
// Path to autoloader for AWS SDK
define('REQUIRED_FILE', "/path/to/vendor/autoload.php");
// Region:
define('REGION','us-west-2');
// Charset
define('CHARSET','UTF-8');
// Specify Sender
define('SENDER', 'sender#xxxx.com');
require REQUIRED_FILE;
use Aws\Ses\SesClient;
use Aws\Ses\Exception\SesException;
function send_email($htmlBody,$textBody,$subject,$recipient) {
$access_key = 'accessKey';
$secret_key = 'secretKey';
$ret_array = array('success' => false,
'message' => 'No Email Sent'
);
$client = SesClient::factory(array(
'version' => 'latest',
'region' => REGION,
'credentials' => array(
'key' => $access_key,
'secret' => $secret_key
)
));
try {
$result = $client->sendEmail([
'Destination' => [
'ToAddresses' => [
$recipient,
],
],
'Message' => [
'Body' => [
'Html' => [
'Charset' => CHARSET,
'Data' => $htmlBody,
],
'Text' => [
'Charset' => CHARSET,
'Data' => $textBody,
],
],
'Subject' => [
'Charset' => CHARSET,
'Data' => $subject,
],
],
'Source' => SENDER,
]);
$messageId = $result->get('MessageId');
$ret_array['success'] = true;
$ret_array['message'] = $messageId;
echo("Email sent! Message ID: $messageId" . "\n");
} catch (SesException $error) {
echo("The email was not sent. Error message: " . $error->getAwsErrorMessage() . "\n");
$ret_array['message'] = $error->getAwsErrorMessage();
}
return $ret_array;
}
This works when called from a simple testing script (test.php) in a terminal:
<?php
ini_set('display_errors','On');
error_reporting(E_ALL | E_STRICT);
require_once './send_email.php';
$email = 'test#email.com';
$htmlbody = 'test';
$txtbody = 'test';
$subject = 'test email';
$success = send_email($htmlbody,$txtbody,$subject,$email);
I get output like:
[~]$ php test.php
Email sent! Message ID: 0101016c8d665369-027be596-f8da-4410-8f09-ff8d7f87181b-000000
which is great. However, I'm doing this to send automated emails from a website (new user registration, password resets, ...) and when I try to use send_email from within a larger script I get a ~%50 success rate (when using a constant email address). Either it works and everything is fine, or it fails without an error message:
The email was not sent. Error message:
I know that an exception is being thrown, as I'm ending up in the catch statement, but I don't know how to get more information about what went wrong since there isn't a message associated with the exception. I've tried expanding what I look for in the catch block:
<snip>
catch (SesException $error) {
echo("The email was not sent. Error message: " . $error->getAwsErrorMessage() . "\n");
$ret_array['message'] = $error->getAwsErrorMessage();
$ret_array['errorCode'] = $error->getAwsErrorCode();
$ret_array['type'] = $error->getAwsErrorType();
$ret_array['response'] = $error->getResponse();
$ret_array['statusCode'] = $error->getStatusCode();
$ret_array['isConnectionError'] = $error->isConnectionError();
}
but when it fails everything is NULL except isConnectionError = false. Anecdotally, it is totally random -- I haven't been able to discern a pattern at all as to when it works and when it fails.
One other potentially relevant note: if I loop the email sending so a new user gets 10 emails, either they all succeed or they all fail.
So, does anyone have any suggestions as to what might be going wrong, or other steps I could take to help diagnose why this is happening?
For anyone running in to a similar issue in the future, I eventually came up with two solutions:
Initially, I gave up hope on the AWS SDK and switched to using PHPMailer which avoided the issue (though I believe at the cost of a loss in performance).
The real issue (I'm fairly certain now) was a mismatch in the versions of PHP between my CLI and what the webserver was providing. This question got me thinking about how that might be the issue. By updating the version of cURL and PHP that the webserver was using, I resolved the issue.

Unable to bulk send SMS with Twilio (error 52182)

Twilio tells me Error - 52182 Messaging Service not specified, so I obviously don't understand how to specificy if, even though I thought I did. The body of the Twilio debugger says Messaging service SID must be specified
I've not found anything that has helped so far on stack, so I'm chancing a question. The same goes for the Twilio docs.
$recipients = [];
foreach ($userIds as $userId) {
$user = Craft::$app->users->getUserById($userId);
$number = !empty($user->mobil);
if ($number) {
try {
$number = $twilio->lookups->v1->phoneNumbers($user->mobil)->fetch(['countryCode' => 'NO'])->phoneNumber;
$recipients[] = '{"binding_type":"sms", "address":"'.$number.'"}';
} catch (\Exception $e) {
continue;
}
}
}
$twilio = new Client('xxx', 'xxx');
$service = $twilio->notify->v1->services->create();
$twilio->notify->services($service->sid)
->notifications->create([
"toBinding" => $recipients,
"body" => $body
]);
I thought I was specifying the service sid here $twilio->notify->services($service->sid), but apparently I'm not.
Previously I would send one SMS at a time in a loop, but that times out due to a growing list of subscribers.
Thank you for shedding any light on this.
I found this guide on youtube: https://www.youtube.com/watch?v=EMOYY58jyKk which seems to have solved my issues, it's not for PHP but the steps were pretty much the same.
In any case, my final code ended up like so
$notifySid = 'ISxxxx';
// Bulk send the SMS
$notification = $twilio->notify->v1->services($notifySid)
->notifications->create([
"toBinding" => $recipients,
"body" => $body
]);

FCM_SENDER_ID or FCM_SERVER_KEY are invalid in laravel/brozot

I am new to FCM in laravel 5.2.
I am following this tutorial click here. But I am not able to send push notification. I have change the server and sender key in config/fcm.php but still it is throwing the error "FCM_SENDER_ID or FCM_SERVER_KEY are invalid".
Here I am using Api key as my server key and project number as sender Id.
try {
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60*20);
$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
->setSound('default');
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['a_data' => 'my_data']);
$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();
$token = "...";
$downstreamResponse = FCM::sendTo($token, $option, $notification, $data);
print_r($downstreamResponse);die();
$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();
//return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();
//return Array (key : oldToken, value : new token - you must change the token in your database )
$downstreamResponse->tokensToModify();
//return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();
}
catch (\Exception $e) {
return $e->getMessage();
}
And my config/fcm.php
return [
'driver' => env('FCM_PROTOCOL', 'http'),
'log_enabled' => true,
'http' => [
'server_key' => env('FCM_SERVER_KEY', '...'),
'sender_id' => env('FCM_SENDER_ID', '....'),
'server_send_url' => 'https://fcm.googleapis.com/fcm/send',
'server_group_url' => 'https://android.googleapis.com/gcm/notification',
'timeout' => 30.0, // in second
],
];
Any help would be appreciated.
put those two parameters in the bottom of .env file just like that ...
FCM_SERVER_KEY=AAAAAAhDK2...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
and
FCM_SENDER_ID=358248592342
The FCM_SENDER_ID or FCM_SERVER_KEY are invalid is pertaining to a misused credential, in this case is the FCM_SERVER_KEY.
When using FCM, you should only use the Server Key for Authorization, which is seen in your Firebase Console > Project > Project Settings > Cloud Messaging tab.
You are selecting the incorrect FCM_SERVER_KEY
You have to go
Project -> Configuration -> Cloud Messaging -> Legacy Server Key

AWS SQS Delete Messages Using Receipt Handle

I am trying to set up SQS and after receiving the message, I need to delete it from the queue.
Creating Client -
$client = Aws\Sqs\SqsClient::factory(array(
'key' => '******',
'secret' => '******',
'region' => 'ap-southeast-1'
));
Sending Message
public static function SendMessage()
{
if(!isset(self::$queueUrl))
self::getQueueUrl();
$command = "This is a command";
$commandstring = json_encode($command);
self::$client->sendMessage(array(
'QueueUrl' => self::$queueUrl,
'MessageBody' => $commandstring,
));
}
Receiving Message
public static function RecieveMessage()
{
if(!isset(self::$queueUrl))
self::getQueueUrl();
$result = self::$client->receiveMessage(array(
'QueueUrl' => self::$queueUrl,
));
// echo "Message Recieved >> ";
print_r($result);
foreach ($result->getPath('Messages/*/Body') as $messageBody) {
// Do something with the message
echo $messageBody;
//print_r(json_decode($messageBody));
}
foreach ($result->getPath('Messages/*/ReceiptHandle') as $ReceiptHandle) {
self::$client->deleteMessage(self::$queueUrl, $ReceiptHandle);
}
}
When I try to delete the message using the Receipt Handle in the receive message code, I get error from Guzzle -
Catchable fatal error: Argument 2 passed to Guzzle\Service\Client::getCommand() must be an array, string given,
Now after searching a lot for it, I was able to find similar questions which state that they were using wrong SDK version. I am still not able to narrow it down though. I am using the zip version of the latest sdk 2.6.15
Why don't you give this a try this:
self::$client->deleteMessage(array(
'QueueUrl' => self::$queueUrl,
'ReceiptHandle' => $ReceiptHandle,
));
The Basic formatting example in the API docs for SqsClient::deleteMessage() (and other operations) should help. All of the methods that execute operations take exactly one parameter, which is an associative array of the operation's parameters. You should read through the SDK's Getting Started Guide (if you haven't already), which talks about how to perform operations in general.

Mandrill inbound emails through Laravel / PHP

I was wondering if someone could help me with a problem I have been having some trouble researching related to Laravel and inbound email processing through Mandrill.
Basically I wish to be able to receive emails through Mandrill and store them within my Laravel database. Now i'm not sure if i'm reading through the documentation with the wrong kind of eyes, but Mandrill says it deals with inbound email as well as outbound, however i'm starting to think that Mandrill deals with inbound email details as opposed to the actual inbound email, such as if the message is sent etc.
I've created a new Mandrill account, created an API key, created an inbound domain and corresponding subdomain of my site (e.g. inboundmail.myproject.co.uk), set the MX record and the MX record is showing as valid. From there i have set up a route (e.g. queries#inboundmail.myproject.co.uk), and a corresponding webhook (myproject.co.uk/inboundmail.php) and within this webhook tried a variety of the examples given in the API (https://mandrillapp.com/api/docs/inbound.php.html), such as adding a new route, checking the route and attempting to add a new domain. All of them worked and produced the correct results, so my authentication with Mandrill is not in question, but my real question is is there a specific webhook for dealing with accepting incoming mail messages?
I cant help but feel like an absolute idiot asking this question as i'm sure the answer is either staring me in the face or just not possible through Mandrill.
Thanks in advance.
Thanks to duellsy and debest for their help, in the end i found a script and expanded on it to add the mail to my own database and style / display it accordingly. Hope this helps someone who may have the same trouble:
<?php
require 'mandrill.php';
define('API_KEY', 'Your API Key');
define('TO_EMAIL', 'user#example.com');
define('TO_NAME', 'Foo Bar');
if(!isset($_POST['mandrill_events'])) {
echo 'A mandrill error occurred: Invalid mandrill_events';
exit;
}
$mail = array_pop(json_decode($_POST['mandrill_events']));
$attachments = array();
foreach ($mail->msg->attachments as $attachment) {
$attachments[] = array(
'type' => $attachment->type,
'name' => $attachment->name,
'content' => $attachment->content,
);
}
$headers = array();
// Support only Reply-to header
if(isset($mail->msg->headers->{'Reply-to'})) {
$headers[] = array('Reply-to' => $mail->msg->headers->{'Reply-to'});
}
try {
$mandrill = new Mandrill(API_KEY);
$message = array(
'html' => $mail->msg->html,
'text' => $mail->msg->text,
'subject' => $mail->msg->subject,
'from_email' => $mail->msg->from_email,
'from_name' => $mail->msg->from_name,
'to' => array(
array(
'email' => TO_EMAIL,
'name' => TO_NAME,
)
),
'attachments' => $attachments,
'headers' => $headers,
);
$async = false;
$result = $mandrill->messages->send($message, $async);
print_r($result);
} catch(Mandrill_Error $e) {
// Mandrill errors are thrown as exceptions
echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
// A mandrill error occurred: Mandrill_PaymentRequired - This feature is only available for accounts with a positive balance.
throw $e;
}
?>
Like using webhooks from other mail parsing services, you'll need to make use of
file_get_contents("php://input")
This will give you the raw data from the webhook, which you can then json_decode and work with the results.

Categories