Annotation of embedaddon/php/ext/standard/tests/mail/mail_basic_alt2-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:
! 37: $res = mail($to, $subject, $message, $extra_headers);
! 38:
! 39: if ($res !== true) {
! 40: exit("TEST FAILED : Unable to send test email\n");
! 41: } else {
! 42: echo "Msg sent OK\n";
! 43: }
! 44:
! 45: // Search for email message on the mail server using imap.
! 46: $imap_stream = imap_open($default_mailbox, $username, $password);
! 47: if ($imap_stream === false) {
! 48: echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
! 49: return false;
! 50: }
! 51:
! 52: $found = false;
! 53: $repeat_count = 20; // we will repeat a max of 20 times
! 54: while (!$found && $repeat_count > 0) {
! 55:
! 56: // sleep for a while to allow msg to be delivered
! 57: sleep(1);
! 58:
! 59: $current_msg_count = imap_check($imap_stream)->Nmsgs;
! 60:
! 61: // Iterate over recent msgs to find the one we sent above
! 62: for ($i = 1; $i <= $current_msg_count; $i++) {
! 63: // get hdr details
! 64: $hdr = imap_headerinfo($imap_stream, $i);
! 65:
! 66: if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
! 67: echo "Id of msg just sent is $i\n";
! 68: echo ".. delete it\n";
! 69: imap_delete($imap_stream, $i);
! 70: $found = true;
! 71: break;
! 72: }
! 73: }
! 74:
! 75: $repeat_count -= 1;
! 76: }
! 77:
! 78: if (!$found) {
! 79: echo "TEST FAILED: email not delivered\n";
! 80: } else {
! 81: echo "TEST PASSED: Msgs sent and deleted OK\n";
! 82: }
! 83:
! 84: imap_close($imap_stream, CL_EXPUNGE);
! 85: ?>
! 86: ===Done===
! 87: --EXPECTF--
! 88: *** Testing mail() : basic functionality ***
! 89: Msg sent OK
! 90: Id of msg just sent is %d
! 91: .. delete it
! 92: TEST PASSED: Msgs sent and deleted OK
! 93: ===Done===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>