1 <?php
2 3 4 5
6 class TestMailer extends Mailer {
7 protected $emailsSent = array();
8
9 10 11 12
13 function sendPlain($to, $from, $subject, $plainContent, $attachedFiles = false, $customHeaders = false) {
14 $this->emailsSent[] = array(
15 'type' => 'plain',
16 'to' => $to,
17 'from' => $from,
18 'subject' => $subject,
19
20 'content' => $plainContent,
21 'plainContent' => $plainContent,
22
23 'attachedFiles' => $attachedFiles,
24 'customHeaders' => $customHeaders,
25 );
26
27 return true;
28 }
29
30 31 32 33
34 function sendHTML($to, $from, $subject, $htmlContent, $attachedFiles = false, $customHeaders = false, $plainContent = false, $inlineImages = false) {
35 $this->emailsSent[] = array(
36 'type' => 'html',
37 'to' => $to,
38 'from' => $from,
39 'subject' => $subject,
40
41 'content' => $htmlContent,
42 'plainContent' => $plainContent,
43 'htmlContent' => $htmlContent,
44
45 'attachedFiles' => $attachedFiles,
46 'customHeaders' => $customHeaders,
47 'inlineImages' => $inlineImages,
48 );
49
50 return true;
51 }
52
53 54 55
56 function clearEmails() {
57 $this->emailsSent = array();
58 }
59
60 61 62 63 64 65 66 67 68
69 function findEmail($to, $from = null, $subject = null, $content = null) {
70 foreach($this->emailsSent as $email) {
71 $matched = true;
72
73 foreach(array('to','from','subject','content') as $field) {
74 if($value = $$field) {
75 if($value[0] == '/') $matched = preg_match($value, $email[$field]);
76 else $matched = ($value == $email[$field]);
77 if(!$matched) break;
78 }
79 }
80
81 if($matched) return $email;
82 }
83 }
84
85
86 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-