Support the ongoing development of →
posted 11 months ago
Laravel Mail
Last updated 10 months ago.

You can use simonschaufi/laravel-dkim tool with Laravel 9 compatibility. This tool use a custom mailer with dkim signature:

$signer = new DkimSigner(file_get_contents($privateKey), $domain, $selector, [], config('dkim.passphrase'));
$signedEmail = $signer->sign($message->getSymfonyMessage());
Last updated 11 months ago.

@rafadigreruiz here is the problem: emails are signed with DKIM with the package "simonschaufi/laravel-dkim" but shows "Your DKIM signature is not valid" - have you tried to test if this package is correctly signed with DKIM? Thanks!

Last updated 11 months ago.

@hostbrook yes, I'm tested the DKIM signature with Must be configured in your name server previously and not be used from local environment. You can generate the signature using tool. In addition, I'm tested the package sending emails from Laravel application.

Last updated 11 months ago.

Well, this is what I found. The package 'simonschaufi/laravel-dkim' works well and DKIM is valid only in case of email was built either with HTML or PLAIN TEXT template. In my case, all my emails have both HTML and PLAIN TEXT, because this is a good practice. For example, how I build a message:

class ContactForm extends Mailable

    public function build()
        return $this;

So, if you use both templates to build the email (what is the right way) you get an invalid DKIM signature. Actually, SWIFT mailer at Laravel 8 didn't have this issue.

Next, I have dug this issue with Symfony mailer and found the possible way on how to fix it, here:

Hopefully authors of 'simonschaufi/laravel-dkim' package can modify it and fix the issue.

P.S. Actually, if DKIM valid or not - you can check it even from the local environment. I used to check outgoing emails for local environment and in case if email built from either one HTML or TEXT template - there no problem, it shows DKIM is valid.


Hi @hostbrook there is a way to make dkim signature in the emails without using any tool as your first example:

class ContactForm extends Mailable
    use Queueable, SerializesModels;

    public $mailData;

    public function __construct($mailData)
        $this->mailData = $mailData;

    public function build()
        $mailData = $this->mailData;

        $htmlView = '';
        $plainView = '';

        $htmlEmail = view($htmlView, compact('mailData'))->render();
        $plainEmail = view($plainView, compact('mailData'))->render();

        return $this->subject($this->mailData['subject'])
            ->withSymfonyMessage(function (Email $message) use ($htmlEmail, $plainEmail) {

                $signer = new DkimSigner(

                $signedEmail = $signer->sign($message);


By this way, you can customize the dkim signature implementation as you like to prevent the Symfony mailer issue when sending with html and text parts.

Solution selected by @hostbrook

This is exactly the answer I was looking for. But the same problem I described in this thread above: the solution doesn't work if the email is built with both HTML and plain text. In this case, the email is signed with DKIM but the signature is not valid. But if the email is built either with HTML or Plain text only - this solution works. Symfony team needs to fix the issue with the DKIM signer or Laravel team needs to find a way how to bypass the issue in the Symfony mailer.


Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.