Skip to content

Commit

Permalink
Merge pull request #4 from WebFiori/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
usernane authored Jul 16, 2022
2 parents c3e2d80 + 8232ba2 commit e51b4df
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 43 deletions.
Binary file added example/AttachmentImg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions example/sendMail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
require '../vendor/autoload.php';

use webfiori\email\SMTPAccount;
use webfiori\email\EmailMessage;

//First, create new SMTP account that holds SMTP connection information.
$smtp = new SMTPAccount([
'port' => 465,
//Replace server address with your mail server address
'server-address' => 'mail.example.com',
//Replace server username with your mail server username
'user' => '[email protected]',
'pass' => 'KnvcbxFYCz77',
'sender-name' => 'Ibrahim',
//Replace sender address with your mail server sender address
'sender-address' => '[email protected]',
'account-name' => 'no-reply'
]);

//Second, create your actual email. using the account that was just created to
//send messages.
$email = new EmailMessage($smtp);

//Set subject
$email->setSubject('Hello World From PHP 😀');

//Optionally, set priority
$email->setPriority(1);

//Specify who will receive the message
$email->addTo('[email protected]');

//Add optional attachments
$email->addAttachment(__DIR__.DIRECTORY_SEPARATOR.'AttachmentImg.png');

//Build your HTML Message
$div = $email->insert('div');
$div->addChild('p')->text('Hello World Message');
$div->addChild('p', [
'style' => [
'font-weight' => 'bold',
'color' => 'red'
]
])->text('This is just a test message.');

//Finally, send.
$email->send();

echo 'sent';
65 changes: 22 additions & 43 deletions tests/webfiori/tests/mail/EmailMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use webfiori\email\EmailMessage;
use webfiori\email\SMTPAccount;
use webfiori\email\SMTPServer;
use webfiori\email\exceptions\SMTPException;
/**
* A test class for testing the class 'webfiori\framework\mail\EmailMessage'.
*
Expand All @@ -29,6 +30,15 @@ class EmailMessageTest extends TestCase {
'sender-address' => '[email protected]',
'account-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'
];
/**
* @test
*/
Expand Down Expand Up @@ -149,47 +159,16 @@ public function testSend00() {
/**
* @test
*/
// public function test01() {
// $smtp = new SMTPAccount();
// $smtp->setAccountName('smtp-acc-00');
// //$smtp->setServerAddress('mail.invalid.com');
// WebFioriApp::getAppConfig()->addAccount($smtp);
// $this->expectException(\Exception::class);
// $this->expectExceptionMessage('The account "smtp-acc-00" has invalid host or port number. Port: 465, Host: .');
// $message = new EmailMessage('smtp-acc-00');
// }
/**
* @test
*/
// public function test02() {
// $this->expectException(\Exception::class);
// $this->expectExceptionMessage('The account "smtp-acc-00" has invalid host or port number. Port: 255, Host: mail.programmingacademia.com.');
// $smtp = new SMTPAccount();
// $smtp->setPassword('iz1Iimu#z');
// $smtp->setAddress('[email protected]');
// $smtp->setUsername('[email protected]');
// $smtp->setServerAddress('mail.programmingacademia.com ');
// $smtp->setPort(255);
// $smtp->setAccountName('smtp-acc-00');
// WebFioriApp::getAppConfig()->addAccount($smtp);
// $message = new EmailMessage('smtp-acc-00');
// }
/**
* @test
*/
// public function test03() {
// $this->expectException(\Exception::class);
// $this->expectExceptionMessage('The account "smtp-acc-00" has invalid host or port number. Port: 765765, Host: mail.programmingacademia.com.');
// $smtp = new SMTPAccount();
// $smtp->setPassword('izimu#z');
// $smtp->setAddress('[email protected]');
// $smtp->setUsername('[email protected]');
// $smtp->setServerAddress('mail.programmingacademia.com ');
// $smtp->setPort(765765);
// $smtp->setAccountName('smtp-acc-00');
// WebFioriApp::getAppConfig()->addAccount($smtp);
// $message = new EmailMessage('smtp-acc-00');
// $this->assertTrue($message instanceof EmailMessage);
// }

public function testSend01() {
$this->expectException(SMTPException::class);
$this->expectExceptionMessage('Unable to login to SMTP server: 535 Incorrect authentication data');
$message = new EmailMessage(new SMTPAccount($this->acc02));
$message->setSubject('Test Email From WebFiori');
$message->setPriority(1);
$message->insert('p')->text('Super test message.');
$message->addTo('[email protected]');

$message->send();

}
}

0 comments on commit e51b4df

Please sign in to comment.