@@ -11,108 +11,68 @@ PHP Class for sending email.
1111## With [ Composer] ( https://getcomposer.org/ )
12121 . Run in console:
1313 ``` text
14- php composer.phar require ddrv/mailer
15- php composer.phar install
14+ php composer.phar require ddrv/mailer:~3
1615 ```
17161. Include autoload file
1817 ```php
1918 require_once('vendor/autoload.php');
2019 ```
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- ```
2820
2921# Usage
3022
3123```php
32- /**
33- * Inititalization Mailer class.
24+ <?php
25+
26+ /*
27+ * Initialization Mailer class.
3428 */
3529$mailer = new \Ddrv\Mailer\Mailer();
3630
37- /**
31+ /*
3832 * If need use SMTP server, setting it
3933 */
40- $mailer->smtp('smtp.host.name',25,'from@host.name','password for from', 'http://host.name');
41-
42- /**
43- * Set sender from@host.name as Site Administrator
44- */
45- $mailer->sender('from@host.name','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+ 'from@host.name', // login
38+ 'password for from', // password
39+ 'from@host.name', // sender
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
6446 */
65- $mailer->attachFromFile('/path/to/file','attach2.txt ');
47+ $mailer->legacy('-f ');
6648
67- /**
68- * Add addresses
49+ /*
50+ * Create message
6951 */
70- $mailer->addAddress('address1@host.name', 'My best Friend');
71- $mailer->addAddress('address2@host.name', 'My second Friend');
52+ $message = new \Ddrv\Mailer\Message('from@host.name', 'subject', '<p>Simple text</p>', true);
7253
73- /**
74- * If error, remove address
54+ /*
55+ * You can set named sender from@host.name as Site Administrator
7556 */
76- $mailer->removeAddress('address2 @host.name');
57+ $message->setSender('from @host.name', 'Site Administrator ');
7758
78- /**
79- * Send email to addresses
59+ /*
60+ * If need adding attachment from string, run
8061 */
81- $mailer->send();
82- ```
62+ $message->attachFromString('attach1.txt', 'content', 'text/plain');
8363
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
10266 */
103- $mailer->addTemplateFromString('tmpl1 ', '< p >Hello, {username}</ p > ');
67+ $message->attachFromFile('attach2.txt ', '/path/to/file ');
10468
105- /**
106- * Add template from file
69+ /*
70+ * Send email to addresses (one mail for all addresses)
10771 */
108- $mailer->addTemplateFromFile('tmpl2 ', '/path/to/template.tmpl' );
72+ $mailer->send($message, array('email1@host.name ', 'email2@host.name') );
10973
110- /**
111- * Set body from template
74+ /*
75+ * or send personal mailing one mail per addresses
11276 */
113- $context = [
114- 'username' => 'Anonymous',
115- 'date' => date('Y-m-d'),
116- ];
117- $mailer->template('tmpl2',$context);
118- ```
77+ $mailer->send($message, array('email1@host.name', 'email2@host.name', true));
78+ ```
0 commit comments