File tree Expand file tree Collapse file tree 2 files changed +72
-0
lines changed Expand file tree Collapse file tree 2 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -54,3 +54,22 @@ swiftmailer:
54
54
file:
55
55
transport: file
56
56
```
57
+
58
+ ## Copy plugin
59
+
60
+ Copy plugin is useful to BCC all outgoing emails to specific address (e.g. if you want to monitor everything what you send out).
61
+
62
+ ** Connecting to Symfony:**
63
+
64
+ Define CopyPlugin as service in ` services.yml ` :
65
+
66
+ ```
67
+ swiftmailer.mailer.plugin.copy:
68
+ class: Geekdevs\SwiftMailer\Plugins\CopyPlugin
69
+ arguments:
70
+
71
+ tags:
72
+ - { name: "swiftmailer.primary.plugin" }
73
+ ```
74
+
75
+ Note the tag ` swiftmailer.primary.plugin ` where "primary" should be the name of your mailer.
Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace Geekdevs \SwiftMailer \Plugin ;
3
+
4
+ /**
5
+ * Class CopyPlugin
6
+ * @package Geekdevs\SwiftMailer\Transport
7
+ */
8
+ class CopyPlugin implements \Swift_Events_SendListener
9
+ {
10
+ /**
11
+ * @var string
12
+ */
13
+ protected $ recipient ;
14
+
15
+ /**
16
+ * CopyPlugin constructor.
17
+ * @param string $recipient
18
+ */
19
+ public function __construct ($ recipient )
20
+ {
21
+ $ this ->recipient = $ recipient ;
22
+ }
23
+
24
+ /**
25
+ * @param \Swift_Events_SendEvent $evt
26
+ */
27
+ public function beforeSendPerformed (\Swift_Events_SendEvent $ evt )
28
+ {
29
+ /**
30
+ * @var \Swift_Message $message
31
+ */
32
+ $ message = $ evt ->getMessage ();
33
+ $ recipient = $ this ->recipient ;
34
+ $ headers = $ message ->getHeaders ();
35
+
36
+ if ($ headers ->has ('to ' )) {
37
+ $ headers ->addMailboxHeader ('X-Swift-To ' , $ message ->getTo ());
38
+ }
39
+
40
+ if ($ headers ->has ('cc ' )) {
41
+ $ headers ->addMailboxHeader ('X-Swift-Cc ' , $ message ->getCc ());
42
+ }
43
+
44
+ $ message ->addBcc ($ recipient );
45
+ }
46
+
47
+ /**
48
+ * @param \Swift_Events_SendEvent $evt
49
+ */
50
+ public function sendPerformed (\Swift_Events_SendEvent $ evt )
51
+ {
52
+ }
53
+ }
You can’t perform that action at this time.
0 commit comments