Coder Social home page Coder Social logo

Comments (10)

COil avatar COil commented on July 17, 2024 2

Don't json encode the values.

    $container = [];
    $email = ['name' => 'Loïc Vernet', 'email' => '[email protected]'];
    $container['textContent'] = 'Hello world !';
    $container['subject'] = 'SendinBlue test via V3 PHP API';
    $container['sender'] = new SendSmtpEmailSender($email);
    $container['replyTo'] = new SendSmtpEmailReplyTo($email);
    $container['to'] = [$email];
    $container['tags'] = ['test'];
    $sendSmtpEmail = new SendSmtpEmail($container);

    return $this->smtpApi->sendTransacEmail($sendSmtpEmail);

from apiv3-php-library.

vcopleutre avatar vcopleutre commented on July 17, 2024 1

AMEN.
For those who want to pass parameters in templates. The correct syntax is :

  1. Pass parameters in the form of array in PHP : ['VARIABLE' => 'test variable']
  2. Get the variable with {{ params.VARIABLE }}

DO NOT use % % in templates for parameters.

Note to sendinblue : I had to pass through hell just for that, finally finding the solution thanks to retrieving html templates with conditions on parameters and reading this : https://help.sendinblue.com/hc/fr/articles/360000591660

from apiv3-php-library.

vcopleutre avatar vcopleutre commented on July 17, 2024 1

Hi,

You're welcome !

For your second question, If I understand well, you want to use "contact" datas without creating a contact. I don't think it's possible unless passing the parameters like you said before params.FIRSTNAME. This is the way you're looking for since you want to get the firstname directly from your database.

Also for your information, I think that a contact may be automatically created by Sendinblue when you send an email but I don't know how does Sendinblue get the firstname and lastname in the automatic process.

from apiv3-php-library.

haterecoil avatar haterecoil commented on July 17, 2024

As reference for further investigation, here is something useful: https://github.com/sendgrid/sendgrid-php

from apiv3-php-library.

COil avatar COil commented on July 17, 2024

Sendgrid PHP API quality was also low some times ago, it's better now.

But +1 for the doc. For example for the sendtransacemail function doc :

$sendSmtpEmail = new \SendinBlue\Client\Model\SendSmtpEmail(); // \SendinBlue\Client\Model\SendSmtpEmail | Values to send a transactional email

try {
    $result = $apiInstance->sendTransacEmail($sendSmtpEmail);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling SMTPApi->sendTransacEmail: ', $e->getMessage(), PHP_EOL;
}

It's not real code as SendSmtpEmail is created without argument. Such a code leads to an error 400 :

Client error: `POST https://api.sendinblue.com/v3/smtp/email` resulted in a `400 Bad Request` response:
{"code":"missing_parameter","message":"No input in body"}

I had to figure out how to pass the to parameter as the documentation is no correct. In fact "Models" sometimes seem not to have to be used ! 🤔

from apiv3-php-library.

vcopleutre avatar vcopleutre commented on July 17, 2024

Hi @COil,

How did you pass the parameters (i'm fighting with json types that are refused by Sendinblue).

My current code :
$params[] = json_encode(array( 'TITLE' => 'testtitle', 'TITLE2' => 'testtitle' )); $sendSmtpEmail->setParams($params);

It doesn't work. Sendinblue log write :
"build template args: decode: json: cannot unmarshal array into Go struct field httpRequestTemplateArgs.params of type map[string]interface {}\n"

I'm stuck with it and i would love a little help. Btw I agree with the fact that documentation is very poor...

Thank you :-)

from apiv3-php-library.

vcopleutre avatar vcopleutre commented on July 17, 2024

Thank you very much !

Unfortunately I dont succeed in using my params in my template even without json_encoding.
%VARIABLE% is not replaced by my params set by $container['params'] = ['VARIABLE' => 'test variable']

I'm trying to reach the tech support

from apiv3-php-library.

boryn avatar boryn commented on July 17, 2024

Hi @vcopleutre! Your comment is a life-saver!

Did you maybe find out how to use {{ contact.FIRSTNAME }} "transactionally"? I mean I'd like to pass the user name on the fly from my database, without a necessity of creating a contact in Sendinblue. Is there any special way to pass the contact data or I just should use {{ params.FIRSTNAME }}?

from apiv3-php-library.

boryn avatar boryn commented on July 17, 2024

I went with the solution with {{ params.FIRSTNAME }} as I trust more data in my database than something automatically created by Sendinblue.

Another important thing: you cannot use hyphens '-' in the variable names. So {{ params.FIRST_NAME }} will work properly, but {{ params.FIRST-NAME }} will fail.

For those working in Laravel with Sendinblue, I have extended the https://github.com/agence-webup/laravel-sendinblue library for using the Sendinblue templates and transactional parameters (agence-webup/laravel-sendinblue#43).

from apiv3-php-library.

preetishishodia7 avatar preetishishodia7 commented on July 17, 2024

Hi,
Can you please tell, do you still face issues with the documentation part in order to use it, if yes can you please share where you are facing issues? So that we can check and improve it, as its an old thread we have changed a lot in our documentation from then.
Thanks!

from apiv3-php-library.

Related Issues (20)

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.