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(dirname(__FILE__).'/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
21error_reporting(E_ALL & ~E_STRICT);
22ini_set("SMTP", "localhost");
23ini_set("smtp_port", 2525);
24ini_set("sendmail_from", "user@example.com");
25
26echo "*** Testing mail() : basic functionality ***\n";
27require_once(dirname(__FILE__).'/mail_include.inc');
28$subject_prefix = "!**PHPT**!";
29
30$to = "$username";
31$subject = "$subject_prefix: Basic PHPT test for mail() function";
32$message = <<<HERE
33Description
34bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
35Send an email message
36HERE;
37
38$res = mail($to, $subject, $message);
39
40if ($res !== true) {
41	exit("TEST COMPLETED : Unable to send test email\n");
42} else {
43	echo "Msg sent OK\n";
44}
45
46// Search for email message on the mail server using imap.
47$imap_stream = imap_open($default_mailbox, $username, $password);
48if ($imap_stream === false) {
49	echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
50	return false;
51}
52
53$found = false;
54$repeat_count = 20; // we will repeat a max of 20 times
55while (!$found && $repeat_count > 0) {
56
57	// sleep for a while to allow msg to be delivered
58	sleep(1);
59
60	$current_msg_count = imap_check($imap_stream)->Nmsgs;
61
62	// Iterate over recent msgs to find the one we sent above
63	for ($i = 1; $i <= $current_msg_count; $i++) {
64		// get hdr details
65		$hdr = imap_headerinfo($imap_stream, $i);
66
67		if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
68			echo "Id of msg just sent is $i\n";
69			echo ".. delete it\n";
70			imap_delete($imap_stream, $i);
71			$found = true;
72			break;
73		}
74	}
75
76	$repeat_count -= 1;
77}
78
79if (!$found) {
80	echo "TEST FAILED: email not delivered\n";
81} else {
82	echo "TEST PASSED: Msgs sent and deleted OK\n";
83}
84
85imap_close($imap_stream, CL_EXPUNGE);
86?>
87===Done===
88--EXPECTF--
89*** Testing mail() : basic functionality ***
90
91Warning: mail(): Failed to connect to mailserver at "localhost" port 2525, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in %s on line %d
92TEST COMPLETED : Unable to send test email
93