|
1 | 1 | # Mailer
|
2 | 2 | Mailer Class
|
| 3 | + |
| 4 | +[](https://packagist.org/packages/initphp/mailer) [](https://packagist.org/packages/initphp/mailer) [](https://packagist.org/packages/initphp/mailer) [](https://packagist.org/packages/initphp/mailer) [](https://packagist.org/packages/initphp/mailer) |
| 5 | + |
| 6 | + |
| 7 | +## Instalation |
| 8 | + |
| 9 | +``` |
| 10 | +composer require initphp/mailer |
| 11 | +``` |
| 12 | + |
| 13 | +## Requirements |
| 14 | + |
| 15 | +- PHP 7.4 or higher |
| 16 | +- MBString Extension |
| 17 | +- Iconv Extension |
| 18 | +- FileInfo Extension |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +```php |
| 23 | +$config = [ |
| 24 | + 'mailType' => 'text' // or 'html' |
| 25 | + 'protocol' => 'smtp' // or 'mail' or 'sendmail' |
| 26 | + 'SMTPAuth' => true, |
| 27 | + 'SMTPHost' => 'smtp.gmail.com', |
| 28 | + 'SMTPUser' => 'your-mail@gmail.com', |
| 29 | + 'SMTPPass' => 'YourMailPassword', |
| 30 | + 'SMTPPort' => 587 |
| 31 | +]; |
| 32 | +$mailer = \InitPHP\Mailer\Mailer::newInstance($config); |
| 33 | + |
| 34 | +$mailer->setFrom('info@muhammetsafak.com.tr', 'Muhammet Şafak'); |
| 35 | +//$mailer->setTo('example@example.com'); |
| 36 | +//$mailer->setCC('john@hotmail.com'); |
| 37 | +//$mailer->setBCC('testing@gmail.com'); |
| 38 | +$mailer->setSubject('Mail Subject'); |
| 39 | +$mailer->setMessage('Mail Body Message'); |
| 40 | +$mailer->send(); |
| 41 | +``` |
| 42 | + |
| 43 | +## Methods |
| 44 | + |
| 45 | +#### `newInstance()` |
| 46 | + |
| 47 | +Creates a new mailer object and returns it. |
| 48 | + |
| 49 | +```php |
| 50 | +public static function newInstance(?array $config = null): \InitPHP\Mailer\Mailer |
| 51 | +``` |
| 52 | + |
| 53 | +### `clear()` |
| 54 | + |
| 55 | +```php |
| 56 | +public function clear(bool $clearAttachments = false): self |
| 57 | +``` |
| 58 | + |
| 59 | +### `setHeader()` |
| 60 | + |
| 61 | +```php |
| 62 | +public function setHeader(string $header, string $value): self |
| 63 | +``` |
| 64 | + |
| 65 | +### `setFrom()` |
| 66 | + |
| 67 | +```php |
| 68 | +public function setFrom(string $from, string $name = '', ?string $returnPath = null): self |
| 69 | +``` |
| 70 | + |
| 71 | +### `setReplyTo()` |
| 72 | + |
| 73 | +```php |
| 74 | +public function setReplyTo(string $replyTo, string $name = ''): self |
| 75 | +``` |
| 76 | + |
| 77 | +### `setTo()` |
| 78 | + |
| 79 | +```php |
| 80 | +public function setTo(string|array $to): self |
| 81 | +``` |
| 82 | + |
| 83 | +### `setCC()` |
| 84 | + |
| 85 | +```php |
| 86 | +public function setCC(string $cc): self |
| 87 | +``` |
| 88 | + |
| 89 | +### `setBCC()` |
| 90 | + |
| 91 | +```php |
| 92 | +public function setBCC(string $bcc, ?int $limit = null): self |
| 93 | +``` |
| 94 | + |
| 95 | +### `setSubject()` |
| 96 | + |
| 97 | +```php |
| 98 | +public function setSubject(string $subject): self |
| 99 | +``` |
| 100 | + |
| 101 | +### `setMessage()` |
| 102 | + |
| 103 | +```php |
| 104 | +public function setMessage(string $body): self |
| 105 | +``` |
| 106 | + |
| 107 | +### `setAttachmentCID()` |
| 108 | + |
| 109 | +```php |
| 110 | +public function setAttachmentCID(string $fileName): false|string |
| 111 | +``` |
| 112 | + |
| 113 | +### `setAltMessage()` |
| 114 | + |
| 115 | +```php |
| 116 | +public function setAltMessage(string $str): self |
| 117 | +``` |
| 118 | + |
| 119 | +### `setMailType()` |
| 120 | + |
| 121 | +```php |
| 122 | +public function setMailType(string $type = 'text'): self |
| 123 | +``` |
| 124 | + |
| 125 | +- `$type` : `text` or `html` |
| 126 | + |
| 127 | +### `setWordWrap()` |
| 128 | + |
| 129 | +```php |
| 130 | +public function setWordWrap(bool $wordWrap = true): self |
| 131 | +``` |
| 132 | + |
| 133 | +### `setProtocol()` |
| 134 | + |
| 135 | +```php |
| 136 | +public function setProtocol(string $protocol = 'mail'): self |
| 137 | +``` |
| 138 | + |
| 139 | +- `$protocol` : `mail`, `sendmail` or `smtp` |
| 140 | + |
| 141 | +### `setPriority()` |
| 142 | + |
| 143 | +```php |
| 144 | +public function setPriority(int $n = 3): self |
| 145 | +``` |
| 146 | + |
| 147 | +- `$n` : An integer between 1 and 5 inclusive. |
| 148 | + |
| 149 | +### `setNewline()` |
| 150 | + |
| 151 | +```php |
| 152 | +public function setNewline(string $newLine = \PHP_EOL): self |
| 153 | +``` |
| 154 | + |
| 155 | +### `setCRLF()` |
| 156 | + |
| 157 | +```php |
| 158 | +public function setCRLF(string $CRLF = \PHP_EOL): self |
| 159 | +``` |
| 160 | + |
| 161 | +### `attach()` |
| 162 | + |
| 163 | +```php |
| 164 | +public function attach(string|resource $file, string $disposition = '', ?string $newName = null, ?string $mime = null): false|self |
| 165 | +``` |
| 166 | + |
| 167 | +### `send()` |
| 168 | + |
| 169 | +```php |
| 170 | +public function send(bool $autoClear = true): bool |
| 171 | +``` |
| 172 | + |
| 173 | +### `printDebugger()` |
| 174 | + |
| 175 | +```php |
| 176 | +public function printDebugger(array $include = ['headers', 'subject', 'body']): string |
| 177 | +``` |
| 178 | + |
| 179 | +## Credits |
| 180 | + |
| 181 | +- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) <<info@muhammetsafak.com.tr>> |
| 182 | + |
| 183 | +## License |
| 184 | + |
| 185 | +Copyright © 2022 [MIT License](./LICENSE) |
0 commit comments