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