summaryrefslogtreecommitdiff
path: root/ext/standard/tests/mail/mail_basic_alt1-win32.phpt
blob: c48634e99c7624cafb34bbe1e0f7038589cbb9a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--TEST--
Test mail() function : basic functionality
--SKIPIF--
<?php

if( substr(PHP_OS, 0, 3) != 'WIN' ) {
   die('skip...Windows only test');
}

require_once(__DIR__.'/mail_skipif.inc');
?>
--INI--
max_execution_time = 120
--FILE--
<?php
/* Prototype  : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
 * Description: Send an email message
 * Source code: ext/standard/mail.c
 * Alias to functions:
 */

ini_set("SMTP", "localhost");
ini_set("smtp_port", 25);
ini_set("sendmail_from", "user@example.com");

echo "*** Testing mail() : basic functionality ***\n";
require_once(__DIR__.'/mail_include.inc');
$subject_prefix = "!**PHPT**!";

$to = "$username";
$subject = "$subject_prefix: Basic PHPT test for mail() function";
$message = <<<HERE
Description
bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
Send an email message
HERE;

$res = mail($to, $subject, $message);

if ($res !== true) {
	exit("TEST FAILED : Unable to send test email\n");
} else {
	echo "Msg sent OK\n";
}

// Search for email message on the mail server using imap.
$imap_stream = imap_open($default_mailbox, $username, $password);
if ($imap_stream === false) {
	echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
	return false;
}

$found = false;
$repeat_count = 20; // we will repeat a max of 20 times
while (!$found && $repeat_count > 0) {

	// sleep for a while to allow msg to be delivered
	sleep(1);

	$current_msg_count = imap_check($imap_stream)->Nmsgs;

	// Iterate over recent msgs to find the one we sent above
	for ($i = 1; $i <= $current_msg_count; $i++) {
		// get hdr details
		$hdr = imap_headerinfo($imap_stream, $i);

		if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
			echo "Id of msg just sent is $i\n";
			echo ".. delete it\n";
			imap_delete($imap_stream, $i);
			$found = true;
			break;
		}
	}

	$repeat_count -= 1;
}

if (!$found) {
	echo "TEST FAILED: email not delivered\n";
} else {
	echo "TEST PASSED: Msgs sent and deleted OK\n";
}

imap_close($imap_stream, CL_EXPUNGE);
?>
--EXPECTF--
*** Testing mail() : basic functionality ***
Msg sent OK
Id of msg just sent is %d
.. delete it
TEST PASSED: Msgs sent and deleted OK