-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
33 lines (27 loc) · 1.24 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
require __DIR__ . '/vendor/autoload.php';
use Pulli\Mime\Crypto\PGPEncrypter;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
$email = (new Email())
->from(new Address('[email protected]', 'PuLLi'))
->to(new Address('[email protected]', 'Fabien Potencier'))
->text("Hello there!\n\nHow are you?")
->subject('PGP Mail')
->attachFromPath('SomeFile.pdf');
$transport = Transport::fromDsn('valid_dsn');
$mailer = new Mailer($transport);
$pgpEncryptor = new PGPEncrypter();
// only needed if you have more than one key belonging to the from-email address
$pgpEncryptor->signingKey('key_identifier');
// method arguments: Message $message, string $passphrase, bool $attachKey
$messageSigned = $pgpEncryptor->sign($email, 'signing_key_passphrase', true);
// method arguments: Message $message, string $passphrase, bool $attachKey
$messageEncryptedAndSigned = $pgpEncryptor->encryptAndSign($email, 'signing_key_passphrase', true);
// method arguments: Message $message, bool $attachKey
$messageEncrypted = $pgpEncryptor->encrypt($email, true);
$mailer->send($messageSigned);
$mailer->send($messageEncryptedAndSigned);
$mailer->send($messageEncrypted);