1--TEST--
2Test mail() function : basic functionality
3--SKIPIF--
4<?php
5if( substr(PHP_OS, 0, 3) != 'WIN' ) {
6   die('skip...Windows only test');
7}
8
9require_once(__DIR__.'/mail_skipif.inc');
10?>
11--INI--
12max_execution_time = 120
13--FILE--
14<?php
15/* Prototype  : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
16 * Description: Send an email message
17 * Source code: ext/standard/mail.c
18 * Alias to functions:
19 */
20
21ini_set("SMTP", "localhost");
22ini_set("smtp_port", 25);
23
24echo "*** Testing mail() : basic functionality ***\n";
25require_once(__DIR__.'/mail_include.inc');
26$subject_prefix = "!**PHPT**!";
27
28$to = "$username";
29$subject = "$subject_prefix: Basic PHPT test for mail() function";
30$message = <<<HERE
31Description
32bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
33Send an email message
34HERE;
35
36$res = mail($to, $subject, $message);
37
38if ($res !== true) {
39	exit("TEST COMPLETED : Unable to send test email\n");
40} else {
41	echo "Msg sent OK\n";
42}
43
44// Search for email message on the mail server using imap.
45$imap_stream = imap_open($default_mailbox, $username, $password);
46if ($imap_stream === false) {
47	echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
48	return false;
49}
50
51$found = false;
52$repeat_count = 20; // we will repeat a max of 20 times
53while (!$found && $repeat_count > 0) {
54
55	// sleep for a while to allow msg to be delivered
56	sleep(1);
57
58	$current_msg_count = imap_check($imap_stream)->Nmsgs;
59
60	// Iterate over recent msgs to find the one we sent above
61	for ($i = 1; $i <= $current_msg_count; $i++) {
62		// get hdr details
63		$hdr = imap_headerinfo($imap_stream, $i);
64
65		if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
66			echo "Id of msg just sent is $i\n";
67			echo ".. delete it\n";
68			imap_delete($imap_stream, $i);
69			$found = true;
70			break;
71		}
72	}
73
74	$repeat_count -= 1;
75}
76
77if (!$found) {
78	echo "TEST FAILED: email not delivered\n";
79} else {
80	echo "TEST PASSED: Msgs sent and deleted OK\n";
81}
82
83imap_close($imap_stream, CL_EXPUNGE);
84?>
85===Done===
86--EXPECTF--
87*** Testing mail() : basic functionality ***
88
89Warning: mail(): Bad Message Return Path in %s on line %d
90TEST COMPLETED : Unable to send test email
91