Symfony Mailer - Encrypted Messages?
cross-posted from: https://lemmy.world/post/48266338
I am learning how to use Symfony Mailer and am a bit lost on the encrypting message section.
This is my simple code below which works in sending the email.
<?php require 'vendor/autoload.php'; const FROM = '[email protected]'; const TO = '[email protected]'; const SUBJECT = 'My Subject'; const MESSAGE = 'Hello World'; const DSN = 'smtp://localhost:1025'; $transport = \Symfony\Component\Mailer\Transport::fromDsn(DSN); $mailer = new \Symfony\Component\Mailer\Mailer($transport); $email = (new \Symfony\Component\Mime\Email()) ->from(FROM) ->to(TO) ->subject(SUBJECT) ->text(MESSAGE); $encrypter = new \Symfony\Component\Mime\Crypto\SMimeEncrypter('my-certificate.crt'); $encryptedEmail = $encrypter->encrypt($email); try { $mailer->send($encryptedEmail); } catch (\Symfony\Component\Mailer\Exception\TransportExceptionInterface $error) { echo 'Unable to send email' . PHP_EOL; }And this is how I generated the certificate and key...
openssl genrsa -aes256 -out my-certificate.key 4096 openssl req -new -x509 -days 29220 -key my-certificate.key -out my-certificate.crtI am able to receive the email using SMTP tools like Mailpit.
My two questions are...
- My emails are encrypted using the certificate, but shouldn't it be done using PGP?
- How do I decrypt the email with SMTP testing tool or any online or CLI tool? I tried to decrypt the email and could not decrypt it even though I have all of the keys.
Take the State of PHP Survey
The @ThePHPF Survey for 2026 is on: take a moment to ask yourself important #PHP questions, and contribute your observation with the community and the fundation.
https://thephp.foundation/blog/2026/06/09/help-shape-the-future-of-php/Open linkView original on lemmy.world







![[RFC] [Discussion] Literal Scalar Types](https://lemmy.world/pictrs/image/d2029491-0e72-4bea-81ac-5da3b2f7c8af.png)





