1--TEST--
2Test mail() function : basic functionality
3--INI--
4sendmail_path=tee mailBasic6.out >/dev/null
5mail.add_x_header = Off
6--SKIPIF--
7<?php
8if(substr(PHP_OS, 0, 3) == "WIN")
9  die("skip Won't run on Windows");
10?>
11--FILE--
12<?php
13echo "*** Testing mail() : basic functionality ***\n";
14
15
16// Valid header
17$to = 'user@example.com';
18$subject = 'Test Subject';
19$message = 'A Message';
20$additional_headers = "HEAD1: a\r\nHEAD2: b\r\n";
21$outFile = "mailBasic6.out";
22@unlink($outFile);
23
24echo "-- Valid Header --\n";
25// Calling mail() with all additional headers
26var_dump( mail($to, $subject, $message, $additional_headers) );
27echo file_get_contents($outFile);
28unlink($outFile);
29
30// Valid header
31$additional_headers = "HEAD1: a\nHEAD2: b\n";
32@unlink($outFile);
33
34echo "-- Valid Header --\n";
35// Calling mail() with all additional headers
36var_dump( mail($to, $subject, $message, $additional_headers) );
37echo @file_get_contents($outFile);
38@unlink($outFile);
39
40// Valid header
41// \r is accepted as valid. This may be changed to invalid.
42$additional_headers = "HEAD1: a\rHEAD2: b\r";
43@unlink($outFile);
44
45echo "-- Valid Header --\n";
46// Calling mail() with all additional headers
47var_dump( mail($to, $subject, $message, $additional_headers) );
48echo @file_get_contents($outFile);
49@unlink($outFile);
50
51//===============================================================================
52// Invalid header
53$additional_headers = "\nHEAD1: a\nHEAD2: b\n";
54@unlink($outFile);
55
56echo "-- Invalid Header - preceding newline--\n";
57// Calling mail() with all additional headers
58var_dump( mail($to, $subject, $message, $additional_headers) );
59echo @file_get_contents($outFile);
60@unlink($outFile);
61
62// Invalid header
63$additional_headers = "\rHEAD1: a\nHEAD2: b\r";
64@unlink($outFile);
65
66echo "-- Invalid Header - preceding newline--\n";
67// Calling mail() with all additional headers
68var_dump( mail($to, $subject, $message, $additional_headers) );
69echo @file_get_contents($outFile);
70@unlink($outFile);
71
72// Invalid header
73$additional_headers = "\r\nHEAD1: a\r\nHEAD2: b\r\n";
74@unlink($outFile);
75
76echo "-- Invalid Header - preceding newline--\n";
77// Calling mail() with all additional headers
78var_dump( mail($to, $subject, $message, $additional_headers) );
79echo @file_get_contents($outFile);
80@unlink($outFile);
81
82// Invalid header
83$additional_headers = "\r\n\r\nHEAD1: a\r\nHEAD2: b\r\n";
84@unlink($outFile);
85
86echo "-- Invalid Header - preceding newline--\n";
87// Calling mail() with all additional headers
88var_dump( mail($to, $subject, $message, $additional_headers) );
89echo @file_get_contents($outFile);
90@unlink($outFile);
91
92// Invalid header
93$additional_headers = "\n\nHEAD1: a\r\nHEAD2: b\r\n";
94@unlink($outFile);
95
96echo "-- Invalid Header - preceding newline--\n";
97// Calling mail() with all additional headers
98var_dump( mail($to, $subject, $message, $additional_headers) );
99echo @file_get_contents($outFile);
100@unlink($outFile);
101
102// Invalid header
103$additional_headers = "\r\rHEAD1: a\r\nHEAD2: b\r\n";
104@unlink($outFile);
105
106echo "-- Invalid Header - preceding newline--\n";
107// Calling mail() with all additional headers
108var_dump( mail($to, $subject, $message, $additional_headers) );
109echo @file_get_contents($outFile);
110@unlink($outFile);
111
112// Invalid header
113$additional_headers = "HEAD1: a\r\n\r\nHEAD2: b\r\n";
114@unlink($outFile);
115
116echo "-- Invalid Header - multiple newlines in the middle --\n";
117// Calling mail() with all additional headers
118var_dump( mail($to, $subject, $message, $additional_headers) );
119echo @file_get_contents($outFile);
120@unlink($outFile);
121
122// Invalid header
123$additional_headers = "HEAD1: a\r\n\nHEAD2: b\r\n";
124@unlink($outFile);
125
126echo "-- Invalid Header - multiple newlines in the middle --\n";
127// Calling mail() with all additional headers
128var_dump( mail($to, $subject, $message, $additional_headers) );
129echo @file_get_contents($outFile);
130@unlink($outFile);
131
132// Invalid header
133$additional_headers = "HEAD1: a\n\nHEAD2: b\r\n";
134@unlink($outFile);
135
136echo "-- Invalid Header - multiple newlines in the middle --\n";
137// Calling mail() with all additional headers
138var_dump( mail($to, $subject, $message, $additional_headers) );
139echo @file_get_contents($outFile);
140@unlink($outFile);
141
142// Invalid header
143$additional_headers = "HEAD1: a\r\rHEAD2: b\r\n";
144@unlink($outFile);
145
146echo "-- Invalid Header - multiple newlines in the middle --\n";
147// Calling mail() with all additional headers
148var_dump( mail($to, $subject, $message, $additional_headers) );
149echo @file_get_contents($outFile);
150@unlink($outFile);
151
152// Invalid header
153$additional_headers = "HEAD1: a\n\rHEAD2: b\r\n";
154@unlink($outFile);
155
156echo "-- Invalid Header - multiple newlines in the middle --\n";
157// Calling mail() with all additional headers
158var_dump( mail($to, $subject, $message, $additional_headers) );
159echo @file_get_contents($outFile);
160@unlink($outFile);
161
162// Invalid header
163$additional_headers = "HEAD1: a\n\r\nHEAD2: b\r\n";
164@unlink($outFile);
165
166echo "-- Invalid Header - multiple newlines in the middle --\n";
167// Calling mail() with all additional headers
168var_dump( mail($to, $subject, $message, $additional_headers) );
169echo @file_get_contents($outFile);
170@unlink($outFile);
171
172// Invalid header
173// Invalid, but PHP_FUNCTION(mail) trims newlines
174$additional_headers = "HEAD1: a\r\nHEAD2: b\r\n\n";
175@unlink($outFile);
176
177echo "-- Invalid Header - trailing newlines --\n";
178// Calling mail() with all additional headers
179var_dump( mail($to, $subject, $message, $additional_headers) );
180echo @file_get_contents($outFile);
181@unlink($outFile);
182
183// Invalid header
184// Invalid, but PHP_FUNCTION(mail) trims newlines
185$additional_headers = "HEAD1: a\r\nHEAD2: b\n\n";
186@unlink($outFile);
187
188echo "-- Invalid Header - trailing newlines --\n";
189// Calling mail() with all additional headers
190var_dump( mail($to, $subject, $message, $additional_headers) );
191echo @file_get_contents($outFile);
192@unlink($outFile);
193
194// Invalid header
195// Invalid, but PHP_FUNCTION(mail) trims newlines
196$additional_headers = "HEAD1: a\r\nHEAD2: b\n";
197@unlink($outFile);
198
199echo "-- Invalid Header - trailing newlines --\n";
200// Calling mail() with all additional headers
201var_dump( mail($to, $subject, $message, $additional_headers) );
202echo @file_get_contents($outFile);
203@unlink($outFile);
204
205// Invalid header
206// Invalid, but PHP_FUNCTION(mail) trims newlines
207$additional_headers = "HEAD1: a\r\nHEAD2: b\r";
208@unlink($outFile);
209
210echo "-- Invalid Header - trailing newlines --\n";
211// Calling mail() with all additional headers
212var_dump( mail($to, $subject, $message, $additional_headers) );
213echo @file_get_contents($outFile);
214@unlink($outFile);
215
216?>
217--EXPECTF--
218*** Testing mail() : basic functionality ***
219-- Valid Header --
220bool(true)
221To: user@example.com
222Subject: Test Subject
223HEAD1: a
224HEAD2: b
225
226A Message
227-- Valid Header --
228bool(true)
229To: user@example.com
230Subject: Test Subject
231HEAD1: a
232HEAD2: b
233
234A Message
235-- Valid Header --
236bool(true)
237To: user@example.com
238Subject: Test Subject
239HEAD1: a
239HEAD2: b
240
241A Message
242-- Invalid Header - preceding newline--
243
244Warning: mail(): Multiple or malformed newlines found in additional_header in %s/mail_basic6.php on line %d
245bool(false)
246-- Invalid Header - preceding newline--
247
248Warning: mail(): Multiple or malformed newlines found in additional_header in %s/mail_basic6.php on line %d
249bool(false)
250-- Invalid Header - preceding newline--
251
252Warning: mail(): Multiple or malformed newlines found in additional_header in %s/mail_basic6.php on line %d
253bool(false)
254-- Invalid Header - preceding newline--
255
256Warning: mail(): Multiple or malformed newlines found in additional_header in %s/mail_basic6.php on line %d
257bool(false)
258-- Invalid Header - preceding newline--
259
260Warning: mail(): Multiple or malformed newlines found in additional_header in %s/mail_basic6.php on line %d
261bool(false)
262-- Invalid Header - preceding newline--
263
264Warning: mail(): Multiple or malformed newlines found in additional_header in %s/mail_basic6.php on line %d
265bool(false)
266-- Invalid Header - multiple newlines in the middle --
267
268Warning: mail(): Multiple or malformed newlines found in additional_header in %s/mail_basic6.php on line %d
269bool(false)
270-- Invalid Header - multiple newlines in the middle --
271
272Warning: mail(): Multiple or malformed newlines found in additional_header in %s/mail_basic6.php on line %d
273bool(false)
274-- Invalid Header - multiple newlines in the middle --
275
276Warning: mail(): Multiple or malformed newlines found in additional_header in %s/mail_basic6.php on line %d
277bool(false)
278-- Invalid Header - multiple newlines in the middle --
279
280Warning: mail(): Multiple or malformed newlines found in additional_header in %s/mail_basic6.php on line %d
281bool(false)
282-- Invalid Header - multiple newlines in the middle --
283
284Warning: mail(): Multiple or malformed newlines found in additional_header in %s/mail_basic6.php on line %d
285bool(false)
286-- Invalid Header - multiple newlines in the middle --
287
288Warning: mail(): Multiple or malformed newlines found in additional_header in %s/mail_basic6.php on line %d
289bool(false)
290-- Invalid Header - trailing newlines --
291bool(true)
292To: user@example.com
293Subject: Test Subject
294HEAD1: a
295HEAD2: b
296
297A Message
298-- Invalid Header - trailing newlines --
299bool(true)
300To: user@example.com
301Subject: Test Subject
302HEAD1: a
303HEAD2: b
304
305A Message
306-- Invalid Header - trailing newlines --
307bool(true)
308To: user@example.com
309Subject: Test Subject
310HEAD1: a
311HEAD2: b
312
313A Message
314-- Invalid Header - trailing newlines --
315bool(true)
316To: user@example.com
317Subject: Test Subject
318HEAD1: a
319HEAD2: b
320
321A Message
322