@@ -11,108 +11,68 @@ PHP Class for sending email.
11
11
## With [ Composer] ( https://getcomposer.org/ )
12
12
1 . Run in console:
13
13
``` text
14
- php composer.phar require ddrv/mailer
15
- php composer.phar install
14
+ php composer.phar require ddrv/mailer:~3
16
15
```
17
16
1. Include autoload file
18
17
```php
19
18
require_once('vendor/autoload.php');
20
19
```
21
- ## Manually install
22
- 1. Download [Archive](https://github.com/ddrv/mailer/archive/master.zip)
23
- 1. Unzip archive to /path/to/libraries/
24
- 1. Include files
25
- ```php
26
- require_once('/path/to/libraries/mailer/src/Mailer.php');
27
- ```
28
20
29
21
# Usage
30
22
31
23
```php
32
- /**
33
- * Inititalization Mailer class.
24
+ <?php
25
+
26
+ /*
27
+ * Initialization Mailer class.
34
28
*/
35
29
$mailer = new \Ddrv\Mailer\Mailer();
36
30
37
- /**
31
+ /*
38
32
* If need use SMTP server, setting it
39
33
*/
40
- $mailer->smtp('smtp.host.name',25,'[email protected] ','password for from', 'http://host.name');
41
-
42
- /**
43
- * Set sender [email protected] as Site Administrator
44
- */
45
- $mailer->sender('[email protected] ','Site Administrator');
46
-
47
- /**
48
- * Set subject of mail
49
- */
50
- $mailer->subject('Subject of mail');
51
-
52
- /**
53
- * Add text of mail in HTML format
54
- */
55
- $mailer->body('<p>Simple text</p>');
56
-
57
- /**
58
- * In need adding attachment from string, run
59
- */
60
- $mailer->attachFromString('content','attach1.txt');
61
-
62
- /**
63
- * In need adding attachment from file, run
34
+ $mailer->smtp(
35
+ 'smtp.host.name', // host
36
+ 25, // port
37
+
38
+ 'password for from', // password
39
+
40
+ null, // encryption: 'tls', 'ssl' or null
41
+ 'http://host.name' // domain
42
+ );
43
+
44
+ /*
45
+ * If need switch provider back to mail() function, use
64
46
*/
65
- $mailer->attachFromFile('/path/to/file','attach2.txt ');
47
+ $mailer->legacy('-f ');
66
48
67
- /**
68
- * Add addresses
49
+ /*
50
+ * Create message
69
51
*/
70
- $mailer->addAddress('[email protected] ', 'My best Friend');
71
- $mailer->addAddress('[email protected] ', 'My second Friend');
52
+ $message = new \Ddrv\Mailer\Message('[email protected] ', 'subject', '<p>Simple text</p>', true);
72
53
73
- /**
74
- * If error, remove address
54
+ /*
55
+ * You can set named sender [email protected] as Site Administrator
75
56
*/
76
- $mailer->removeAddress('address2 @host.name');
57
+ $message->setSender('from @host.name', 'Site Administrator ');
77
58
78
- /**
79
- * Send email to addresses
59
+ /*
60
+ * If need adding attachment from string, run
80
61
*/
81
- $mailer->send();
82
- ```
62
+ $message->attachFromString('attach1.txt', 'content', 'text/plain');
83
63
84
- ## Templates
85
-
86
- Content of file /path/to/template.tmpl:
87
- ``` text
88
- <h1>This template</h1>
89
- <p>Hello, {username}!</p>
90
- <p>This message generated automatically.</p>
91
- <p>{date}</p>
92
- ```
93
-
94
- PHP code:
95
- ``` php
96
- /**
97
- * You can using templates for your mails
98
- */
99
-
100
- /**
101
- * Add template from string
64
+ /*
65
+ * If need adding attachment from file, run
102
66
*/
103
- $mailer->addTemplateFromString('tmpl1 ', '< p >Hello, {username}</ p > ');
67
+ $message->attachFromFile('attach2.txt ', '/path/to/file ');
104
68
105
- /**
106
- * Add template from file
69
+ /*
70
+ * Send email to addresses (one mail for all addresses)
107
71
*/
108
- $mailer->addTemplateFromFile('tmpl2 ', '/path/to/template.tmpl' );
72
+ $mailer->send($message, array('[email protected] ', '[email protected] ') );
109
73
110
- /**
111
- * Set body from template
74
+ /*
75
+ * or send personal mailing one mail per addresses
112
76
*/
113
- $context = [
114
- 'username' => 'Anonymous',
115
- 'date' => date('Y-m-d'),
116
- ];
117
- $mailer->template('tmpl2',$context);
118
- ```
77
+ $mailer->send($message, array('[email protected] ', '[email protected] ', true));
78
+ ```
0 commit comments