{"id":13705319,"url":"https://github.com/nette/mail","last_synced_at":"2025-05-15T00:07:17.581Z","repository":{"id":14969112,"uuid":"17694037","full_name":"nette/mail","owner":"nette","description":"A handy library for creating and sending emails in PHP","archived":false,"fork":false,"pushed_at":"2024-10-05T03:15:42.000Z","size":463,"stargazers_count":478,"open_issues_count":9,"forks_count":71,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-05-03T20:35:44.860Z","etag":null,"topics":["html","mail","mailer","nette","nette-framework","php"],"latest_commit_sha":null,"homepage":"https://doc.nette.org/mailing","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nette.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"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},"funding":{"github":"dg","custom":"https://nette.org/donate"}},"created_at":"2014-03-13T03:46:38.000Z","updated_at":"2025-04-29T21:16:41.000Z","dependencies_parsed_at":"2024-04-29T12:27:14.710Z","dependency_job_id":"b04cf480-6497-4532-8bbc-dbd93ca89788","html_url":"https://github.com/nette/mail","commit_stats":{"total_commits":357,"total_committers":38,"mean_commits":9.394736842105264,"dds":"0.15966386554621848","last_synced_commit":"7d582f1ce5485f933e8298b2d2f2ff15298f18be"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nette%2Fmail","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nette%2Fmail/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nette%2Fmail/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nette%2Fmail/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nette","download_url":"https://codeload.github.com/nette/mail/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253411566,"owners_count":21904151,"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":["html","mail","mailer","nette","nette-framework","php"],"created_at":"2024-08-02T22:00:37.226Z","updated_at":"2025-05-15T00:07:12.570Z","avatar_url":"https://github.com/nette.png","language":"PHP","readme":"[![Nette Mail](https://github.com/nette/mail/assets/194960/8b2371bd-0976-443c-b60a-460eb8b3222f)](https://doc.nette.org/en/mail)\n\n[![Downloads this Month](https://img.shields.io/packagist/dm/nette/mail.svg)](https://packagist.org/packages/nette/mail)\n[![Tests](https://github.com/nette/mail/workflows/Tests/badge.svg?branch=master)](https://github.com/nette/mail/actions)\n[![Coverage Status](https://coveralls.io/repos/github/nette/mail/badge.svg?branch=master)](https://coveralls.io/github/nette/mail?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/nette/mail/v/stable)](https://github.com/nette/mail/releases)\n[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/nette/mail/blob/master/license.md)\n\n \u003c!----\u003e\n\n\nIntroduction\n------------\n\nAre you going to send emails such as newsletters or order confirmations? Nette Framework provides the necessary tools with a very nice API.\n\nDocumentation can be found on the [website](https://doc.nette.org/en/mail).\n\n \u003c!----\u003e\n\n\n[Support Me](https://github.com/sponsors/dg)\n--------------------------------------------\n\nDo you like Nette Mail? Are you looking forward to the new features?\n\n[![Buy me a coffee](https://files.nette.org/icons/donation-3.svg)](https://github.com/sponsors/dg)\n\nThank you!\n\n \u003c!----\u003e\n\n\nInstallation\n------------\n\n```shell\ncomposer require nette/mail\n```\n\nIt requires PHP version 8.0 and supports PHP up to 8.4.\n\n \u003c!----\u003e\n\n\nCreating Emails\n===============\n\nEmail is a [Nette\\Mail\\Message](https://api.nette.org/3.0/Nette/Mail/Message.html) object:\n\n```php\n$mail = new Nette\\Mail\\Message;\n$mail-\u003esetFrom('John \u003cjohn@example.com\u003e')\n\t-\u003eaddTo('peter@example.com')\n\t-\u003eaddTo('jack@example.com')\n\t-\u003esetSubject('Order Confirmation')\n\t-\u003esetBody(\"Hello, Your order has been accepted.\");\n```\n\nAll parameters must be encoded in UTF-8.\n\nIn addition to specifying recipients with the `addTo()` method, you can also specify the recipient of copy with `addCc()`, or the recipient of blind copy with `addBcc()`. All these methods, including `setFrom()`, accepts addressee in three ways:\n\n```php\n$mail-\u003esetFrom('john.doe@example.com');\n$mail-\u003esetFrom('john.doe@example.com', 'John Doe');\n$mail-\u003esetFrom('John Doe \u003cjohn.doe@example.com\u003e');\n```\n\nThe body of an email written in HTML is passed using the `setHtmlBody()` method:\n\n```php\n$mail-\u003esetHtmlBody('\u003cp\u003eHello,\u003c/p\u003e\u003cp\u003eYour order has been accepted.\u003c/p\u003e');\n```\n\nYou don't have to create a text alternative, Nette will generate it automatically for you. And if the email does not have a subject set, it will be taken from the `\u003ctitle\u003e` element.\n\nImages can also be extremely easily inserted into the HTML body of an email. Just pass the path where the images are physically located as the second parameter, and Nette will automatically include them in the email:\n\n```php\n// automatically adds /path/to/images/background.gif to the email\n$mail-\u003esetHtmlBody(\n\t'\u003cb\u003eHello\u003c/b\u003e \u003cimg src=\"background.gif\"\u003e',\n\t'/path/to/images',\n);\n```\n\nThe image embedding algorithm supports the following patterns: `\u003cimg src=...\u003e`, `\u003cbody background=...\u003e`, `url(...)` inside the HTML attribute `style` and special syntax `[[...]]`.\n\nCan sending emails be even easier?\n\nEmails are like postcards. Never send passwords or other credentials via email.\n\n\n\nAttachments\n-----------\n\nYou can, of course, attach attachments to email. Use the `addAttachment(string $file, string $content = null, string $contentType = null)`.\n\n```php\n// inserts the file /path/to/example.zip into the email under the name example.zip\n$mail-\u003eaddAttachment('/path/to/example.zip');\n\n// inserts the file /path/to/example.zip into the email under the name info.zip\n$mail-\u003eaddAttachment('info.zip', file_get_contents('/path/to/example.zip'));\n\n// attaches new example.txt file contents \"Hello John!\"\n$mail-\u003eaddAttachment('example.txt', 'Hello John!');\n```\n\n\nTemplates\n---------\n\nIf you send HTML emails, it's a great idea to write them in the [Latte](https://latte.nette.org) template system. How to do it?\n\n```php\n$latte = new Latte\\Engine;\n$params = [\n\t'orderId' =\u003e 123,\n];\n\n$mail = new Nette\\Mail\\Message;\n$mail-\u003esetFrom('John \u003cjohn@example.com\u003e')\n\t-\u003eaddTo('jack@example.com')\n\t-\u003esetHtmlBody(\n\t\t$latte-\u003erenderToString('/path/to/email.latte', $params),\n\t\t'/path/to/images',\n\t);\n```\n\nFile `email.latte`:\n\n```latte\n\u003chtml\u003e\n\u003chead\u003e\n\t\u003cmeta charset=\"utf-8\"\u003e\n\t\u003ctitle\u003eOrder Confirmation\u003c/title\u003e\n\t\u003cstyle\u003e\n\tbody {\n\t\tbackground: url(\"background.png\")\n\t}\n\t\u003c/style\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\t\u003cp\u003eHello,\u003c/p\u003e\n\n\t\u003cp\u003eYour order number {$orderId} has been accepted.\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nNette automatically inserts all images, sets the subject according to the `\u003ctitle\u003e` element, and generates text alternative for HTML body.\n\n \u003c!----\u003e\n\n\nSending Emails\n==============\n\nMailer is class responsible for sending emails. It implements the [Nette\\Mail\\Mailer](https://api.nette.org/3.0/Nette/Mail/Mailer.html) interface and several ready-made mailers are available which we will introduce.\n\n\n\nSendmailMailer\n--------------\n\nThe default mailer is SendmailMailer which uses PHP function `mail()`. Example of use:\n\n```php\n$mailer = new Nette\\Mail\\SendmailMailer;\n$mailer-\u003esend($mail);\n```\n\nIf you want to set `returnPath` and the server still overwrites it, use `$mailer-\u003ecommandArgs = '-fmy@email.com'`.\n\n\nSmtpMailer\n----------\n\nTo send mail via the SMTP server, use `SmtpMailer`.\n\n```php\n$mailer = new Nette\\Mail\\SmtpMailer(\n\thost: 'smtp.gmail.com',\n\tusername: 'franta@gmail.com',\n\tpassword: '*****',\n\tencryption: Nette\\Mail\\SmtpMailer::EncryptionSSL,\n);\n$mailer-\u003esend($mail);\n```\n\nThe following additional parameters can be passed to the constructor:\n\n* `port` - if not set, the default 25 or 465 for `ssl` will be used\n* `timeout` - timeout for SMTP connection\n* `persistent` - use persistent connection\n* `clientHost` - client designation\n* `streamOptions` - allows you to set [SSL context options](https://www.php.net/manual/en/context.ssl.php) for connection\n\n\nFallbackMailer\n--------------\n\nIt does not send email but sends them through a set of mailers. If one mailer fails, it repeats the attempt at the next one. If the last one fails, it starts again from the first one.\n\n```php\n$mailer = new Nette\\Mail\\FallbackMailer([\n\t$smtpMailer,\n\t$backupSmtpMailer,\n\t$sendmailMailer,\n]);\n$mailer-\u003esend($mail);\n```\n\nOther parameters in the constructor include the number of repeat and waiting time in milliseconds.\n\n\n \u003c!----\u003e\n\nDKIM\n====\n\nDKIM (DomainKeys Identified Mail) is a trustworthy email technology that also helps detect spoofed messages. The sent message is signed with the private key of the sender's domain and this signature is stored in the email header.\nThe recipient's server compares this signature with the public key stored in the domain's DNS records. By matching the signature, it is shown that the email actually originated from the sender's domain and that the message was not modified during the transmission of the message.\n\n```php\n$signer = new Nette\\Mail\\DkimSigner(\n\tdomain: 'nette.org',\n\tselector: 'dkim',\n\tprivateKey: file_get_contents('../dkim/dkim.key'),\n\tpassPhrase: '****',\n);\n\n$mailer = new Nette\\Mail\\SendmailMailer; // or SmtpMailer\n$mailer-\u003esetSigner($signer);\n$mailer-\u003esend($mail);\n```\n","funding_links":["https://github.com/sponsors/dg","https://nette.org/donate"],"categories":["电子邮件 Email","Code","邮件( Email )"],"sub_categories":["Library"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnette%2Fmail","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnette%2Fmail","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnette%2Fmail/lists"}