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