{"id":18929463,"url":"https://github.com/thecodingmachine/utils.mailer.mail-interface","last_synced_at":"2025-07-10T02:38:31.324Z","repository":{"id":8440149,"uuid":"10031152","full_name":"thecodingmachine/utils.mailer.mail-interface","owner":"thecodingmachine","description":"This package contains interfaces and classes describing mails. It also contains the MailerService interface that should be implemented by any service that can send mails. You should use a package implementing this interface (like the SmtpMailer package.","archived":false,"fork":false,"pushed_at":"2018-05-03T13:20:35.000Z","size":23,"stargazers_count":0,"open_issues_count":2,"forks_count":5,"subscribers_count":13,"default_branch":"2.2","last_synced_at":"2025-06-30T03:09:39.707Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thecodingmachine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-13T12:31:35.000Z","updated_at":"2015-02-10T12:57:28.000Z","dependencies_parsed_at":"2022-08-23T12:20:26.141Z","dependency_job_id":null,"html_url":"https://github.com/thecodingmachine/utils.mailer.mail-interface","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/thecodingmachine/utils.mailer.mail-interface","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.mail-interface","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.mail-interface/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.mail-interface/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.mail-interface/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thecodingmachine","download_url":"https://codeload.github.com/thecodingmachine/utils.mailer.mail-interface/tar.gz/refs/heads/2.2","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.mail-interface/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264519719,"owners_count":23621858,"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-08T11:32:52.032Z","updated_at":"2025-07-10T02:38:31.025Z","avatar_url":"https://github.com/thecodingmachine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://poser.pugx.org/mouf/utils.mailer.mail-interface/v/stable.svg)](https://packagist.org/packages/mouf/utils.mailer.mail-interface)\n[![Latest Unstable Version](https://poser.pugx.org/mouf/utils.mailer.mail-interface/v/unstable.svg)](https://packagist.org/packages/mouf/utils.mailer.mail-interface)\n[![License](https://poser.pugx.org/mouf/utils.mailer.mail-interface/license.svg)](https://packagist.org/packages/mouf/utils.mailer.mail-interface)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/thecodingmachine/utils.mailer.mail-interface/badges/quality-score.png?b=2.0)](https://scrutinizer-ci.com/g/thecodingmachine/utils.mailer.mail-interface/?branch=2.1)\n\nMouf Mail system\n================\n\nThe Mouf framework is only an IOC framework. As such, it does not provide any means for managing any kind of cache. Hopefully,\nthe Mouf team provides also a range of packages to manage sending mails.\n\nThe mail architecture\n---------------------\n\nIn Mouf, \u003cem\u003eemails\u003c/em\u003e are sent using \u003cem\u003eMailServices\u003c/em\u003e.\u003cbr/\u003e\nMouf provides 4 implementations of mail services. You can provide your own if you want.\n\n\nBy default, Mouf provides these 3 implementations:\n\n- [**SwiftMailService**](http://mouf-php.com/packages/mouf/utils.mailer.swift-mail-service/README.md): a mail service that uses a SMTP server to send mails (this is a wrapper using the Swift mail library).\n- [**SmtpMailService**](http://mouf-php.com/packages/mouf/utils.mailer.smtp-mail-service/README.md): a mail service that uses a SMTP server to send mails (this is a wrapper using the Zend_Mail library).\n- [**DBMailService**](http://mouf-php.com/packages/mouf/utils.mailer.db-mail-service/README.md): a mail service that does not send any mails. Instead, it writes the mail in a MySQL database. It \n  can forward the mail later to another mail service that will actually send the mail. This mail server is available in the \n  package \u003cem\u003eutils/mailer/db-mail-service\u003c/em\u003e.\n\n\nEach mail service must extend the \u003ccode\u003eMailServiceInterface\u003c/code\u003e interface that is part of the\npackage utils/mailer/mail-interface.\n\nThe mail service interface\n--------------------------\n\nEach class implementing the \u003ccode\u003eMailServiceInterface\u003c/code\u003e provides one simple method to send mails:\n```php\ninterface MailServiceInterface {\n\t\n\t/**\n\t * Sends the mail passed in parameter.\n\t *\n\t * @param MailInterface $mail The mail to send.\n\t */\n\tfunction send(MailInterface $mail);\n}\n```\n\nThe mail passed in parameter must implement the \u003ccode\u003eMailInterface\u003c/code\u003e interface. Hopefully, Mouf provides a \u003ccode\u003eMail\u003c/code\u003e class\nthat does just that!\n\nFor instance, to send a mail, you just need to write:\n\n```php\n$mailService = Mouf::getSmtpMailService();\n\n$mail = new Mail();\n$mail-\u003esetBodyText(\"This is my mail!\");\n$mail-\u003esetBodyHtml(\"This is my \u0026lt;b\u0026gt;mail\u0026lt;/b\u0026gt;!\");\n$mail-\u003esetFrom(new MailAddress(\"my@server.com\", \"Server\"));\n$mail-\u003eaddToRecipient(new MailAddress(\"david@email.com\", \"David\"));\n$mail-\u003esetTitle(\"My mail\");\n\n$mailService-\u003esend($mail);\n```\n\nThe code above assumes that you configured an instance in Mouf called \"smtpMailService\".\n\nThe \u003ccode\u003eMailInterface\u003c/code\u003e interface supports:\n\n- Text/Html mails (\u003ccode\u003esetBodyText\u003c/code\u003e and \u003ccode\u003esetBodyHtml\u003c/code\u003e methods)\n- Multiple recipients (\u003ccode\u003eaddToRecipient\u003c/code\u003e method)\n- Multiple Cc recipients (\u003ccode\u003eaddCcRecipient\u003c/code\u003e method)\n- Multiple Bcc recipients (\u003ccode\u003eaddBccRecipient\u003c/code\u003e method)\n- File attachments (\u003ccode\u003eaddAttachment\u003c/code\u003e method)\n\nMail addresses are passed as a \u003ccode\u003eMailAddress\u003c/code\u003e object, that contains 2 strings: the mail address and the alias.\n\n\nAutomatic text body generation\n------------------------------\nWhen sending mails, it is a good practice to send 2 *bodies*: one in **plain text** and one in **HTML**.\nForget the **plain text** and your mail could be flagged as spam.\nHowever, most of the time, your users will look at the mail in HTML. Mail clients that can only read plain text\nare really rare those days. \n\nThe `Mail` class can help you here. Indeed, it will automatically generate the plain text version of your mail\nfrom the HTML, by stripping all tags.\n\n```php\n$mail = new Mail();\n$mail-\u003esetBodyHtml(\"This is my \u0026lt;b\u0026gt;mail\u0026lt;/b\u0026gt;!\");\n// No need to call $mail-\u003esetBodyText()\n```\n\nIf you want to explicitly disable the plain text generation you can call this method:\n\n```php\n$mail = new Mail();\n$mail-\u003esetBodyHtml(\"This is my \u0026lt;b\u0026gt;mail\u0026lt;/b\u0026gt;!\");\n// Disable plaing text generation from HTML. The mail will NOT contain the plain text part.\n$mail-\u003eautoCreateBodyText(false);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Futils.mailer.mail-interface","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecodingmachine%2Futils.mailer.mail-interface","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Futils.mailer.mail-interface/lists"}