-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
Nette Mail: Sending E-mails | ||
=========================== | ||
[![Nette Mail](https://github.com/nette/mail/assets/194960/8b2371bd-0976-443c-b60a-460eb8b3222f)](https://doc.nette.org/en/mail) | ||
|
||
[![Downloads this Month](https://img.shields.io/packagist/dm/nette/mail.svg)](https://packagist.org/packages/nette/mail) | ||
[![Tests](https://github.com/nette/mail/workflows/Tests/badge.svg?branch=master)](https://github.com/nette/mail/actions) | ||
[![Coverage Status](https://coveralls.io/repos/github/nette/mail/badge.svg?branch=master)](https://coveralls.io/github/nette/mail?branch=master) | ||
[![Latest Stable Version](https://poser.pugx.org/nette/mail/v/stable)](https://github.com/nette/mail/releases) | ||
[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/nette/mail/blob/master/license.md) | ||
|
||
<!----> | ||
|
||
|
||
Introduction | ||
------------ | ||
|
||
Are you going to send emails such as newsletters or order confirmations? Nette Framework provides the necessary tools with a very nice API. | ||
|
||
Documentation can be found on the [website](https://doc.nette.org/mailing). | ||
Documentation can be found on the [website](https://doc.nette.org/en/mail). | ||
|
||
<!----> | ||
|
||
|
||
[Support Me](https://github.com/sponsors/dg) | ||
|
@@ -25,6 +28,8 @@ Do you like Nette Mail? Are you looking forward to the new features? | |
|
||
Thank you! | ||
|
||
<!----> | ||
|
||
|
||
Installation | ||
------------ | ||
|
@@ -35,6 +40,8 @@ composer require nette/mail | |
|
||
It requires PHP version 8.0 and supports PHP up to 8.3. | ||
|
||
<!----> | ||
|
||
|
||
Creating Emails | ||
=============== | ||
|
@@ -74,7 +81,7 @@ Images can also be extremely easily inserted into the HTML body of an email. Jus | |
// automatically adds /path/to/images/background.gif to the email | ||
$mail->setHtmlBody( | ||
'<b>Hello</b> <img src="background.gif">', | ||
'/path/to/images' | ||
'/path/to/images', | ||
); | ||
``` | ||
|
||
|
@@ -118,14 +125,14 @@ $mail = new Nette\Mail\Message; | |
$mail->setFrom('John <john@example.com>') | ||
->addTo('[email protected]') | ||
->setHtmlBody( | ||
$latte->renderToString('email.latte', $params), | ||
'/path/to/images' | ||
$latte->renderToString('/path/to/email.latte', $params), | ||
'/path/to/images', | ||
); | ||
``` | ||
|
||
File `email.latte`: | ||
|
||
```html | ||
```latte | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
|
@@ -146,6 +153,7 @@ File `email.latte`: | |
|
||
Nette automatically inserts all images, sets the subject according to the `<title>` element, and generates text alternative for HTML body. | ||
|
||
<!----> | ||
|
||
|
||
Sending Emails | ||
|
@@ -174,22 +182,22 @@ SmtpMailer | |
To send mail via the SMTP server, use `SmtpMailer`. | ||
|
||
```php | ||
$mailer = new Nette\Mail\SmtpMailer([ | ||
'host' => 'smtp.gmail.com', | ||
'username' => '[email protected]', | ||
'password' => '*****', | ||
'secure' => 'ssl', | ||
]); | ||
$mailer = new Nette\Mail\SmtpMailer( | ||
host: 'smtp.gmail.com', | ||
username: '[email protected]', | ||
password: '*****', | ||
encryption: Nette\Mail\SmtpMailer::EncryptionSSL, | ||
); | ||
$mailer->send($mail); | ||
``` | ||
|
||
If you do not specify `host`, the value from php.ini will be used. The following additional keys can be used in the options: | ||
The following additional parameters can be passed to the constructor: | ||
|
||
* `port` - if not set, the default 25 or 465 for `ssl` will be used | ||
* `context` - allows you to set [SSL context options](https://www.php.net/manual/en/context.ssl.php) for connection | ||
* `timeout` - timeout for SMTP connection | ||
* `persistent` - use persistent connection | ||
* `clientHost` - client designation | ||
* `streamOptions` - allows you to set [SSL context options](https://www.php.net/manual/en/context.ssl.php) for connection | ||
|
||
|
||
FallbackMailer | ||
|
@@ -201,13 +209,15 @@ It does not send email but sends them through a set of mailers. If one mailer fa | |
$mailer = new Nette\Mail\FallbackMailer([ | ||
$smtpMailer, | ||
$backupSmtpMailer, | ||
$sendmailMailer | ||
$sendmailMailer, | ||
]); | ||
$mailer->send($mail); | ||
``` | ||
|
||
Other parameters in the constructor include the number of repeat and waiting time in miliseconds. | ||
Other parameters in the constructor include the number of repeat and waiting time in milliseconds. | ||
|
||
|
||
<!----> | ||
|
||
DKIM | ||
==== | ||
|
@@ -216,14 +226,14 @@ DKIM (DomainKeys Identified Mail) is a trustworthy email technology that also he | |
The 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. | ||
|
||
```php | ||
$options = [ | ||
'domain' => 'nette.org', | ||
'selector' => 'dkim', | ||
'privateKey' => file_get_contents('../dkim/dkim.key'), | ||
'passPhrase' => '****', | ||
]; | ||
$signer = new Nette\Mail\DkimSigner( | ||
domain: 'nette.org', | ||
selector: 'dkim', | ||
privateKey: file_get_contents('../dkim/dkim.key'), | ||
passPhrase: '****', | ||
); | ||
|
||
$mailer = new Nette\Mail\SendmailMailer; // or SmtpMailer | ||
$mailer->setSigner(new Nette\Mail\DkimSigner($options)); | ||
$mailer->setSigner($signer); | ||
$mailer->send($mail); | ||
``` |