-
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.
- Loading branch information
1 parent
0fad361
commit 1d8fc95
Showing
10 changed files
with
1,223 additions
and
1 deletion.
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 |
---|---|---|
@@ -1 +1,84 @@ | ||
"# mail" | ||
# Effectra\Mail | ||
|
||
Effectra\Mail is a package that provides a flexible and easy-to-use email sending functionality for your applications. It supports multiple mail drivers and allows you to configure various email settings such as the mail server host, port, authentication, and more. | ||
|
||
## Features | ||
|
||
- Support for multiple mail drivers (SMTP, sendmail, etc.) | ||
- Configuration options for mail server settings | ||
- Easy setup and usage | ||
- Exception handling for mail sending errors | ||
|
||
## Installation | ||
|
||
You can install the Effectra\Mail package via Composer. Run the following command in your terminal: | ||
|
||
```bash | ||
composer require effectra/mail | ||
``` | ||
|
||
## Usage | ||
|
||
### Creating a Mailer Instance | ||
|
||
To send emails using the Effectra\Mail package, you need to create a mailer instance. The `MailerFactory` class provides a convenient way to create the mailer instance: | ||
|
||
```php | ||
use Effectra\Mail\Factory\MailerFactory; | ||
|
||
$mailerFactory = new MailerFactory(); | ||
|
||
// Create a mailer instance | ||
$mailer = $mailerFactory->createMailer( | ||
'smtp', // Mail driver (e.g., 'smtp', 'sendmail') | ||
'mail.example.com', // Mail server host | ||
587, // Mail server port | ||
'username', // Username for authentication | ||
'password', // Password for authentication | ||
'[email protected]' // "From" email address | ||
); | ||
``` | ||
|
||
### Sending an Email | ||
|
||
Once you have a mailer instance, you can use it to send emails. The `Mailer` class provides methods for setting the email recipients, subject, content, and more. Here's an example of sending an email: | ||
|
||
```php | ||
// Set email recipients | ||
$mailer->to('[email protected]'); | ||
$mailer->cc('[email protected]'); | ||
$mailer->bcc('[email protected]'); | ||
|
||
// Set email subject and content | ||
$mailer->subject('Hello, world!'); | ||
$mailer->text('This is the plain text content of the email.'); | ||
$mailer->html('<p>This is the HTML content of the email.</p>'); | ||
|
||
// Send the email | ||
try { | ||
$mailer->send(); | ||
echo 'Email sent successfully!'; | ||
} catch (Exception $e) { | ||
echo 'An error occurred while sending the email: ' . $e->getMessage(); | ||
} | ||
``` | ||
|
||
Feel free to explore the `Mailer` class and its methods to customize the email sending process according to your needs. | ||
|
||
## License | ||
|
||
This package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT). | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please create an issue or submit a pull request on the GitHub repository. | ||
|
||
## Credits | ||
|
||
Effectra\Mail is developed and maintained by [Mohammed Taha](https://github.com/bmtMohammedTaha). | ||
|
||
## Support | ||
|
||
For any questions or support regarding the Effectra\Mail package, please contact [[email protected]](mailto:[email protected]). | ||
|
||
``` |
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,23 @@ | ||
{ | ||
"name": "effectra/mail", | ||
"description": "The Effectra File Mail package.", | ||
"type": "library", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"Effectra\\Mail\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Mohammed Taha", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.0.2", | ||
"effectra/config": "^1.0", | ||
"phpmailer/phpmailer": "^6.8" | ||
}, | ||
"minimum-stability": "stable" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Effectra\Mail\Contracts; | ||
|
||
/** | ||
* Interface MailerInterface | ||
* @package Effectra\Mail\Contracts | ||
*/ | ||
interface MailerInterface | ||
{ | ||
/** | ||
* Set the "from" email address. | ||
* | ||
* @param string|null $email The "from" email address. | ||
* @return MailerInterface | ||
*/ | ||
public function from(string|null $email = null): self; | ||
|
||
/** | ||
* Set the "to" email address(es). | ||
* | ||
* @param string|array $email The "to" email address(es). | ||
* @return MailerInterface | ||
*/ | ||
public function to(string|array $email): self; | ||
|
||
/** | ||
* Add the "bcc" email address(es). | ||
* | ||
* @param string|array $users The "bcc" email address(es). | ||
* @return MailerInterface | ||
*/ | ||
public function bcc(string|array $users): self; | ||
|
||
/** | ||
* Add the "cc" email address(es). | ||
* | ||
* @param string|array $users The "cc" email address(es). | ||
* @return MailerInterface | ||
*/ | ||
public function cc(string|array $users): self; | ||
|
||
/** | ||
* Set the email subject. | ||
* | ||
* @param string $subject The email subject. | ||
* @return MailerInterface | ||
*/ | ||
public function subject(string $subject): self; | ||
|
||
/** | ||
* Set the email content as plain text. | ||
* | ||
* @param string $msg The plain text email content. | ||
* @return MailerInterface | ||
*/ | ||
public function text(string $msg): self; | ||
|
||
/** | ||
* Set the email content as HTML. | ||
* | ||
* @param string $html The HTML email content. | ||
* @return MailerInterface | ||
*/ | ||
public function html(string $html): self; | ||
|
||
/** | ||
* Attach file(s) to the email. | ||
* | ||
* @param string|array $files The file(s) to attach. | ||
* @return MailerInterface | ||
*/ | ||
public function attachment(string|array $files): self; | ||
|
||
/** | ||
* Send the email. | ||
* | ||
* @param callable $callback The callback function to execute before sending the email. | ||
* @param mixed $args Additional arguments to pass to the callback function. | ||
* @return mixed | ||
*/ | ||
public function send(callable $callback, $args): mixed; | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Effectra\Mail\Exception; | ||
|
||
use Exception; | ||
|
||
/** | ||
* Class ConnectException | ||
* | ||
* Represents an exception that is thrown when a connection error occurs in the mail system. | ||
* | ||
* @package Effectra\Mail\Exception | ||
*/ | ||
class ConnectException extends Exception | ||
{ | ||
// No additional properties or methods in this class | ||
} |
Oops, something went wrong.