1--TEST--
2Test mail() function : basic functionality (win)
3--SKIPIF--
4<?php require_once __DIR__.'/mail_windows_skipif.inc'; ?>
5--INI--
6SMTP=localhost
7smtp_port=25
8--FILE--
9<?php
10
11require_once __DIR__.'/mail_util.inc';
12$users = MailBox::USERS;
13
14$cases = [
15    [
16        'from' => 'from@example.com',
17        'premise' => function ($from, $to, $subject, $message) {
18            ini_set('sendmail_from', $from);
19            return mail($to, $subject, $message);
20        }
21    ],
22    [
23        'from' => 'ex_from@example.com',
24        'premise' => function ($from, $to, $subject, $message) {
25            ini_restore('sendmail_from');
26            $headers = "from: {$from}";
27            return mail($to, $subject, $message, $headers);
28        }
29    ],
30    [
31        'from' => 'ex_from@example.com',
32        'premise' => function ($from, $to, $subject, $message) {
33            ini_restore('sendmail_from');
34            $headers = "FRom: {$from}";
35            return mail($to, $subject, $message, $headers);
36        }
37    ],
38    [
39        'from' => 'ex_from@example.com',
40        'premise' => function ($from, $to, $subject, $message) {
41            ini_restore('sendmail_from');
42            $headers = "from: {$from}";
43            $parameters = 'addons'; // should be ignored
44            return mail($to, $subject, $message, $headers, $parameters);
45        }
46    ],
47];
48
49foreach ($cases as $index => ['from' => $from, 'premise' => $premise]) {
50    echo "========== Case {$index} ==========\n";
51
52    $to = $users[$index];
53    $subject = "{$index}: Basic PHPT test for mail() function";
54    $message = <<<HERE
55Description
56bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
57Send an email message
58HERE;
59
60    $res = $premise($from, $to, $subject, $message);
61
62    if ($res !== true) {
63        die("Unable to send the email.\n");
64    }
65
66    echo "Email sent.\n";
67
68    $mailBox = MailBox::login($to);
69    $mail = $mailBox->getMailsBySubject($subject);
70    $mailBox->logout();
71
72    if ($mail->isAsExpected($from, $to, $subject, $message)) {
73        echo "Found the email.\n\n";
74    }
75}
76?>
77--CLEAN--
78<?php
79require_once __DIR__.'/mail_util.inc';
80for ($i = 0; $i <= 3; $i++) {
81    $subject = "{$i}: Basic PHPT test for mail() function";
82    $mailBox = MailBox::login(MailBox::USERS[$i]);
83    $mailBox->deleteMailsBySubject($subject);
84    $mailBox->logout();
85}
86?>
87--EXPECT--
88========== Case 0 ==========
89Email sent.
90Found the email.
91
92========== Case 1 ==========
93Email sent.
94Found the email.
95
96========== Case 2 ==========
97Email sent.
98Found the email.
99
100========== Case 3 ==========
101Email sent.
102Found the email.
103