dietercoopman/mailspfchecker

A package to check if you can send e-mail through a given mailserver in name of a given e-mail address

v1.0.6 2024-03-12 20:47 UTC

README

showsql

Latest Version on Packagist Total Downloads

A Laravel package to check if you can send e-mail through a given mailserver in name of a given e-mail address

Mail spf checker

A Laravel package to check if your application can send e-mail in name of a given address.

Use case

Most of the web applications are sending mails. Mostly through a local mail server or an external mailing service.
When sending in name of a domain without using the legitimate mailserver of the domain it can get tricky.
Most of the time your mail ends up in a spam folder. This can be solved by configuring a correct SPF record for the domain you are sending with. This package gives you the possibility to check if you can send with a given from address using the mailserver specified in your mail config or a given mailserver. It also gives the possibility to retrieve a dns txt record to configure your dns.

Compatibility

This package can be installed in Laravel 6,7,8,9 and 10

Installation

composer require dietercoopman/mailspfchecker

Examples

Using the mailserver used by your application

    if ($mailSpfChecker->canISendAs("hello@dietse.dev")) {
        // the happy path
    } else {
        // you can not send e-mail in name of hello@dietse.dev, but I can tell you what to do  
        echo $mailSpfChecker->howCanISendAs("hello@dietse.be");
        // Generate a txt-record with a name of dietse.dev and the value v=spf1 ip4:#.#.#.# -all
    }

Using a given mailserver

    if ($mailSpfChecker->using('smtp.mandrill.com')->canISendAs("hello@dietse.dev")) {
        // the happy path
    } else {
        // you can not send e-mail in name of hello@dietse.dev, but I can tell you what to do  
        echo $mailSpfChecker->using('smtp.mandrill.com')->howCanISendAs("hello@dietse.be");
        // Generate a txt-record with a name of dietse.dev and the value v=spf1 ip4:spf.mandrill.com -all
    }

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.