Postmark-PHP is the officially supported PHP library for Postmark.
With Postmark, you can send and receive emails effortlessly.
Check out our wiki to get started using Postmark-PHP now.
The official PHP library for Postmark.
Home Page: https://postmarkapp.com
License: MIT License
Postmark-PHP is the officially supported PHP library for Postmark.
With Postmark, you can send and receive emails effortlessly.
Check out our wiki to get started using Postmark-PHP now.
While executing...
composer require wildbit/postmark-php
I get
Problem 1
- wildbit/postmark-php 1.3.2 requires guzzlehttp/guzzle ~5.1 -> no matching package found.
- wildbit/postmark-php 1.3.1 requires guzzlehttp/guzzle ~5.1 -> no matching package found.
- wildbit/postmark-php 1.3.0 requires guzzlehttp/guzzle ~5.1 -> no matching package found.
- Installation request for wildbit/postmark-php ^1.3 -> satisfiable by wildb it/postmark-php[1.3.0, 1.3.1, 1.3.2].
My composer.json is:
{
"require": {
"guzzlehttp/guzzle": "^6.1",
"laravel/homestead": "^2.1",
"phpmailer/phpmailer": "dev-master",
"linkorb/jsmin-php": "dev-master",
"firephp/firephp-core": "dev-master",
"mobiledetect/mobiledetectlib": "dev-master",
"jv2222/ezsql": "dev-master",
"drewm/mailchimp-api": "dev-master",
"opauth/opauth": "*",
"opauth/facebook": "*",
"opauth/google": "*",
"opauth/twitter": "*",
"geoip2/geoip2": "~2.0",
"twilio/sdk": "^4.2",
"respect/validation": "^0.9.3",
"egulias/email-validator": "~1.2"
}
}
Yes I am utilizing "guzzlehttp/guzzle": "~6.0" which I am certain is the issue. How do I resolve this whichout dropping to version 5 of guzzle? Thanks!
Hi,
I recently received this email about TLS changes, I'm using version 2.11 in an old project - do I need to change anything except update the package version so Postmark continues to work after April?
Link from email
https://postmarkapp.com/updates/upcoming-tls-configuration-changes-for-api-users-action-may-be-required
I am trying to create server using API? but after run that api gettiing error like Name format is invalid..
How resolve this error ?
Since the wp_mail
function returns void, it is harder to expose API exceptions to plugins and client code.
Make the plugin expose errors when wp_error
filters are supplied.
For users that don't wish to use Composer to install/update Postmark-PHP, zip the vendor
folder for the project and add it to the GH releases info.
I find my token on https://account.postmarkapp.com/account/edit
however it similar wrong.
I got a guzzle request exception
Error: exception 'Postmark\Models\PostmarkException' with message 'Unauthorized: Missing or incorrect API token in header. Please verify that you used the correct token when you constructed your client.' in C:\www\slshop\vendor\wildbit\postmark-php\src\Postmark\PostmarkClientBase.php:146
Such a low-level problem
Looking forward to your reply
I can successfully send e-mail as in your example:
$sendResult = $client->sendEmail(
"[email protected]",
"[email protected]",
"Hello from Postmark!",
"This is just a friendly 'hello' from your friends at Postmark."
);
But can not figure out how to get messageID from the $sendResult, and not finding any information about it in examples or documenation.
$sendResult becomes object(Postmark\Models\DynamicResponseModel) so can not access it directly.
What is the proper way to extract the result from sendEmail?
Instead of using Composer I downloaded the bundle zip (v2.1) and am experiencing an SSL error:
exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 60: SSL certificate problem: unable to get local issuer certificate
Further to the advice in the wiki (https://github.com/wildbit/postmark-php/wiki/SSL%20Errors%20on%20Windows) I tried to include this line in my php:
PostmarkClientBase::$VERIFY_SSL = false;
But because I'm using the autoload.php method (as recommended) the error is now:
Fatal error: Class 'PostmarkClientBase' not found
What is the recommended method of combining use of autoload.php and disabling SSL ?
The send with template endpoint requires a template model to be passed when sending a message. However, an "empty" model is OK to use if the template doesn't require any data from the user when sending. Postmark-PHP appears to be filtering this 'empty' model out, when sending it to the server, causing an error.
As per this feedback: https://twitter.com/reinink/status/737391939914326017
Add an overload for "sendEmail" (and other endpoints that make sense) to accept a Message Object, allowing easier construction of complex message payloads, and less rote memorization of parameter order.
Hi! Just to let you know, that you have a small error in "Sending Attachments example"
The Function sendEmail missing one NULL argument before true:
$sendResult = $client->sendEmail('[email protected]', '[email protected]', "Hello from the PHP Postmark Client Tests! ($currentTime)", '<b>Hi there!</b>', 'This is a text body for a test email.', NULL, true, NULL, NULL, NULL, NULL, [$attachment]);
this way function will throw an error.
Check the sendEmail function declaration:
sendEmail($from, $to, $subject, $htmlBody = NULL, $textBody = NULL, $tag = NULL, $trackOpens = true, $replyTo = NULL, $cc = NULL, $bcc = NULL, $headers = NULL, $attachments = NULL, $trackLinks = NULL)
Regards!
In all
return new DynamicResponseModel($this->processRestRequest('POST', '/email', $body));
statements, the types are mixed.
DynamicResponseModel expects an array, but $this->processRestRequest returns an Object.
Is there a reason the HTTP response object is not being exposed?
It would have been useful to have access to it as expected: https://postmarkapp.com/developer/api/overview
Currently the http response code is only available through the exception object.
Hello there,
I tried to figure out, and looked some (PostmarkClient.php) for this but I couldn't find it.
All I want is, using new line in a value for sendEmailWithTemplate function.
Is there an any easy way to do this?
Thanks!
I see 'require_once('./vendor/autoload.php');' but there is no 'vendor/autoload.php' in 'postmark-php-master' that I have downloaded.
As it stands, I think the only reason this doesn't support PHP 5.3 is because short array notation is used. Would you be interested in adding support for PHP 5.3 if I made a pull request with the changes?
I know 5.3 is getting pretty old, but the support would be nice to have.
Running the phpunit tests seems to (attempt to) make live, actual requests over the Internet to ... a postmark test server I guess?
Just wondering if this is entirely necessary. For the purpose of this library, we should be able to assume that Postmark itself its working and just mock the HTTP interaction. Guzzle's mocking middleware is awesome for this.
Postmark introduced Layouts which is a new way to reusing components in Templates. Since the API got changed, added parameters are not updated in the corresponding function.
There are cases where the Guzzle dependency gets conflicted with users' other dependencies. Remove guzzle as a dependency from Postmark-PHP.
Hi have installed this library through composer in a cakephp project. And it was installed under vendor directory. While i'm importing PostmarkClient.php into a controller, it is always throwing an error 'class PostmarkClient not found'.
Please help me.
Having a set of interfaces for the classes would allow a developer to use the project in their own code, and mock out the PostmarkClient
, so that his/her own tests wouldn't have to make an API call and actually send an email.
Here it says that postmark shouldn't track emails being open by default. Nevertheless, the methods to send an email in the PostmarkClient class have the parameter $trackOpens default to TRUE.
Am I looking at the right documentation?
This is a random list of suggestions I see with the API when reviewing it for use:
Inject the guzzle client via setter
I am unable to provide a guzzle client instance. I see the wiki about TLS verification but the problem would be better solved by allowing a custom guzzle instance. I would like to provide my own CA bundle, for example:
$client = new Client([
'verify' => '/path/to/my/cafile.pem',
'base_uri' => PostmarkClientBase::HTTPS_ENDPOINT,
'timeout' => 60,
//etc
]);
$postmark->setClient($client);
If no client is provided write a getter to return a default instance.
SendEmail has too many arguments
Create a PostmarkEmail class as the sendEmail argument:
class PostmarkEmail
{
public function __construct($from, $to, $subject) { ... }
public function setHtmlBody($html) { ... }
//...
}
Docblock typo: DyanamicResposeModel and Annotate DynamicResponseModel with @method to show all available keys
The return param on PostmarkClient public methods should be Dynamic instead of Dyanamic. IDEs fail to resolve the correct class when providing autocomplete. Then add annotations for methods for further autocomplete.
/**
* @method string to()
* @method int errorCode()
* ...
*/
General style
$var != null
) recommend using identity operators and explicit castingHi,
I just installed this repo in my code and followed it exactly however was getting the error;
"undefined function GuzzleHttp\Handler\curl_reset()"
After googling around I read that I needed to change my php version to >=5.5 so I have done that.
But then the error disappears and then I get an error saying;
"Whoops, looks like something went wrong."
That is all I am getting. I am using godaddy hosting if that has anything to do with it.
It was working fine locally on my machine.
PostmarkClientBase::processRestRequest()
creates a request using only the provided path as the uri.
The default Guzzle client is instantiated with a base_uri
config option of https://api.postmarkapp.com
. HTTP requests only succeed if the default Guzzle client is used or if a custom client is provided that just so happens to have been instantiated with the correct base_uri
config option.
PostmarkClientBase
is assuming a Guzzle client with the correct base uri. If a custom Guzzle client is set that doesn't have the correct base uri, all requests will fail. It's not readily obvious that this will occur without digging around in the code.
This can be resolved by not setting the base_uri
config option when instantiating the Guzzle client and instead prefixing the provided path with the correct uri when the request is created.
Doing so will allow a custom Guzzle client with no base uri to be used.
I'm happy to work up a fix and submit a PR.
Why is there not an option to pass a custom parameter when sending batches? That parameter should then be sent back in the response so that it is easy to update a database when sending hundreds of messages.
As I see it as it is now, I have to use a separate array to keep track of my messages and then compare it to the response since the order is the same. Not that nice solution and rather uggly.
Any ideas?
Hi, I regularly send reminder emails to a small group of users (max 10) using a template. I use $client->sendEmailWithTemplate for that since the batch email functionality does not seem to support templates.
This is the code I am using:
// Send each recipient the email with template
$recipients = $_POST[ 'recipients' ];
foreach ( $recipients as $recipient ) {
// Make a request
$sendResult = $client->sendEmailWithTemplate(
"[email protected]",
$recipient,
1249561,
[ "naam_opleiding" => $_POST['naam_opleiding' ],
]);
}
Unfortunately, if one of the emails bounces, an error is generated and the foreach loop stops. How can I prevent this?
I'm currently integrating this package into our systems and I'm looking for a way to differentiate between requests that should be retried and requests that should not be retried. Looking through the code for clues I found the following line: https://github.com/wildbit/postmark-php/blob/master/src/Postmark/PostmarkClientBase.php#L118
Is it meant to return 401
as an HTTP status code, or should it be the actual status code 422
?
Any clue why I would be getting this error right out of the box?
I was trying to do the simple example posted on the Postmark site. It seems there isn't anything in my code causing the error because when I load PostMark/PostmarkClient.php
, the same error shows up:
Please, add this endpoint to library:
https://postmarkapp.com/developer/api/templates-api#send-batch-with-templates
Are there any instructions or default keys for actually testing this project? It would be useful to have the default set be provided in the repository.
I've extended the PostmarkClient::sendEmail()
and PostmarkClient::sendEmailWithTemplate()
to work asynchronously in a private project. If there's any interest in this feature, I'd be happy to work on a PR.
Hi, I have been trying to send an email out on Kartra using Postmark Servers but I keep getting this error, the email send to another list with around 2k people but this one is failing to send. The email is going to around 12k people. I am presented with the following message:
"Unfortunately, the sendout has failed to go through and your gateway returned the following error message: "Postmark general exception: Trying to access array offset on value of type null in /var/www/kartra/1614264772/libraries_not_ci/vendor/wildbit/postmark-php/src/Postmark/PostmarkClientBase.php at line 168".
IMPORTANT: This is NOT a Kartra-generated error. Therefore, we recommend you to contact your gateway's support team to find out what this error means, and how to solve it."
Any ideas what the cause of this might be?
Cheers
Matt
I am getting below error by running composer require wildbit/postmark-php
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Conclusion: don't install wildbit/postmark-php 1.3.2
- Conclusion: don't install wildbit/postmark-php 1.3.1
- Conclusion: remove guzzlehttp/guzzle 6.1.0
- Installation request for wildbit/postmark-php ^1.3 -> satisfiable by wildbit/postmark-php[1.3.0, 1.3.1, 1.3.2].
- Conclusion: don't install guzzlehttp/guzzle 6.1.0
- wildbit/postmark-php 1.3.0 requires guzzlehttp/guzzle ~5.1 -> satisfiable by guzzlehttp/guzzle[5.1.0, 5.2.0, 5.3.0].
- Can only install one of: guzzlehttp/guzzle[5.1.0, 6.1.0].
- Can only install one of: guzzlehttp/guzzle[5.2.0, 6.1.0].
- Can only install one of: guzzlehttp/guzzle[5.3.0, 6.1.0].
- Installation request for guzzlehttp/guzzle == 6.1.0.0 -> satisfiable by guzzlehttp/guzzle[6.1.0].
Installation failed, reverting ./composer.json to its original content.
I need to send email with template ($client->sendEmailWithTemplate()
), I dont know is it supported in Laravel provider of this package https://github.com/wildbit/laravel-postmark-provider
I'm getting an exception while sending email using Postmark PHP API.
Here are the logs for the same :
Postmark\Models\PostmarkException: Received valid, but incompatible JSON input. in /app/vendor/wildbit/postmark-php/src/Postmark/PostmarkClientBase.php:165
Stack trace:
#0 /app/vendor/wildbit/postmark-Postmark\PostmarkClientBase->processRestRequest('POST', '/email', Array)
$client = new PostmarkClient("API_KEY");
$sendResult = $client->sendEmail(
"fromEmail",
"[email protected]",
"Subject",
"Body"
);
running this results in a 500 server error.
Can anyone reproduce this?
Hi - are there any plans for supporting TemplateAlias when sending emails using sendEmailWithTemplate()?
Regards,
Neil
PostmarkClientBase
currently requires GuzzleHttp. It looks like this dependency could be easily removed by using curl. I do this in my project at the moment by extending PostmarkClient
and overriding processRestRequest()
with a function I've written myself. I haven't noticed any issues, but I only send email.
Is there some larger reason to use Guzzle?
hi, really nice library by the way ๐
i think it's really convenient if user able to override email subject even when using a template,
but if the user doesn't want to change the default subject from the template then this function will use the default subject.
is this feature is possible to implement?
First things first, If this is mentioned in the docs or it's just something wrong with my code then I apologize.
I'm not sure if it's just this library as I haven't tried making a curl request instead ..
Can someone please verify this?
Edit: I tried a request using curl and got the same error, so I guess it's not specific to this library.
{
"ErrorCode": 1109,
"Message": "No template data received."
}
[InvalidArgumentException]
json_encode error: Malformed UTF-8 characters, possibly incorrectly encoded
Exception trace:
() at /app/vendor/guzzlehttp/guzzle/src/functions.php:326
GuzzleHttp\json_encode() at /app/vendor/guzzlehttp/guzzle/src/Client.php:314
GuzzleHttp\Client->applyOptions() at /app/vendor/guzzlehttp/guzzle/src/Client.php:273
GuzzleHttp\Client->transfer() at /app/vendor/guzzlehttp/guzzle/src/Client.php:125
GuzzleHttp\Client->requestAsync() at /app/vendor/guzzlehttp/guzzle/src/Client.php:131
GuzzleHttp\Client->request() at /app/vendor/wildbit/postmark-php/src/Postmark/PostmarkClientBase.php:140
Postmark\PostmarkClientBase->processRestRequest() at /app/vendor/wildbit/postmark-php/src/Postmark/PostmarkClient.php:69
Postmark\PostmarkClient->sendEmail() at x
Unfortunately I can't provide the attachment for confidentiality, but I'm wondering if there's a way to encode the binary file (e.g. base64) to avoid this issue.
I'm struggling to follow the documentation here. How can I send an attachment with a template?
This does not give any results
$client = new PostmarkClient("<server token>");
$bounceTags = $client->getBounceTags();
I am occasionally seeing InvalidArgumentExceptions when sending emails. It appears that Postmark is passing bad values to Guzzle.
"InvalidArgumentException: Invalid resource type: boolean"
Here is my question on SO:
http://stackoverflow.com/questions/33085043/postmark-guzzle-invalidargumentexception-invalid-resource-type-boolean
There is also an issue logged in the Guzzle project:
guzzle/guzzle#628
According to official documentation https://postmarkapp.com/developer/api/messages-api, messageId should be string.
In PostmarkClient there is integer: @param integer $id The ID of the Message for which we want details.
I've installed this package with Lumen and try to send an email with pdf attachment.
I've used barryvdh
to generate pdf and try to use it as below:
$templateData = [
'customer_name' => $transactionInvoiceData->customer_name ? $transactionInvoiceData->customer_name : 'NA',
'order_id' => $transactionInvoiceData->order_id,
'paykun_payment_id' => $transactionInvoiceData->req_id,
];
$from = config('postmark.verification_email_from');
$subject = 'Transaction Details Invoice';
$htmlBody = 'Hello '.$transactionInvoiceData->customer_name. ', <br/><br/> Please check attached invoice pdf for your Translation Order. <br/><br/> Thanks,';
$attachPDF = PDF::loadView('emails.transaction_invoice', $templateData)->output();
$attachment = PostmarkAttachment::fromRawData($attachPDF , "transaction_invoice.pdf", "application/pdf");
$sendEmail = $client->sendEmail($from, $email_id, $htmlBody, NULL, true, NULL, NULL, NULL, NULL, [$attachPDF]);
But it gives me error like:
local.ERROR: Critical Error : base64_encode() expects parameter 1 to be string, object given
If i remove $attachment
then its send an mail without attachment, but not working for attachment!
Any help will be appreciated!
Thanks.
This is my code below, basically its sending to itself. but I need to attach a reply-to on the email on the contact form.
$reply_to_email = "[email protected]";
$client = new PostmarkClient(12312312);
$sendResult = $client->sendEmail(POSTMARK_EMAIL_FROM,
POSTMARK_EMAIL_FROM,
$postmark_subject,
$postmark_message);
Calling sendEmailWithTemplate()
with an empty model (eg array()
, null
, etc) fails with a Received valid, but incompatible JSON input
error.
Would be nice if empty models were removed from the request. The error is kinda misleading as the JSON isn't actually invalid.
At the moment I'm just sending a template model of array('empty' => '')
to get around the error as there doesn't seem to be a way to send an empty model?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.