GithubHelp home page GithubHelp logo

activecampaign / postmark-php Goto Github PK

View Code? Open in Web Editor NEW
162.0 17.0 53.0 1.51 MB

The official PHP library for Postmark.

Home Page: https://postmarkapp.com

License: MIT License

PHP 100.00%
postmark postmark-integrations email mail

postmark-php's Introduction

Postmark-PHP

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.

Build Status

postmark-php's People

Contributors

anthonysterling avatar ashgibson avatar atheken avatar baci266 avatar balvig avatar camuthig avatar cnagele avatar ewood-ac avatar gayankalhara avatar intossh avatar jchoca avatar jhuggart avatar jpruiz114 avatar jxmallett avatar kevin-ryser avatar limenet avatar nickcanz avatar rtek avatar scott-davidjones avatar svycka avatar tomcastleman avatar tristanpouliquen avatar vdwijngaert avatar vladsandu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

postmark-php's Issues

Installation on Laravel 5.1 failed

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

Tests make live requests?

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.

feature request: override email subject when using sendEmailWithTemplate()

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?

How to get messageID from sendEmail?

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?

Instructions for testing

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.

Some attachments break JSON encoding

                                                                              
  [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.

Feature Request: Interfaces

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.

Batch function improvment

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?

how to set replyTo email?

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);

Sending multiple emails with a template

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?

API suggestions

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

  • Many instances of equality testing with null ($var != null) recommend using identity operators and explicit casting
  • Many instances of missing method visibility
  • Remove the trailing PHP tag for all classes as its not needed. Some classes already exclude it.

Support for PHP 5.3

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.

Sending a templated email with an empty model fails

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?

Setting custom Guzzle client tha wasn't instantiated with the correct 'base_url' option will cause all requests to fail

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.

How can i get my server token.

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

Sending Attachments. Error in examples.

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!

PostmarkException: Received valid, but incompatible JSON input

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)

New line in sendEmailWithTemplate function

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!

wildbit/postmark-php 1.3.2 requires guzzlehttp/guzzle ~5.1 -> no matching package found.

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!

Remove Guzzle dependency.

There are cases where the Guzzle dependency gets conflicted with users' other dependencies. Remove guzzle as a dependency from Postmark-PHP.

Error out of the box

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:

screen shot 2015-03-11 at 11 22 49 am

any interest in async behavior?

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.

Allow sending email with an "empty" template model.

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.

undefined function GuzzleHttp\Handler\curl_reset()

Hi,

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.

wildbit

Solving SSL issue when using autoload.php

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 ?

Requirement for GuzzleHttp

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?

Making a GET request to /templates/validate (getting template aliased 'validate') doesn't work.

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."
}

Where is the autoload.php?

I see 'require_once('./vendor/autoload.php');' but there is no 'vendor/autoload.php' in 'postmark-php-master' that I have downloaded.

local.ERROR: Critical Error : base64_encode() expects parameter 1 to be string, object given

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.

"Trying to access array offset"

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

Type mismatch

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.

Expose errors via wp_error filter.

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.

import into cakephp

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.