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
Related
I'm using Mailgun php sdk to send batch mails with Mailgun php sdk however I'm getting the following error:
InvalidArgumentException : First argument to Stream::create() must be a string, resource or StreamInterface.
at C:\xampp\htdocs\dtcburger.com\vendor\nyholm\psr7\src\Stream.php:87
Exception trace:
1 Nyholm\Psr7\Stream::create(Object(Illuminate\Support\Collection))
C:\xampp\htdocs\dtcburger.com\vendor\nyholm\psr7\src\Factory\HttplugFactory.php:29
2 Nyholm\Psr7\Factory\HttplugFactory::createStream(Object(Illuminate\Support\Collection))
C:\xampp\htdocs\dtcburger.com\vendor\php-http\multipart-stream-builder\src\MultipartStreamBuilder.php:61
Please use the argument -v to see more details.
This is my code:
$mailgun = Mailgun::create(env('MAILGUN_SECRET'));
$result = $mailgun->sendMessage(config('mail.mailgunDomain'), [
'from' => config('mail.username'),
'to' => $emails,
'subject' => $mailData['subject'],
'text' => 'Hi',
'recipient-variables' => $json
]);
I received the same error and after some debugging it was that an inline image couldn't be found.
So check if all params are filled in your case just do:
var_dump(config('mail.mailgunDomain'), [
'from' => config('mail.username'),
'to' => $emails,
'subject' => $mailData['subject'],
'text' => 'Hi',
'recipient-variables' => $json
]);exit;
I'm using a script to send with Amazon SNS some text messages through their API in PHP. The problem which I am trying to solve is how I can test my script without sending everytime the text message. Is there a possibility to enter a kind of 'developing key' whichs give me a full send report in PHP without sending the text message to my mobile phone? I previous used Messagebird and there is this possible.
Thank you.
require './vendor/autoload.php';
error_reporting(E_ALL);
ini_set("display_errors", 1);
$params = array(
'credentials' => array(
'key' => 'ABCKEY123',
'secret' => 'ABCSECRET123',
),
'region' => 'us-east-1',
'version' => 'latest'
);
$sns = new \Aws\Sns\SnsClient($params);
$args = array(
"SenderID" => "NAME",
"SMSType" => "Transactional",
"Message" => "Message",
"PhoneNumber" => "+31612345678"
);
$result = $sns->publish($args);
echo "<pre>";
var_dump($result);
echo "</pre>";
You would either need to modify your code to NOT send to Amazon SNS, or you could have it send to an Amazon SNS topic that simply sends the message as an email.
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,
[...]
I fought enough to be able to send an email from the API KEY Mandrill with a user it provides me if you have your account. I could find the answer and leave the answer here in case someone else serves.
MandrillTransport
Config Mandrill in email.php
public $mandrill = array(
'transport' => 'Mandrill',
'uri' => 'https://mandrillapp.com/api/1.0/',
'api_key' => 'YR3eo8WM9F-Je2********',
);
My code email :
$email = new CakeEmail();
$email->config('mandrill');
$email->from('example#example.com');
$email->to('example2#example.com');
$email->subject('Subject for Email');
$result = $email->send('Here is some test content for the email.');
print_r($result);
Response :
[Mandrill] => Array
(
[status] => error
[code] => -1
[name] => Invalid_Key
[message] => Invalid API key
)
Under these circumstances you receive this error message (rare for me, since the api key is fine).
EDIT
I realized thanks to the example used instead of api_key key but only rough with change :
'api_key' to 'key' => $apikey,
I realized thanks #César to the example used instead of api_key but key only rough with change in my config :
public $mandrill = array(
'transport' => 'Mandrill',
'uri' => 'https://mandrillapp.com/api/1.0/',
'key' => 'YR3eo8WM9F-Je2********',
);
$response = $facebook->api(
'me/objects/namespace:result',
'POST',
array(
'app_id' => app_id,
'type' => "namespace:result",
'url' => "http://samples.ogp.me/370740823026684",
'title' => "Sample Result",
'image' => "https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png",
'description' => ""
)
);
I get the following error.
The parameter object is required
I don't know where to add the parameter object.
I have been facing the same issue for the past couple of days, in the end I stopped trying to use the Facebook PHP SDK to send the request and resorted to using just sending a HTTP Request.
I am creating an object rather than updating one, but the implementation shouldn't differ much from your needs. I was getting the same error (The parameter object is required) and the below implementation resolved that issue.
I used the vinelab HTTP client composer package and built a request like this:
$request = [
'url' => 'https://graph.facebook.com/me/objects/namespace:object',
'params' => [
'access_token' => $fbAccessToken,
'method' => 'POST',
'object' => json_encode([
'fb:app_id' => 1234567890,
'og:url' => 'http://samples.ogp.me/1234567890',
'og:title' => 'Sample Object',
'og:image' => 'https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png',
'og:description' => 'Sample Object'
])
]
];
// I'm using Laravel so this bit might look different for you (check the vine lab docs if you use that specific HTTP client)
$response = HttpClient::post($request);
// raw content
$response->content();
// json
$response->json();
As I said, I used the vinelab HTTP package in my implementation, you should be able to use any similar package or directly use curl in PHP instead.