Skip to content

Commit b1af05c

Browse files
committed
version 4.0.0
1 parent 48e509a commit b1af05c

23 files changed

+2194
-502
lines changed

.github/ISSUE_TEMPLATE.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
| Q | A
1010
| ---------------- | ---
11-
| Mailer version | 3.0.?
11+
| Mailer version | 4.0.?
12+
| Mailer spool | `memory` or `file`
1213
| Mailer transport | `sendmail`, `smtp`, etc
1314
| PHP version | 5.?
1415
| Operating system |
15-
16-
### Add your binary database file in attacnments

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
/.idea/*
1+
/.idea/*
2+
/vendor/*
3+
/phpunit.xml

README.md

+82-166
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PHP library for sending email.
1111
## With [Composer](https://getcomposer.org/)
1212
1. Run in console:
1313
```text
14-
php composer.phar require ddrv/mailer:~3
14+
php composer.phar require ddrv/mailer:~4.0
1515
```
1616
1. Include autoload file
1717
```php
@@ -24,6 +24,14 @@ PHP library for sending email.
2424
```php
2525
<?php
2626
27+
use \Ddrv\Mailer\Transport\SendmailTransport;
28+
use \Ddrv\Mailer\Transport\SmtpTransport;
29+
use \Ddrv\Mailer\Transport\FakeTransport;
30+
use \Ddrv\Mailer\Spool\MemorySpool;
31+
use \Ddrv\Mailer\Spool\FileSpool;
32+
use \Ddrv\Mailer\Mailer;
33+
use \Ddrv\Mailer\Message;
34+
2735
/*
2836
* Step 1. Initialization transport
2937
* --------------------------------
@@ -32,15 +40,14 @@ PHP library for sending email.
3240
/*
3341
* a. Sendmail
3442
*/
35-
$transport = new \Ddrv\Mailer\Transport\Sendmail(
36-
'[email protected]', // sender
43+
$transport = new SendmailTransport(
3744
'-f' // sendmail options
3845
);
3946
4047
/*
4148
* b. SMTP
4249
*/
43-
$transport = new \Ddrv\Mailer\Transport\Smtp(
50+
$transport = new SmtpTransport(
4451
'smtp.fight.club', // host
4552
25, // port
4653
'joe', // login
@@ -54,37 +61,72 @@ $transport = new \Ddrv\Mailer\Transport\Smtp(
5461
* c. Fake (emulation send emails)
5562
*/
5663
57-
$transport = new \Ddrv\Mailer\Transport\Fake();
64+
$transport = new FakeTransport();
5865
5966
/*
6067
* d. Other. You can implement Ddrv\Mailer\Transport\TransportInterface interface
6168
*/
6269
6370
/*
64-
* Step 2. Initialization Mailer
71+
* Step 2. Initialization spool
6572
* -----------------------------
6673
*/
67-
$mailer = new \Ddrv\Mailer\Mailer($transport);
6874
6975
/*
70-
* Step 3. Create message
76+
* a. File spool.
77+
*/
78+
$spool = new FileSpool($transport, sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mail');
79+
80+
/*
81+
* b. Memory spool.
82+
*/
83+
$spool = new MemorySpool($transport);
84+
85+
/*
86+
* c. Other. You can implement Ddrv\Mailer\SpoolInterface interface
87+
*/
88+
89+
/*
90+
* Step 3. Initialization Mailer
91+
* -----------------------------
92+
*/
93+
$mailer = new Mailer($spool);
94+
95+
// If you need a replace header "From" in all messages, set your sender in second parameter
96+
$mailer = new Mailer($spool, "Fight Club Informer <[email protected]>");
97+
98+
/*
99+
* Step 4. Create message
71100
* ----------------------
72101
*/
102+
73103
74-
$text = <<<HTML
104+
$message1 = new Message(
105+
'Test message', // subject of message
106+
'<h1>Hello, world!</h1>', // html body
107+
'Hello, world!' // plain body
108+
);
109+
$message1->addTo('[email protected]', 'My Friend');
110+
111+
$html = <<<HTML
75112
<h1>Welcome to Fight Club</h1>
76113
<p>Please, read our rules in attachments</p>
77114
HTML;
78-
79115
80-
$message = new \Ddrv\Mailer\Message(
81-
'Fight Club', // subject of message
82-
$text, // text of message
83-
true // true for html, false for plain text
84-
);
116+
$text = <<<TEXT
117+
Welcome to Fight Club
118+
Please, read our rules in attachments
119+
TEXT;
120+
121+
$message2 = new Message();
122+
$message2
123+
->setSubject('Fight Club')
124+
->setHtmlBody($html)
125+
->setPlainBody($text)
126+
;
85127
86128
/*
87-
* Step 4. Attachments
129+
* Step 5. Attachments
88130
* -------------------
89131
*/
90132
@@ -102,7 +144,7 @@ $rules = <<<TEXT
102144
8. If this is your first night at fight club, you have to fight.
103145
TEXT;
104146
105-
$message->attachFromString(
147+
$message2->attachFromString(
106148
'fight-club.txt', // attachment name
107149
$rules, // content
108150
'text/plain' // content-type
@@ -111,178 +153,52 @@ $message->attachFromString(
111153
/*
112154
* b. Creating attachments from file
113155
*/
114-
115156
$path = '/home/tyler/docs/projects/mayhem/rules.txt';
116157
117-
$message->attachFromFile(
158+
$message2->attachFromFile(
118159
'project-mayhem.txt', // attachment name
119160
$path // path to attached file
120161
);
121162
122163
/*
123-
* Step 5. Add contacts names (OPTIONAL)
164+
* Step 6. Add recipients
124165
*/
125-
126-
$mailer->addContact('[email protected]', 'Tyler Durden');
127-
$mailer->addContact('[email protected]', 'Angel Face');
128-
$mailer->addContact('[email protected]', 'Robert Paulson');
166+
$message2->addTo('[email protected]', 'Tyler Durden');
167+
$message2->addCc('[email protected]', 'Robert Paulson');
168+
$message2->addBcc('[email protected]', 'Angel Face');
129169
130170
/*
131-
* Step 6. Send mail
171+
* Step 7. Send mail
132172
* -----------------
133173
*/
134174
135175
/*
136-
* a. Personal mailing (one mail per address)
176+
* a. Simple send to all recipients
137177
*/
138-
139-
$mailer->send(
140-
$message,
141-
array(
142-
143-
144-
145-
)
146-
);
147-
148-
/*
149-
* b. Mass mailing (one mail to all addresses)
150-
*/
151-
152-
$mailer->mass(
153-
$message,
154-
array('[email protected]'), // recipients
155-
array('[email protected]'), // CC (carbon copy)
156-
array('[email protected]') // BCC (blind carbon copy)
157-
);
158-
```
159-
160-
# Channels
161-
162-
You can add some channels for sending.
163-
164-
```php
165-
<?php
166-
167-
$default = new \Ddrv\Mailer\Transport\Sendmail('[email protected]');
168-
169-
$noreply = new \Ddrv\Mailer\Transport\Smtp(
170-
'smtp.host.name',
171-
25,
172-
173-
'password',
174-
175-
'tls',
176-
'http://host.name'
177-
);
178-
179-
$support = new \Ddrv\Mailer\Transport\Smtp(
180-
'smtp.host.name',
181-
25,
182-
183-
'password',
184-
185-
null,
186-
'http://host.name'
187-
);
188-
189-
// channel name is \Ddrv\Mailer\Mailer::CHANNEL_DEFAULT.
190-
// You can define your channel name in second parameter
191-
// for example: $mailer = new \Ddrv\Mailer\Mailer($default, 'channel');
192-
$mailer = new \Ddrv\Mailer\Mailer($default);
193-
$mailer->setChannel($noreply, 'noreply');
194-
$mailer->setChannel($support, 'support');
195-
196-
$mailer->addContact('[email protected]', 'Informer');
197-
$mailer->addContact('[email protected]', 'Support Agent');
198-
199-
$msg1 = new \Ddrv\Mailer\Message(
200-
'host.name: your account registered',
201-
'Your account registered! Please do not reply to this email',
202-
false
203-
);
204-
205-
$msg2 = new \Ddrv\Mailer\Message(
206-
'host.name: ticket #4221 closed',
207-
'<p>Ticket #4221 closed</p>',
208-
true
209-
);
210-
211-
$mailer->addContact('[email protected]', 'Recipient First');
212-
$mailer->addContact('[email protected]', 'Recipient Second');
213-
$mailer->addContact('[email protected]', 'Other Recipient');
214-
215-
$recipients1 = array(
216-
217-
218-
);
219-
$recipients2 = array(
220-
221-
222-
);
178+
$mailer->send($message1);
223179
224180
/*
225-
* Send to channel
226-
* -----------------------
181+
* b. Spooling
182+
* For add message to spool, you need set second parameter as positive integer
227183
*/
228-
$mailer->send(
229-
$msg1, // message
230-
$recipients1, // recipients
231-
'noreply' // channel name
232-
);
233-
234-
$mailer->send(
235-
$msg2, // message
236-
$recipients2, // recipients
237-
'support' // channel name
238-
);
184+
$mailer->send($message1, 2);
185+
$mailer->send($message2, 1);
239186
240-
/*
241-
* Send to some channels
242-
*/
243-
$mailer->send(
244-
$msg2, // message
245-
$recipients2, // recipients
246-
array('support', 'noreply') // channels
247-
);
187+
// Send from spool.
188+
$mailer->flush();
248189
249190
/*
250-
* Send to all channels
191+
* You can set limit for send messages from spool
251192
*/
252-
$mailer->send($msg2, $recipients2, \Ddrv\Mailer\Mailer::CHANNEL_ALL);
193+
$mailer->flush(5);
253194
254195
/*
255-
* CAUTION!
256-
* If the channel does not exists, the call well be skipped
196+
* Step 8. Personal mailing
197+
* You can send one message with many recipient as many mails per recipient
198+
* (messages will be without CC fnd BCC headers and include only one email on To header).
257199
*/
200+
$mailer->personal($message2); // without spool
201+
// or
202+
$mailer->personal($message2, 1); // with spool
203+
$mailer->flush();
258204
259-
// If you need clear memory, you may clear contacts
260-
261-
$mailer->clearContacts();
262-
263-
```
264-
265-
# Logging
266-
267-
```php
268-
<?php
269-
270-
$support = new \Ddrv\Mailer\Transport\Sendmail('[email protected]');
271-
$noreply = new \Ddrv\Mailer\Transport\Sendmail('[email protected]');
272-
$default = new \Ddrv\Mailer\Transport\Sendmail('[email protected]');
273-
$mailer = new \Ddrv\Mailer\Mailer($support, 'support');
274-
$mailer->setChannel($noreply, 'noreply');
275-
$mailer->setChannel($default, 'default');
276-
277-
/**
278-
* @var Psr\Log\LoggerInterface $logger
279-
*/
280-
281-
$mailer->setLogger(
282-
function ($log) use ($logger) {
283-
$logger->info($log);
284-
},
285-
array('noreply', 'support') // channels
286-
);
287-
288-
```

composer.json

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
{
22
"name": "ddrv/mailer",
3-
"version":"3.1.1",
4-
"require":{
5-
"php":">=5.3.0",
6-
"ext-mbstring": "*"
7-
},
8-
"suggest": {
9-
"ext-fileinfo": "Mime-Type detecting"
10-
},
3+
"version": "4.0.0",
114
"type": "library",
125
"description": "PHP library for sending email",
136
"keywords": ["email", "mail", "send", "attachments", "smtp", "sendmail"],
@@ -19,9 +12,25 @@
1912
"homepage": "https://ddrv.ru"
2013
}
2114
],
15+
"require": {
16+
"php": ">=5.3.3",
17+
"ext-mbstring": "*"
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "^4.8.35 || ^5.7",
21+
"fzaninotto/faker": "~1.8"
22+
},
23+
"suggest": {
24+
"ext-fileinfo": "Mime-Type detecting"
25+
},
2226
"autoload": {
2327
"psr-4": {
2428
"Ddrv\\Mailer\\": "src/"
2529
}
30+
},
31+
"autoload-dev": {
32+
"psr-4": {
33+
"Tests\\Ddrv\\Mailer\\": "tests/"
34+
}
2635
}
2736
}

0 commit comments

Comments
 (0)