class-mail
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/*
* @Name Weet ik veel meel:D
* @Author Mark Pieper
* @Date 23-01-07
* @Todo Bijlagen
?>
*/
class Mail {
/**
* Email onderwerp
*/
protected $subject;
/**
* Email bericht
*/
protected $msg;
/**
* Email ontvanger
*/
protected $email_recipient;
/**
* Naam ontvanger
*/
protected $name_recipient;
/**
* Email zender
*/
protected $email_sender;
/**
* Naam zender
*/
protected $name_sender;
/**
* Carbon Copy
*/
protected $cc = array();
/**
* Blind Carbon Copy
*/
protected $bcc = array();
/**
* Email headers
*/
protected $headers = array();
/**
* Constructor
* @param: $content_type = html of text
*/
public function __construct($content_type = 'text') {
if($content_type == 'html') {
$this -> add_header('Content-Type: text/html; charset=iso-8859-1');
}
else
{
$this -> add_header('Content-Type: text/plain; charset=iso-8859-1');
}
$this -> add_msg('');
}
/**
* Verzend de email
*/
public function send_mail() {
$header = $this -> make_headers();
if(mail($this -> email_recipient, $this -> subject, $this -> msg, $header)) {
return 'Versturen gelukt';
}
else
{
trigger_error('<p><strong>Er is een fout opgetreden bij het verzenden van de email!</strong></p>');
}
}
/**
* Stel het onderwerp in
* @param: $subject = het onderwerp van de email
*/
public function set_subject($subject) {
$this -> subject = $subject;
}
/**
* Stel de naam en de email van de ontvanger in
* @param: $name = de naam van de ontvanger
* @param: $email = het emailadres van de ontvanger
*/
public function set_recipient($name, $email) {
$this -> name_recipient = $name;
$this -> email_recipient = $email;
}
/**
* Stel de naam en de email van de verzender in
* @param: $name = de naam van de verzender
* @param: $email = het emailadres van de verzender
*/
public function set_sender($name, $email) {
$this -> name_sender = $name;
$this -> email_sender = $email;
}
/**
* Voeg een CC toe
* @param: $cc = Carbon Copy (Mag een array zijn)
*/
public function add_cc($cc) {
if(is_array($cc)) {
foreach($cc as $waarde) {
$this -> cc[] = $waarde;
}
}
else
{
$this -> cc[] = $cc;
}
}
/**
* Maak het bericht
* @param: $msg = het bericht van de email
*/
public function add_msg($msg) {
$this -> msg .= $msg;
}
/**
* Voeg een BCC toe
* @param: $cc = Blind Carbon Copy (Mag een array zijn)
*/
public function add_bcc($bcc) {
if(is_array($bcc)) {
foreach($bcc as $waarde) {
$this -> bcc[] = $waarde;
}
}
else
{
$this -> bcc[] = $bcc;
}
}
/*** Protected Functions ***/
/**
* @param: $header = De header die moet worden toegevoegd
*/
protected function add_header($header) {
$replace = array("\n", "\r");
$header = str_replace($replace, '', $header);
$this -> headers[] = $header."\r\n";
}
/**
* Maak de headers, en voeg ze toe
*/
protected function make_headers() {
$this -> add_header('MIME-Version: 1.0');
$this -> add_header('X-Priority: 3');
$this -> add_header('X-MSMail-Priority: Normal');
$this -> add_header('X-Mailer: PHP/'.phpversion());
$this -> add_header('Return-Path: '.$this -> name_sender.' <'.$this -> email_sender.'>');
$this -> add_header('Reply-To: '.$this -> name_sender.' <'.$this -> email_sender.'>');
if(count($this -> cc != 0)) { // Als Carbon Copy is ingesteld, maak de header
$cc = implode(', ', $this -> cc);
$this -> add_header('Cc: '.$cc.'');
}
if(count($this -> bcc != 0)) { // Als Blind Carbon Copy is ingesteld, maak de header
$bcc = implode(', ', $this -> bcc);
$this -> add_header('Bcc: '.$bcc.'');
}
$this -> add_header('To: '.$this -> name_recipient.' <'.$this -> email_recipient.'>');
$this -> add_header('From: '.$this -> name_sender.' <'.$this -> email_sender.'>');
$headers = implode("\n", $this -> headers);
return $headers;
}
}
/*
* @Name Weet ik veel meel:D
* @Author Mark Pieper
* @Date 23-01-07
* @Todo Bijlagen
?>
*/
class Mail {
/**
* Email onderwerp
*/
protected $subject;
/**
* Email bericht
*/
protected $msg;
/**
* Email ontvanger
*/
protected $email_recipient;
/**
* Naam ontvanger
*/
protected $name_recipient;
/**
* Email zender
*/
protected $email_sender;
/**
* Naam zender
*/
protected $name_sender;
/**
* Carbon Copy
*/
protected $cc = array();
/**
* Blind Carbon Copy
*/
protected $bcc = array();
/**
* Email headers
*/
protected $headers = array();
/**
* Constructor
* @param: $content_type = html of text
*/
public function __construct($content_type = 'text') {
if($content_type == 'html') {
$this -> add_header('Content-Type: text/html; charset=iso-8859-1');
}
else
{
$this -> add_header('Content-Type: text/plain; charset=iso-8859-1');
}
$this -> add_msg('');
}
/**
* Verzend de email
*/
public function send_mail() {
$header = $this -> make_headers();
if(mail($this -> email_recipient, $this -> subject, $this -> msg, $header)) {
return 'Versturen gelukt';
}
else
{
trigger_error('<p><strong>Er is een fout opgetreden bij het verzenden van de email!</strong></p>');
}
}
/**
* Stel het onderwerp in
* @param: $subject = het onderwerp van de email
*/
public function set_subject($subject) {
$this -> subject = $subject;
}
/**
* Stel de naam en de email van de ontvanger in
* @param: $name = de naam van de ontvanger
* @param: $email = het emailadres van de ontvanger
*/
public function set_recipient($name, $email) {
$this -> name_recipient = $name;
$this -> email_recipient = $email;
}
/**
* Stel de naam en de email van de verzender in
* @param: $name = de naam van de verzender
* @param: $email = het emailadres van de verzender
*/
public function set_sender($name, $email) {
$this -> name_sender = $name;
$this -> email_sender = $email;
}
/**
* Voeg een CC toe
* @param: $cc = Carbon Copy (Mag een array zijn)
*/
public function add_cc($cc) {
if(is_array($cc)) {
foreach($cc as $waarde) {
$this -> cc[] = $waarde;
}
}
else
{
$this -> cc[] = $cc;
}
}
/**
* Maak het bericht
* @param: $msg = het bericht van de email
*/
public function add_msg($msg) {
$this -> msg .= $msg;
}
/**
* Voeg een BCC toe
* @param: $cc = Blind Carbon Copy (Mag een array zijn)
*/
public function add_bcc($bcc) {
if(is_array($bcc)) {
foreach($bcc as $waarde) {
$this -> bcc[] = $waarde;
}
}
else
{
$this -> bcc[] = $bcc;
}
}
/*** Protected Functions ***/
/**
* @param: $header = De header die moet worden toegevoegd
*/
protected function add_header($header) {
$replace = array("\n", "\r");
$header = str_replace($replace, '', $header);
$this -> headers[] = $header."\r\n";
}
/**
* Maak de headers, en voeg ze toe
*/
protected function make_headers() {
$this -> add_header('MIME-Version: 1.0');
$this -> add_header('X-Priority: 3');
$this -> add_header('X-MSMail-Priority: Normal');
$this -> add_header('X-Mailer: PHP/'.phpversion());
$this -> add_header('Return-Path: '.$this -> name_sender.' <'.$this -> email_sender.'>');
$this -> add_header('Reply-To: '.$this -> name_sender.' <'.$this -> email_sender.'>');
if(count($this -> cc != 0)) { // Als Carbon Copy is ingesteld, maak de header
$cc = implode(', ', $this -> cc);
$this -> add_header('Cc: '.$cc.'');
}
if(count($this -> bcc != 0)) { // Als Blind Carbon Copy is ingesteld, maak de header
$bcc = implode(', ', $this -> bcc);
$this -> add_header('Bcc: '.$bcc.'');
}
$this -> add_header('To: '.$this -> name_recipient.' <'.$this -> email_recipient.'>');
$this -> add_header('From: '.$this -> name_sender.' <'.$this -> email_sender.'>');
$headers = implode("\n", $this -> headers);
return $headers;
}
}