Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/php-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: PHP Tests

on:
push:
pull_request:

jobs:
test:
name: PHP ${{ matrix.php-version }}
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

strategy:
matrix:
php-version: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
max-parallel: 1

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Install Dependencies
run: composer install

- name: Run Tests
run: ./vendor/bin/phpunit --configuration phpunit.xml.dist --verbose
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.lock
.idea/
docs/
phpunit.xml
.phpunit.result.cache
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
}
],
"require": {
"php": ">=5.3.2",
"php": ">=5.4",
"psr/log": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~5.0",
"phpunit/phpunit": "~8.5",
"monolog/monolog": "~1.13"
},
"autoload": {
Expand All @@ -31,8 +31,8 @@
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
"psr-4": {
"Tx\\Mailer\\Tests\\": "tests/"
}
}
}
20 changes: 10 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.0/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./vendor/autoload.php"
Expand All @@ -18,16 +18,16 @@
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory suffix=".php">vendor</directory>
</blacklist>
<whitelist>
<exclude>
<directory suffix=".php">vendor</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log
type="coverage-html"
target="docs/report"
lowUpperBound="35"
highLowerBound="70"
/>
<log type="coverage-html"
target="docs/report"
lowUpperBound="35"
highLowerBound="70"/>
</logging>
</phpunit>
34 changes: 11 additions & 23 deletions src/Mailer/SMTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ public function __construct(LoggerInterface $logger=null)
* set server and port
* @param string $host server
* @param int $port port
* @param string $secure ssl tls tlsv1.0 tlsv1.1 tlsv1.2
* @param string $secure ssl tls
* @param bool $allowInsecure skip certificate verification?
* @return $this
*/
public function setServer($host, $port, $secure=null, $allowInsecure=null)
{
$this->host = $host;
$this->port = $port;
$this->secure = $secure;
$this->allowInsecure = $allowInsecure;
$this->allowInsecure = (bool) $allowInsecure;
if(!$this->ehlo) $this->ehlo = $host;
$this->logger && $this->logger->debug("Set: the server");
return $this;
Expand Down Expand Up @@ -204,7 +205,7 @@ protected function connect()
$this->logger && $this->logger->debug("Connecting to {$this->host} at {$this->port}");
$host = ($this->secure == 'ssl') ? 'ssl://' . $this->host : $this->host;
// Create connection
$context = null;
$context = stream_context_create([]);
if ($this->allowInsecure) {
$context = stream_context_create([
'ssl' => [
Expand All @@ -214,18 +215,16 @@ protected function connect()
]
]);
}
$this->smtp = stream_socket_client(
$this->smtp = @stream_socket_client(
$host.':'.$this->port,
$error_code,
$error_message,
ini_get('default_socket_timeout'),
STREAM_CLIENT_CONNECT,
$context
);
//set block mode
// stream_set_blocking($this->smtp, 1);
if (!$this->smtp){
throw new SMTPException("Could not open SMTP Port.");
throw new SMTPException("Could not open SMTP Port to $host:{$this->port}");
}
$code = $this->getCode();
if ($code !== '220'){
Expand Down Expand Up @@ -254,24 +253,13 @@ protected function starttls()
throw new CryptoException('Crypto type expected PHP 5.6 or greater');
}

switch ($this->secure) {
case 'tlsv1.0':
$crypto_type = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT;
break;
case 'tlsv1.1':
$crypto_type = STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
break;
case 'tlsv1.2':
$crypto_type = STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
break;
default:
$crypto_type = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT |
STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT |
STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
break;
if ($this->allowInsecure) {
stream_context_set_option($this->smtp, 'ssl', 'verify_peer', false);
stream_context_set_option($this->smtp, 'ssl', 'verify_peer_name', false);
stream_context_set_option($this->smtp, 'ssl', 'allow_self_signed', true);
}

if(!\stream_socket_enable_crypto($this->smtp, true, $crypto_type)) {
if(!\stream_socket_enable_crypto($this->smtp, true, STREAM_CRYPTO_METHOD_ANY_CLIENT)) {
throw new CryptoException("Start TLS failed to enable crypto");
}
return $this;
Expand Down
15 changes: 5 additions & 10 deletions tests/MailerTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
<?php

use \Tx\Mailer;
use \Tx\Mailer\SMTP;
use \Tx\Mailer\Message;
use \Tx\Mailer\Exceptions\SMTPException;
use \Monolog\Logger;
namespace Tx\Mailer\Tests;

use Tx\Mailer;
use Monolog\Logger;

class MailerTest extends TestCase
{

public function setup()
{
}

public function testSend()
{
$mail = new Mailer(new Logger('Mailer'));
Expand All @@ -23,7 +18,7 @@ public function testSend()
->addTo(self::TO_NAME, self::TO_EMAIL)
->addCc(self::CC_NAME, self::CC_EMAIL)
->addBcc(self::BCC_NAME, self::BCC_EMAIL)
->setSubject('Test Mailer '. time())
->setSubject('Test Mailer ' . time())
->setBody('Hi, boy')
->addAttachment('test', __FILE__)
->send();
Expand Down
Loading