1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
*@author nicolaas [at] sunnysideup.co.nz |
4
|
|
|
* @package sapphire |
5
|
|
|
* @subpackage email |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class TestMailerToFile extends Mailer |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
private static $show_all_details = false; |
11
|
|
|
|
12
|
|
|
private static $file_to_write_to = "assets/emails.txt"; |
13
|
|
|
|
14
|
|
|
private static $separation_string = "
|
15
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------"; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Send a plain-text email |
19
|
|
|
*/ |
20
|
|
|
public function sendPlain($to, $from, $subject, $plainContent, $attachedFiles = false, $customheaders = false) |
21
|
|
|
{ |
22
|
|
View Code Duplication |
if ($this->Config()->get("show_all_details")) { |
23
|
|
|
$string = "
|
24
|
|
|
~TO: $to ~
|
25
|
|
|
~FROM: $from ~
|
26
|
|
|
~SUBJECT: $subject ~
|
27
|
|
|
~PLAINTEXT: $plainContent ~
|
28
|
|
|
~ATTACHEDFILES: ".print_r($attachedFiles, 1)." ~
|
29
|
|
|
~CUSTOMHEADERS: ".print_r($customheaders, 1)." ~"; |
30
|
|
|
} else { |
31
|
|
|
$string = "
|
32
|
|
|
~PLAINTEXT: TRUE
|
33
|
|
|
~TO: $to ~
|
34
|
|
|
~FROM: $from ~
|
35
|
|
|
~SUBJECT: $subject ~"; |
36
|
|
|
} |
37
|
|
|
$this->writeToFile($string); |
38
|
|
|
return true; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Send a multi-part HTML email |
43
|
|
|
*/ |
44
|
|
|
public function sendHTML($to, $from, $subject, $htmlContent, $attachedFiles = false, $customheaders = false, $plainContent = false, $inlineImages = false) |
45
|
|
|
{ |
46
|
|
View Code Duplication |
if ($this->Config()->get("show_all_details")) { |
47
|
|
|
$string = "
|
48
|
|
|
~TO: $to ~
|
49
|
|
|
~FROM: $from ~
|
50
|
|
|
~SUBJECT: $subject ~
|
51
|
|
|
~HTMLCONTENT: $htmlContent ~
|
52
|
|
|
~ATTACHEDFILES: ".print_r($attachedFiles, 1)." ~
|
53
|
|
|
~CUSTOMHEADERS: ".print_r($customheaders, 1)." ~
|
54
|
|
|
~PLAINTEXT: $plainContent ~
|
55
|
|
|
~INLINEIMAGES: $inlineImages ~"; |
56
|
|
|
} else { |
57
|
|
|
$string = "
|
58
|
|
|
~PLAINTEXT: FALSE
|
59
|
|
|
~TO: $to ~
|
60
|
|
|
~FROM: $from ~
|
61
|
|
|
~SUBJECT: $subject ~"; |
62
|
|
|
} |
63
|
|
|
$this->writeToFile($string); |
64
|
|
|
return true; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function writeToFile($string) |
68
|
|
|
{ |
69
|
|
|
$myFile = Director::baseFolder()."/".self::$file_to_write_to; |
70
|
|
|
$fh = fopen($myFile, 'a') or die("can't open file $myFile"); |
|
|
|
|
71
|
|
|
$stringData = self::$separation_string.$string; |
72
|
|
|
fwrite($fh, $stringData); |
73
|
|
|
fclose($fh); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|