Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dietercoopman/mailspfchecker
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.2
Choose a base ref
...
head repository: dietercoopman/mailspfchecker
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
Showing with 41 additions and 29 deletions.
  1. +1 −1 .github/workflows/dependabot-auto-merge.yml
  2. +3 −3 .github/workflows/fix-php-code-style-issues.yml
  3. +2 −2 .github/workflows/phpstan.yml
  4. +16 −3 .github/workflows/run-tests.yml
  5. +3 −5 README.md
  6. +4 −5 composer.json
  7. +12 −10 src/Mailspfchecker.php
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ jobs:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.3.3
uses: dependabot/fetch-metadata@v1.6.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

6 changes: 3 additions & 3 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
@@ -8,14 +8,14 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@1.0.0
uses: aglipanci/laravel-pint-action@2.4

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix styling
4 changes: 2 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ jobs:
name: phpstan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
@@ -20,7 +20,7 @@ jobs:
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v2

- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github
19 changes: 16 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -13,18 +13,31 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.1]
laravel: [9.*]
php: [ 8.2,8.1,8.0, 7.4 ]
laravel: [8.*,9.*,10*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
- laravel: 8.*
testbench: 6.*
exclude:
- laravel: 10.*
php: 8.0
- laravel: 10.*
php: 7.4
- laravel: 9.*
php: 7.4
- laravel: 8.*
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
![showsql](https://banners.beyondco.de/mailspfchecker.png?theme=light&packageManager=composer+require&packageName=dietercoopman%2Fmailspfchecker&pattern=architect&style=style_1&description=A+Laravel+package+to+check+if+your+application+can+send+e-mail+in+name+of+a+given+address.&md=1&showWatermark=1&fontSize=100px&images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg)

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

[![Latest Version on Packagist](https://img.shields.io/packagist/v/dietercoopman/mailspfchecker.svg?style=flat-square)](https://packagist.org/packages/dietercoopman/mailspfchecker)
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/dietercoopman/mailspfchecker/run-tests?label=tests)](https://github.com/dietercoopman/mailspfchecker/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/dietercoopman/mailspfchecker/Fix%20PHP%20code%20style%20issues?label=code%20style)](https://github.com/dietercoopman/mailspfchecker/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/dietercoopman/mailspfchecker.svg?style=flat-square)](https://packagist.org/packages/dietercoopman/mailspfchecker)

# 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.
@@ -21,7 +19,7 @@ or a given mailserver. It also gives the possibility to retrieve a dns txt reco

## Compatibility

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

## Installation

9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -16,22 +16,21 @@
}
],
"require": {
"php": "^7.4|^8.0|^8.1",
"illuminate/contracts": "^9.0",
"php": "^8.0|^8.1",
"illuminate/contracts": "^8.0|^9.0|^10|^11.0|^12.0",
"mlocati/spf-lib": "^3.1",
"spatie/laravel-package-tools": "^1.9.2"
},
"require-dev": {
"laravel/pint": "^1.1",
"nunomaduro/collision": "^6.0",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^7.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"orchestra/testbench": "^6.15"
},
"autoload": {
"psr-4": {
22 changes: 12 additions & 10 deletions src/Mailspfchecker.php
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ private function getDomain(string $emailOrDomain): string
public function check(string $emailOrDomain, $returnCode = false): mixed
{
$domain = $this->getDomain($emailOrDomain);
$decoder = new \SPFLib\Decoder();
$decoder = new \SPFLib\Decoder;

$code = 'error';
$codes = [];
@@ -81,7 +81,7 @@ private function setSendingMailServer(): void
$sendingMailserver = config('mail.mailers.smtp.host');
}

//if the address is localhost, then check wan address via icanhazip
// if the address is localhost, then check wan address via icanhazip
if ($sendingMailserver == '127.0.0.1' || $sendingMailserver == 'localhost') {
$sendingMailserver = trim(file_get_contents('https://icanhazip.com/'));
}
@@ -96,17 +96,19 @@ private function retreiveSpfRecordsFromSendingServer(): array
$server = $this->sendingMailserver;

if (! filter_var($server, FILTER_VALIDATE_IP)) {
$checker = new Decoder();
$checker = new Decoder;
$explodedServerUrl = explode('.', $server);
array_shift($explodedServerUrl);
$domain = implode('.', $explodedServerUrl);
if ($domain) {
$record = $checker->getRecordFromDomain($domain);
foreach ($record->getTerms() as $term) {
if ($term instanceof Mechanism\IncludeMechanism || $term instanceof Mechanism\AMechanism) {
$domainSpec = (string) $term->getDomainSpec();
if (strstr($domainSpec, $domain)) {
$spfRecords[] = $domainSpec;
if ($record) {
foreach ($record->getTerms() as $term) {
if ($term instanceof Mechanism\IncludeMechanism || $term instanceof Mechanism\AMechanism) {
$domainSpec = (string) $term->getDomainSpec();
if (strstr($domainSpec, $domain)) {
$spfRecords[] = $domainSpec;
}
}
}
}
@@ -116,7 +118,7 @@ private function retreiveSpfRecordsFromSendingServer(): array
return array_unique($spfRecords);
}

public function howCanISendAs(string $emailOrDomain, string $overRuleMessage = null): string
public function howCanISendAs(string $emailOrDomain, ?string $overRuleMessage = null): string
{
[$name, $value] = array_values($this->buildDnsString($emailOrDomain));
if ($overRuleMessage) {
@@ -129,7 +131,7 @@ public function howCanISendAs(string $emailOrDomain, string $overRuleMessage = n
public function buildDnsString(string $emailOrDomain): array
{
$domain = $this->getDomain($emailOrDomain);
$record = new \SPFLib\Record();
$record = new \SPFLib\Record;
if (! empty($this->spfRecords)) {
foreach ($this->spfRecords as $server) {
if (filter_var($server, FILTER_VALIDATE_IP)) {