-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from WebFiori/dev
refactor: Added Class to Store SMTP Options
- Loading branch information
Showing
6 changed files
with
117 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,22 @@ | |
|
||
require '../vendor/autoload.php'; | ||
|
||
use webfiori\email\AccountOption; | ||
use webfiori\email\Email; | ||
use webfiori\email\SMTPAccount; | ||
|
||
//First, create new SMTP account that holds SMTP connection information. | ||
$smtp = new SMTPAccount([ | ||
'port' => 465, | ||
AccountOption::PORT => 465, | ||
//Replace server address with your mail server address | ||
'server-address' => 'mail.example.com', | ||
AccountOption::SENDER_ADDRESS => 'mail.example.com', | ||
//Replace server username with your mail server username | ||
'user' => '[email protected]', | ||
'pass' => 'KnvcbxFYCz77', | ||
'sender-name' => 'Ibrahim', | ||
AccountOption::USERNAME => '[email protected]', | ||
AccountOption::PASSWORD => 'KnvcbxFYCz77', | ||
AccountOption::SENDER_NAME => 'Ibrahim', | ||
//Replace sender address with your mail server sender address | ||
'sender-address' => '[email protected]', | ||
'account-name' => 'no-reply' | ||
AccountOption::SERVER_ADDRESS => '[email protected]', | ||
AccountOption::NAME => 'no-reply' | ||
]); | ||
|
||
//Second, create your actual email. using the account that was just created to | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
namespace webfiori\tests\mail; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use webfiori\email\AccountOption; | ||
use webfiori\email\Email; | ||
use webfiori\email\exceptions\SMTPException; | ||
use webfiori\email\SendMode; | ||
|
@@ -16,31 +17,31 @@ | |
*/ | ||
class EmailMessageTest extends TestCase { | ||
private $acc00 = [ | ||
'port' => 587, | ||
'server-address' => 'outlook.office365.com', | ||
'user' => '[email protected]', | ||
'password' => '???', | ||
'sender-name' => 'Ibrahim', | ||
'sender-address' => '[email protected]', | ||
'account-name' => 'no-reply' | ||
AccountOption::PORT => 587, | ||
AccountOption::SERVER_ADDRESS => 'outlook.office365.com', | ||
AccountOption::USERNAME => '[email protected]', | ||
AccountOption::PASSWORD => '???', | ||
AccountOption::SENDER_NAME => 'Ibrahim', | ||
AccountOption::SENDER_ADDRESS => '[email protected]', | ||
AccountOption::NAME => 'no-reply' | ||
]; | ||
private $acc01 = [ | ||
'port' => 465, | ||
'server-address' => 'mail.programmingacademia.com', | ||
'user' => '[email protected]', | ||
'pass' => 'KnvcbxFYCz77', | ||
'sender-name' => 'Ibrahim', | ||
'sender-address' => '[email protected]', | ||
'account-name' => 'no-reply2' | ||
AccountOption::PORT => 465, | ||
AccountOption::SERVER_ADDRESS => 'mail.programmingacademia.com', | ||
AccountOption::USERNAME => '[email protected]', | ||
AccountOption::PASSWORD => 'KnvcbxFYCz77', | ||
AccountOption::SENDER_NAME => 'Ibrahim', | ||
AccountOption::SENDER_ADDRESS => '[email protected]', | ||
AccountOption::NAME => 'no-reply2' | ||
]; | ||
private $acc02 = [ | ||
'port' => 465, | ||
'server-address' => 'mail.programmingacademia.com', | ||
'user' => '[email protected]', | ||
'pass' => '2233', | ||
'sender-name' => 'Ibrahim', | ||
'sender-address' => '[email protected]', | ||
'account-name' => 'no-reply2' | ||
AccountOption::PORT => 465, | ||
AccountOption::SERVER_ADDRESS => 'mail.programmingacademia.com', | ||
AccountOption::USERNAME => '[email protected]', | ||
AccountOption::PASSWORD => '2233', | ||
AccountOption::SENDER_NAME => 'Ibrahim', | ||
AccountOption::SENDER_ADDRESS => '[email protected]', | ||
AccountOption::NAME => 'no-reply2' | ||
]; | ||
/** | ||
* @test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
namespace webfiori\tests\mail; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use webfiori\email\AccountOption; | ||
use webfiori\email\SMTPAccount; | ||
/** | ||
* A test class for testing the class 'webfiori\framework\mail\SMTPAccount'. | ||
|
@@ -26,13 +27,13 @@ public function test00() { | |
*/ | ||
public function test01() { | ||
$acc = new SMTPAccount([ | ||
'user' => '[email protected]', | ||
'pass' => '123456', | ||
'port' => 25, | ||
'server-address' => 'mail.examplex.com', | ||
'sender-name' => 'Example Sender', | ||
'sender-address' => '[email protected]', | ||
'account-name' => 'no-reply' | ||
AccountOption::USERNAME => '[email protected]', | ||
AccountOption::PASSWORD => '123456', | ||
AccountOption::PORT => 25, | ||
AccountOption::SERVER_ADDRESS => 'mail.examplex.com', | ||
AccountOption::SENDER_NAME => 'Example Sender', | ||
AccountOption::SENDER_ADDRESS => '[email protected]', | ||
AccountOption::NAME => 'no-reply' | ||
]); | ||
$this->assertSame(25,$acc->getPort()); | ||
$this->assertEquals('[email protected]',$acc->getAddress()); | ||
|
@@ -47,13 +48,13 @@ public function test01() { | |
*/ | ||
public function test02() { | ||
$acc = new SMTPAccount([ | ||
'username' => '[email protected]', | ||
'password' => '123456', | ||
'port' => 25, | ||
'server-address' => 'mail.examplex.com', | ||
'sender-name' => 'Example Sender', | ||
'sender-address' => '[email protected]', | ||
'account-name' => 'no-reply' | ||
AccountOption::USERNAME => '[email protected]', | ||
AccountOption::PASSWORD => '123456', | ||
AccountOption::PORT => 25, | ||
AccountOption::SERVER_ADDRESS => 'mail.examplex.com', | ||
AccountOption::SENDER_NAME => 'Example Sender', | ||
AccountOption::SENDER_ADDRESS => '[email protected]', | ||
AccountOption::NAME => 'no-reply' | ||
]); | ||
$this->assertSame(25,$acc->getPort()); | ||
$this->assertEquals('[email protected]',$acc->getAddress()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* This file is licensed under MIT License. | ||
* | ||
* Copyright (c) 2024 Ibrahim BinAlshikh | ||
* | ||
* For more information on the license, please visit: | ||
* https://github.com/WebFiori/.github/blob/main/LICENSE | ||
* | ||
*/ | ||
namespace webfiori\email; | ||
|
||
/** | ||
* A class that holds constants that represents SMTP account options. | ||
* | ||
* @author Ibrahim | ||
*/ | ||
class AccountOption { | ||
/** | ||
* An option which is used to set the address of SMTP server. | ||
*/ | ||
const SERVER_ADDRESS = 'server-address'; | ||
/** | ||
* An option which is used to set SMTP server port. | ||
*/ | ||
const PORT = 'port'; | ||
/** | ||
* An option which is used to set the username at which it is used to log in to SMTP server. | ||
*/ | ||
const USERNAME = 'user'; | ||
/** | ||
* An option which is used to set the password of the account. | ||
*/ | ||
const PASSWORD = 'pass'; | ||
/** | ||
* An option which is used to set the name of the sender that will appear when the | ||
* message is sent. | ||
*/ | ||
const SENDER_NAME = 'sender-name'; | ||
/** | ||
* An option which is used to set the address that will appear when the | ||
* message is sent. Usually, it is the same as the username. | ||
*/ | ||
const SENDER_ADDRESS = 'sender-address'; | ||
/** | ||
* An option which is used to set a unique name for the account. | ||
*/ | ||
const NAME = 'account-name'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters