{"id":19010281,"url":"https://github.com/railsware/mailtrap-php","last_synced_at":"2025-04-05T12:01:58.034Z","repository":{"id":110513943,"uuid":"604599155","full_name":"railsware/mailtrap-php","owner":"railsware","description":"The official mailtrap.io PHP client","archived":false,"fork":false,"pushed_at":"2025-01-27T09:07:02.000Z","size":209,"stargazers_count":38,"open_issues_count":1,"forks_count":8,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-03-29T11:03:29.563Z","etag":null,"topics":["email","mail","mailtrap-io","php"],"latest_commit_sha":null,"homepage":"https://mailtrap.io","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/railsware.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-21T12:00:53.000Z","updated_at":"2025-03-08T07:53:56.000Z","dependencies_parsed_at":"2024-03-19T14:48:01.716Z","dependency_job_id":"09a4f7a7-ab8a-4e61-bd6d-1966504fac42","html_url":"https://github.com/railsware/mailtrap-php","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsware%2Fmailtrap-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsware%2Fmailtrap-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsware%2Fmailtrap-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsware%2Fmailtrap-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/railsware","download_url":"https://codeload.github.com/railsware/mailtrap-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332556,"owners_count":20921853,"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":["email","mail","mailtrap-io","php"],"created_at":"2024-11-08T19:10:39.938Z","updated_at":"2025-04-05T12:01:58.018Z","avatar_url":"https://github.com/railsware.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Official Mailtrap PHP client\n===============\n![GitHub Actions](https://github.com/railsware/mailtrap-php/actions/workflows/ci-phpunit.yml/badge.svg)\n\n[![PHP version support](https://img.shields.io/packagist/dependency-v/railsware/mailtrap-php/php?style=flat)](https://packagist.org/packages/railsware/mailtrap-php)\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/railsware/mailtrap-php.svg?style=flat)](https://packagist.org/packages/railsware/mailtrap-php)\n[![Total Downloads](https://img.shields.io/packagist/dt/railsware/mailtrap-php.svg?style=flat)](https://packagist.org/packages/railsware/mailtrap-php)\n\n\n## Installation\nYou can install the package via [composer](http://getcomposer.org/)\n\nThe Mailtrap API Client is not hard coupled to Guzzle, React, Zend, Symfony HTTP or any other library that sends\nHTTP messages. Instead, it uses the [PSR-18](https://www.php-fig.org/psr/psr-18/) client abstraction.\n\nThis will give you the flexibility to choose what [HTTP client](https://docs.php-http.org/en/latest/clients.html) you want to use.\n\nIf you just want to get started quickly you should run one of the following command (depends on which HTTP client you want to use):\n```bash\n# With symfony http client (recommend)\ncomposer require railsware/mailtrap-php symfony/http-client nyholm/psr7\n\n# Or with guzzle http client\ncomposer require railsware/mailtrap-php guzzlehttp/guzzle php-http/guzzle7-adapter\n```\n\n## Usage\nYou should use Composer autoloader in your application to automatically load your dependencies. \n\nHere's how to send a message using the SDK:\n\n```php\n\u003c?php\n\nuse Mailtrap\\Helper\\ResponseHelper;\nuse Mailtrap\\MailtrapClient;\nuse Mailtrap\\Mime\\MailtrapEmail;\nuse Symfony\\Component\\Mime\\Address;\nuse Symfony\\Component\\Mime\\Email;\nuse Symfony\\Component\\Mime\\Header\\UnstructuredHeader;\n\nrequire __DIR__ . '/vendor/autoload.php';\n\n// Mailtrap SENDING client (real) for transactional emails\n$mailtrap = MailtrapClient::initSendingEmails(\n    apiKey: getenv('MAILTRAP_API_KEY') # your API token from here https://mailtrap.io/api-tokens\n);\n\n$email = (new MailtrapEmail())\n    -\u003efrom(new Address('example@your-domain-here.com', 'Mailtrap Test'))\n    -\u003ereplyTo(new Address('reply@your-domain-here.com'))\n    -\u003eto(new Address('email@example.com', 'Jon'))\n    -\u003epriority(Email::PRIORITY_HIGH)\n    -\u003ecc('mailtrapqa@example.com')\n    -\u003eaddCc('staging@example.com')\n    -\u003ebcc('mailtrapdev@example.com')\n    -\u003esubject('Best practices of building HTML emails')\n    -\u003etext('Hey! Learn the best practices of building HTML emails and play with ready-to-go templates. Mailtrap’s Guide on How to Build HTML Email is live on our blog')\n    -\u003ehtml(\n        '\u003chtml\u003e\n        \u003cbody\u003e\n        \u003cp\u003e\u003cbr\u003eHey\u003c/br\u003e\n        Learn the best practices of building HTML emails and play with ready-to-go templates.\u003c/p\u003e\n        \u003cp\u003e\u003ca href=\"https://mailtrap.io/blog/build-html-email/\"\u003eMailtrap’s Guide on How to Build HTML Email\u003c/a\u003e is live on our blog\u003c/p\u003e\n        \u003cimg src=\"cid:logo\"\u003e\n        \u003c/body\u003e\n    \u003c/html\u003e'\n    )\n    -\u003eembed(fopen('https://mailtrap.io/wp-content/uploads/2021/04/mailtrap-new-logo.svg', 'r'), 'logo', 'image/svg+xml')\n    -\u003ecategory('Integration Test')\n    -\u003ecustomVariables([\n        'user_id' =\u003e '45982',\n        'batch_id' =\u003e 'PSJ-12'\n    ])\n;\n\n// Custom email headers (optional)\n$email-\u003egetHeaders()\n    -\u003eaddTextHeader('X-Message-Source', 'domain.com')\n    -\u003eadd(new UnstructuredHeader('X-Mailer', 'Mailtrap PHP Client')) // the same as addTextHeader\n;\n\ntry {\n    $response = $mailtrap-\u003esend($email);\n\n    var_dump(ResponseHelper::toArray($response)); // body (array)\n} catch (Exception $e) {\n    echo 'Caught exception: ',  $e-\u003egetMessage(), \"\\n\";\n}\n\n\n// OR -\u003e Mailtrap BULK SENDING client (real)\ntry {\n    $mailtrapBulkSending = MailtrapClient::initSendingEmails(\n        apiKey: getenv('MAILTRAP_API_KEY'), # your API token from here https://mailtrap.io/api-tokens\n        isBulk: true # Bulk sending (@see https://help.mailtrap.io/article/113-sending-streams)\n    );\n\n    $response = $mailtrapBulkSending-\u003esend($email);\n\n    var_dump(ResponseHelper::toArray($response)); // body (array)\n} catch (Exception $e) {\n    echo 'Caught exception: ',  $e-\u003egetMessage(), \"\\n\";\n}\n\n// OR -\u003e Mailtrap Testing client (sandbox)\ntry {\n    $mailtrapTesting = MailtrapClient::initSendingEmails(\n        apiKey: getenv('MAILTRAP_API_KEY'), # your API token from here https://mailtrap.io/api-tokens\n        isSandbox: true, # Sandbox sending (@see https://help.mailtrap.io/article/109-getting-started-with-mailtrap-email-testing)\n        inboxId: getenv('MAILTRAP_INBOX_ID') # required param for sandbox sending\n    );\n\n    $response = $mailtrapTesting-\u003esend($email);\n\n    var_dump(ResponseHelper::toArray($response)); // body (array)\n} catch (Exception $e) {\n    echo 'Caught exception: ',  $e-\u003egetMessage(), \"\\n\";\n}\n\n```\n\n### All usage examples\n\nYou can find more examples [here](examples).\n* [General examples](examples/general)\n* [Testing examples](examples/testing)\n* [Sending examples](examples/sending)\n\n\n## Framework integration\n\nIf you are using a framework you might consider these composer packages to make the framework integration easier.\n\n* [Symfony](src/Bridge/Symfony)\n* [Laravel](src/Bridge/Laravel)\n\n## Contributing\n\nBug reports and pull requests are welcome on [GitHub](https://github.com/railsware/mailtrap-php). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).\n\n## License\n\nThe package is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Mailtrap project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frailsware%2Fmailtrap-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frailsware%2Fmailtrap-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frailsware%2Fmailtrap-php/lists"}