1--TEST--
2Test mail() function : basic functionality (win)
3--SKIPIF--
4<?php die('skip test'); 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$from = ini_get('sendmail_from');
15
16$cases = [
17    [
18        'label' => 'From is not set',
19        'premise' => function () {
20            ini_set('SMTP', 'localhost');
21            ini_set('smtp_port', 25);
22        }
23    ],
24    [
25        'label' => 'Invalid port',
26        'premise' => function () {
27            ini_set('SMTP', 'localhost');
28            ini_set('smtp_port', 2525);
29            ini_set('sendmail_from', 'from@example.com');
30        }
31    ],
32    [
33        'label' => 'Invalid host',
34        'premise' => function () {
35            ini_set('SMTP', 'localplace');
36            ini_set('smtp_port', 25);
37            ini_set('sendmail_from', 'from@example.com');
38        }
39    ],
40];
41
42foreach ($cases as $index => ['label' => $label, 'premise' => $premise]) {
43    echo "========== {$label} ==========\n";
44
45    $premise();
46
47    $to = $users[$index];
48    $subject = "{$index}: Basic PHPT test for mail() function";
49    $message = <<<HERE
50Description
51bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
52Send an email message
53HERE;
54
55    $res = mail($to, $subject, $message);
56
57    if ($res === true) {
58        echo "Email sent.\n";
59    }
60
61    $mailBox = MailBox::login($to);
62    $mail = $mailBox->getMailsBySubject($subject);
63    $mailBox->logout();
64
65    if ($mail->count() > 0) {
66        echo "Found the email.\n\n";
67    }
68}
69?>
70--CLEAN--
71<?php
72require_once __DIR__.'/mail_util.inc';
73for ($i = 0; $i <= 2; $i++) {
74    $subject = "{$i}: Basic PHPT test for mail() function";
75    $mailBox = MailBox::login(MailBox::USERS[$i]);
76    $mailBox->deleteMailsBySubject($subject);
77    $mailBox->logout();
78}
79?>
80--EXPECTF--
81========== From is not set ==========
82
83Warning: mail(): Bad Message Return Path in %s on line %d
84========== Invalid port ==========
85
86Warning: 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
87========== Invalid host ==========
88
89Warning: mail(): Failed to connect to mailserver at "localplace" port 1025, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in %s on line %d
90
91