|
1 | 1 | # Mailer |
2 | 2 | PHP Class for sending email. |
3 | 3 |
|
4 | | -## For example |
| 4 | +# Install |
| 5 | +## With [Composer](https://getcomposer.org/) |
| 6 | +1. Run in console: |
| 7 | + ```text |
| 8 | + php composer.phar require ddrv/mailer |
| 9 | + php composer.phar install |
| 10 | + ``` |
| 11 | +1. Include autoload file |
| 12 | + ```php |
| 13 | + include('vendor/autoload.php'); |
| 14 | + ``` |
| 15 | +## Manually install |
| 16 | +1. Download [Archive](https://github.com/ddrv/mailer/archive/master.zip) |
| 17 | +1. Unzip archive to /path/to/libraries/ |
| 18 | +1. Include files |
| 19 | + ```php |
| 20 | + require_once('/path/to/libraries/mailer/src/Mailer.php'); |
| 21 | + ``` |
| 22 | +
|
| 23 | +#Usage |
5 | 24 |
|
6 | 25 | ```php |
| 26 | +/** |
| 27 | + * Inititalization Mailer class. |
| 28 | + * Sender must be from@host.name |
| 29 | + * Encoding of mail must be UTF-8 |
| 30 | + */ |
| 31 | +$mailer = new \Ddrv\Mailer\Mailer('from@host.name','utf8'); |
| 32 | +
|
| 33 | +/** |
| 34 | + * Set subject of mail |
| 35 | + */ |
| 36 | +$mailer->subject('Subject of mail'); |
| 37 | +
|
| 38 | +/** |
| 39 | + * Add text of mail in HTML format |
| 40 | + */ |
| 41 | +$mailer->body('<p>Simple text</p>'); |
| 42 | +
|
| 43 | +/** |
| 44 | + * In need adding attachment from string, run |
| 45 | + */ |
| 46 | +$mailer->attachFromString('content','attach1.txt'); |
| 47 | +
|
| 48 | +/** |
| 49 | + * In need adding attachment from file, run |
| 50 | + */ |
| 51 | +$mailer->attachFromFile('/path/to/file','attach2.txt'); |
7 | 52 |
|
8 | | -$params = [ |
9 | | - 'sender' => 'sender@host.name', |
10 | | - 'charset' => 'utf8', |
11 | | -]; |
12 | | - |
13 | | -$mailer = new \Ddrv\Mailer\Mailer($params); |
14 | | - |
15 | | -// Simple text |
16 | | -$mailer->send('user@host.name','Test Simple Text', 'This is simple text'); |
17 | | - |
18 | | -// Attachments |
19 | | -$attachments = array( |
20 | | - // Attachment from string |
21 | | - array( |
22 | | - 'name' => 'attach_from_string.txt', |
23 | | - 'type' => 'string', |
24 | | - 'content' => 'Content of attach 1', |
25 | | - ), |
26 | | - // Attachment from file |
27 | | - array( |
28 | | - 'name' => 'attach_from_file.txt', |
29 | | - 'type' => 'file', |
30 | | - 'content' => '/path/to/file', |
31 | | - ) |
32 | | -); |
33 | | -$mailer->send('user@host.name','Test Attachments', '<i>This is Body</i>', $attachments); |
34 | | -``` |
| 53 | +/** |
| 54 | + * Send email to address@host.name |
| 55 | + */ |
| 56 | +$mailer->send('address@host.name'); |
| 57 | +``` |
0 commit comments