Annotation of embedaddon/php/ext/standard/tests/mail/mail_basic_alt4-win32.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test mail() function : basic functionality
! 3: --SKIPIF--
! 4: <?php
! 5: if( substr(PHP_OS, 0, 3) != 'WIN' ) {
! 6: die('skip...Windows only test');
! 7: }
! 8:
! 9: require_once(dirname(__FILE__).'/mail_skipif.inc');
! 10: ?>
! 11: --INI--
! 12: max_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:
! 21: error_reporting(E_ALL & ~E_STRICT);
! 22:
! 23: echo "*** Testing mail() : basic functionality ***\n";
! 24: require_once(dirname(__FILE__).'/mail_include.inc');
! 25: $subject_prefix = "!**PHPT**!";
! 26:
! 27: $to = "$username";
! 28: $subject = "$subject_prefix: Basic PHPT test for mail() function";
! 29: $message = <<<HERE
! 30: Description
! 31: bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
! 32: Send an email message
! 33: HERE;
! 34:
! 35: $extra_headers = "from: user@company.com";
! 36: $extra_parameters = "addons"; // should be ignored
! 37:
! 38: $res = mail($to, $subject, $message, $extra_headers, $extra_parameters);
! 39:
! 40: if ($res !== true) {
! 41: exit("TEST FAILED : 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);
! 48: if ($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
! 55: while (!$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:
! 79: if (!$found) {
! 80: echo "TEST FAILED: email not delivered\n";
! 81: } else {
! 82: echo "TEST PASSED: Msgs sent and deleted OK\n";
! 83: }
! 84:
! 85: imap_close($imap_stream, CL_EXPUNGE);
! 86: ?>
! 87: ===Done===
! 88: --EXPECTF--
! 89: *** Testing mail() : basic functionality ***
! 90: Msg sent OK
! 91: Id of msg just sent is %d
! 92: .. delete it
! 93: TEST PASSED: Msgs sent and deleted OK
! 94: ===Done===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>