{"id":21152105,"url":"https://github.com/mailjet/mailjet-apiv3-php-no-composer","last_synced_at":"2025-07-09T09:32:23.591Z","repository":{"id":37548752,"uuid":"52454384","full_name":"mailjet/mailjet-apiv3-php-no-composer","owner":"mailjet","description":"[API v3] Mailjet PHP Wrapper bundled with composer dependencies","archived":false,"fork":false,"pushed_at":"2023-04-19T18:27:26.000Z","size":18901,"stargazers_count":8,"open_issues_count":8,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-03-25T21:30:08.448Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mailjet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-24T15:53:55.000Z","updated_at":"2024-03-25T21:30:08.448Z","dependencies_parsed_at":"2022-08-26T15:30:53.057Z","dependency_job_id":null,"html_url":"https://github.com/mailjet/mailjet-apiv3-php-no-composer","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailjet%2Fmailjet-apiv3-php-no-composer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailjet%2Fmailjet-apiv3-php-no-composer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailjet%2Fmailjet-apiv3-php-no-composer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailjet%2Fmailjet-apiv3-php-no-composer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mailjet","download_url":"https://codeload.github.com/mailjet/mailjet-apiv3-php-no-composer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225532835,"owners_count":17484144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T10:24:50.021Z","updated_at":"2024-11-20T10:24:50.762Z","avatar_url":"https://github.com/mailjet.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[doc]: http://dev.mailjet.com/guides/?php#\n[api_credential]: https://app.mailjet.com/account/api_keys\n[mailjet]: http://www.mailjet.com\n\n![alt text](http://cdn.appstorm.net/web.appstorm.net/files/2012/02/mailjet_logo_200x200.png \"Mailjet\")\n\n[![Codacy Badge](https://api.codacy.com/project/badge/grade/3fa729f3750849ce8e0471b0487439cb)](https://www.codacy.com/app/gbadi/mailjet-apiv3-php)\n[![Build Status](https://travis-ci.org/mailjet/mailjet-apiv3-php.svg?branch=master)](https://travis-ci.org/mailjet/mailjet-apiv3-php)\n![MIT License](https://img.shields.io/badge/license-MIT-007EC7.svg?style=flat-square)\n![Current Version](https://img.shields.io/badge/version-1.1.8-green.svg)\n\n[Mailjet][mailjet] API Client.\n\nCheck out all the resources and all the PHP code examples on the official documentation: [Maijlet Documentation][doc]\n\n## Requirements\n\n`PHP \u003e= 7.2`\n\n## Installation\n\n``` bash\ncomposer require mailjet/mailjet-apiv3-php\n```\nWithout composer:\n\nClone or Download [this repository](https://github.com/mailjet/mailjet-apiv3-php-no-composer) that already contains all the dependencies and the `vendor/autoload.php` file. If you encounter any issue, please post it here and not on the mirror repository.\n\n### Authentication\n\nThe Mailjet Email API uses your API and Secret keys for authentication. [Grab][api_credential] and save your Mailjet API credentials.\n\n```bash\nexport MJ_APIKEY_PUBLIC='your API key'\nexport MJ_APIKEY_PRIVATE='your API secret'\n```\n\n\u003e Note: For the SMS API the authorization is based on a Bearer token. See information about it in the [SMS API](#sms-api) section of the readme.\n\nInitialize your [Mailjet][mailjet] Client:\n\n```php\nuse \\Mailjet\\Resources;\n\n// getenv will allow us to get the MJ_APIKEY_PUBLIC/PRIVATE variables we created before:\n\n$apikey = getenv('MJ_APIKEY_PUBLIC');\n$apisecret = getenv('MJ_APIKEY_PRIVATE');\n\n$mj = new \\Mailjet\\Client($apikey, $apisecret);\n\n// or, without using environment variables:\n\n$apikey = 'your API key';\n$apisecret = 'your API secret';\n\n$mj = new \\Mailjet\\Client($apikey, $apisecret);\n```\n\n### Make your first call\n\nHere's an example on how to send an email:\n\n```php\n\u003c?php\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n\n// Use your saved credentials, specify that you are using Send API v3.1\n\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'),true,['version' =\u003e 'v3.1']);\n\n// Define your request body\n\n$body = [\n    'Messages' =\u003e [\n        [\n            'From' =\u003e [\n                'Email' =\u003e \"$SENDER_EMAIL\",\n                'Name' =\u003e \"Me\"\n            ],\n            'To' =\u003e [\n                [\n                    'Email' =\u003e \"$RECIPIENT_EMAIL\",\n                    'Name' =\u003e \"You\"\n                ]\n            ],\n            'Subject' =\u003e \"My first Mailjet Email!\",\n            'TextPart' =\u003e \"Greetings from Mailjet!\",\n            'HTMLPart' =\u003e \"\u003ch3\u003eDear passenger 1, welcome to \u003ca href=\\\"https://www.mailjet.com/\\\"\u003eMailjet\u003c/a\u003e!\u003c/h3\u003e\n            \u003cbr /\u003eMay the delivery force be with you!\"\n        ]\n    ]\n];\n\n// All resources are located in the Resources class\n\n$response = $mj-\u003epost(Resources::$Email, ['body' =\u003e $body]);\n\n// Read the response\n\n$response-\u003esuccess() \u0026\u0026 var_dump($response-\u003egetData());\n?\u003e\n```\n\n## Client / Call Configuration Specifics\n\nTo instantiate the library you can use the following constructor:  \n\n`new \\Mailjet\\Client($MJ_APIKEY_PUBLIC, $MJ_APIKEY_PRIVATE,$CALL,$OPTIONS);`\n\n - `$MJ_APIKEY_PUBLIC` : public Mailjet API key\n - `$MJ_APIKEY_PRIVATE` : private Mailjet API key\n - `$CALL` : boolean to enable the API call to Mailjet API server (should be `true` to run the API call)\n - `$OPTIONS` : associative PHP array describing the connection options (see Options bellow for full list)\n\n### Options\n\n#### API Versioning\n\nThe Mailjet API is spread among three distinct versions:\n\n- `v3` - The Email API\n- `v3.1` - Email Send API v3.1, which is the latest version of our Send API\n- `v4` - SMS API\n\nSince most Email API endpoints are located under `v3`, it is set as the default one and does not need to be specified when making your request. For the others you need to specify the version using `version`. For example, if using Send API `v3.1`:\n\n```php\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'),true,['version' =\u003e 'v3.1']);\n```\n\nFor additional information refer to our [API Reference](https://dev.preprod.mailjet.com/reference/overview/versioning/).\n\n#### Base URL\n\nThe default base domain name for the Mailjet API is api.mailjet.com. You can modify this base URL by setting a value for `url` in your call:\n\n```php\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'),\n                          getenv('MJ_APIKEY_PRIVATE'), true,\n                          ['url' =\u003e \"api.us.mailjet.com\"]\n                        );\n```\n\nIf your account has been moved to Mailjet's US architecture, the URL value you need to set is `api.us.mailjet.com`.\n\n### Disable API call\n\nBy default the API call parameter is always enabled. However, you may want to disable it during testing to prevent unnecessary calls to the Mailjet API. This is done by setting the third parameter to `false`:\n\n```php\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'), false);\n```\n\n## List of resources\n\nYou can find the list of all available resources for this library in [/src/Mailjet/Resources.php](https://github.com/mailjet/mailjet-apiv3-php/blob/master/src/Mailjet/Resources.php). The file lists the names of the PHP resources and the corresponding names in the [API reference][ref].\n\n## Request Examples\n\n### POST Request\n\nUse the `post` method of the Mailjet CLient (i.e. `$mj-\u003epost($resource, $params)`)\n\n`$params` will be a PHP associative array with the following keys :\n\n - `body`: associative PHP array defining the object to create. The properties correspond to the property of the JSON Payload)\n - `id` : ID you want to apply a POST request to (used in case of action on a resource)\n\n#### Simple POST request\n\n```php\n\u003c?php\n/*\nCreate a new contact:\n*/\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));\n$body = [\n    'Email' =\u003e \"email@example.com\"\n];\n$response = $mj-\u003epost(Resources::$Contact, ['body' =\u003e $body]);\n$response-\u003esuccess() \u0026\u0026 var_dump($response-\u003egetData());?\u003e\n```\n\n#### Using actions\n\n```php\n\u003c?php\n/*\nManage the subscription status of a contact to multiple lists\n*/\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));\n$body = [\n    'ContactsLists' =\u003e [\n        [\n            'ListID' =\u003e \"$ListID_1\",\n            'Action' =\u003e \"addnoforce\"\n        ],\n        [\n            'ListID' =\u003e \"$ListID_2\",\n            'Action' =\u003e \"addforce\"\n        ]\n    ]\n];\n$response = $mj-\u003epost(Resources::$ContactManagecontactslists, ['id' =\u003e $id, 'body' =\u003e $body]);\n$response-\u003esuccess() \u0026\u0026 var_dump($response-\u003egetData());\n?\u003e\n```\n\n### GET Request\n\nUse the `get` method of the Mailjet CLient (i.e. `$mj-\u003eget($ressource, $params)`)\n\n`$param` will be a PHP associative array with the following keys :\n\n - `id` : Unique ID of the element you want to get (optional)\n - `filters`: associative array listing the query parameters you want to apply to your get (optional)\n\n#### Retrieve all objects\n\n```php\n\u003c?php\n/*\nRetrieve all contacts:\n*/\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));\n$response = $mj-\u003eget(Resources::$Contact);\n$response-\u003esuccess() \u0026\u0026 var_dump($response-\u003egetData());\n?\u003e\n```\n\n#### Use filtering\n\n```php\n\u003c?php\n/*\nRetrieve all contacts that are not in the campaign exclusion list :\n*/\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));\n$filters = [\n  'IsExcludedFromCampaigns' =\u003e 'false'\n];\n$response = $mj-\u003eget(Resources::$Contact, ['filters' =\u003e $filters]);\n$response-\u003esuccess() \u0026\u0026 var_dump($response-\u003egetData());\n?\u003e\n```\n\n#### Use paging and sorting\n\n```php\n\u003c?php\n/*\nRetrieve a specific contact ID :\n*/\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));\n$filters = [\n    'Limit'=\u003e40,  // default is 10, max is 1000\n    'Offset'=\u003e20,\n    'Sort'=\u003e'ArrivedAt DESC',\n    'Contact'=\u003e$contact-\u003eID,\n    'showSubject'=\u003etrue\n];\n$response = $mj-\u003eget(Resources::$Message, ['filters'=\u003e$filters]);\n$response-\u003esuccess() \u0026\u0026 var_dump($response-\u003egetData());\n?\u003e\n```\n\n#### Retrieve a single object\n\n```php\n\u003c?php\n/*\nRetrieve a specific contact ID :\n*/\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));\n$response = $mj-\u003eget(Resources::$Contact, ['id' =\u003e $id]);\n$response-\u003esuccess() \u0026\u0026 var_dump($response-\u003egetData());\n?\u003e\n```\n\n### PUT Request\n\nUse the `put` method of the Mailjet CLient (i.e. `$mj-\u003eput($ressource, $params)`)\n\n`$param` will be a PHP associative array with the following keys :\n\n - `id` : Unique ID of the element you want to modify\n - `body`: associative array representing the object property to update\n\nA `PUT` request in the Mailjet API will work as a `PATCH` request - the update will affect only the specified properties. The other properties of an existing resource will neither be modified, nor deleted. It also means that all non-mandatory properties can be omitted from your payload.\n\nHere's an example of a PUT request:\n\n```php\n\u003c?php\n/*\nUpdate the contact properties for a contact:\n*/\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));\n$body = [\n    'first_name' =\u003e \"John\",\n    'last_name' =\u003e \"Smith\"\n];\n$response = $mj-\u003eput(Resources::$ContactData, ['id' =\u003e $id, 'body' =\u003e $body]);\n$response-\u003esuccess() \u0026\u0026 var_dump($response-\u003egetData());\n?\u003e\n```\n\n### DELETE Request\n\nUse the `delete` method of the Mailjet CLient (i.e. `$mj-\u003edelete($ressource, $params)`)\n\nUpon a successful `DELETE` request the response will not include a response body, but only a `204 No Content` response code.\n\nHere's an example of a `DELETE` request:\n\n```php\n\u003c?php\n/*\nDelete an email template:\n*/\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));\n$response = $mj-\u003edelete(Resources::$Template, ['id' =\u003e $id]);\n$response-\u003esuccess() \u0026\u0026 var_dump($response-\u003egetData());\n?\u003e\n```\n\n### Response\n\nThe `get`, `post`, `put` and `delete` method will return a `Response` object with the following available methods:\n\n - `success()` : returns a boolean indicating if the API call was successful\n - `getStatus()` : http status code (ie: 200,400 ...)\n - `getData()` : content of the property `data` of the JSON response payload if exist or the full JSON payload returned by the API call. This will be PHP associative array.   \n - `getCount()` : number of elements returned in the response\n - `getReasonPhrase()` : http response message phrases (\"OK\", \"Bad Request\" ...)\n\n### API resources helpers\n\nAll API resources are listed in the `Resources` object. It will make it easy to find the resources and actions aliases.\n\n```\n$response = $mj-\u003edelete(Resources::$Template, ['id' =\u003e $id]);\n$response = $mj-\u003eput(Resources::$ContactData, ['id' =\u003e $id, 'body' =\u003e $body]);\n$response = $mj-\u003epost(Resources::$ContactManagecontactslists, ['id' =\u003e $id, 'body' =\u003e $body]);\n```\n\n## SMS API\n\n### Token Authentication\n\nAuthentication for the SMS API endpoints is done using a bearer token. The bearer token is generated in the [SMS section](https://app.mailjet.com/sms) of your Mailjet account.\n\nTo create a new instance of the Mailjet client with token authentication, the token should be provided as the first parameter, and the second must be NULL:\n\n```php\n$mj = new \\Mailjet\\Client(getenv('MJ_APITOKEN'),\n                          NULL, true,\n                          ['url' =\u003e \"api.mailjet.com\", 'version' =\u003e 'v4', 'call' =\u003e false]\n                        );\n```\n\n### Example Request\n\nHere's an example SMS API request:\n\n```php\n//Send an SMS\n$mj = new \\Mailjet\\Client(getenv('MJ_APITOKEN'),\n                          NULL, true,\n                          ['url' =\u003e \"api.mailjet.com\", 'version' =\u003e 'v4', 'call' =\u003e false]\n                        );\n$body = [\n    'Text' =\u003e \"Have a nice SMS flight with Mailjet !\",\n    'To' =\u003e \"+336000000000\",\n    'From' =\u003e \"MJ Pilot\",\n];\n$response = $mj-\u003epost(Resources::$SmsSend, ['body' =\u003e $body]);\n$response-\u003esuccess() \u0026\u0026 var_dump($response-\u003egetData());\n```\n\n## Contribute\n\nMailjet loves developers. You can be part of this project!\n\nThis wrapper is a great introduction to the open source world, check out the code!\n\nFeel free to ask anything, and contribute:\n\n- Fork the project.\n- Create a new branch.\n- Implement your feature or bug fix.\n- Add documentation to it.\n- Commit, push, open a pull request and voila.\n\nIf you have suggestions on how to improve the guides, please submit an issue in our [Official API Documentation repo](https://github.com/mailjet/api-documentation).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailjet%2Fmailjet-apiv3-php-no-composer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmailjet%2Fmailjet-apiv3-php-no-composer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailjet%2Fmailjet-apiv3-php-no-composer/lists"}