Annotation of embedaddon/php/ext/standard/tests/mail/mail_basic_alt1-win32.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test mail() function : basic functionality 
                      3: --SKIPIF--
                      4: <?php 
                      5: 
                      6: if( substr(PHP_OS, 0, 3) != 'WIN' ) {
                      7:    die('skip...Windows only test');
                      8: }
                      9: 
                     10: require_once(dirname(__FILE__).'/mail_skipif.inc');
                     11: ?>
                     12: --INI--
                     13: max_execution_time = 120
                     14: --FILE--
                     15: <?php
                     16: /* Prototype  : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
                     17:  * Description: Send an email message 
                     18:  * Source code: ext/standard/mail.c
                     19:  * Alias to functions: 
                     20:  */
                     21: 
                     22: error_reporting(E_ALL & ~E_STRICT);
                     23: ini_set("SMTP", "localhost");
                     24: ini_set("smtp_port", 25);
                     25: ini_set("sendmail_from", "user@company.com");
                     26: 
                     27: echo "*** Testing mail() : basic functionality ***\n";
                     28: require_once(dirname(__FILE__).'/mail_include.inc');
                     29: $subject_prefix = "!**PHPT**!";
                     30: 
                     31: $to = "$username";
                     32: $subject = "$subject_prefix: Basic PHPT test for mail() function";
                     33: $message = <<<HERE
                     34: Description
                     35: bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
                     36: Send an email message
                     37: HERE;
                     38: 
                     39: $res = mail($to, $subject, $message);
                     40: 
                     41: if ($res !== true) {
                     42:        exit("TEST FAILED : Unable to send test email\n"); 
                     43: } else {
                     44:        echo "Msg sent OK\n";
                     45: }
                     46: 
                     47: // Search for email message on the mail server using imap.
                     48: $imap_stream = imap_open($default_mailbox, $username, $password);
                     49: if ($imap_stream === false) {
                     50:        echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
                     51:        return false;
                     52: }      
                     53: 
                     54: $found = false;
                     55: $repeat_count = 20; // we will repeat a max of 20 times 
                     56: while (!$found && $repeat_count > 0) {
                     57: 
                     58:        // sleep for a while to allow msg to be delivered
                     59:        sleep(1);
                     60: 
                     61:        $current_msg_count = imap_check($imap_stream)->Nmsgs;
                     62: 
                     63:        // Iterate over recent msgs to find the one we sent above
                     64:        for ($i = 1; $i <= $current_msg_count; $i++) {
                     65:                // get hdr details
                     66:                $hdr = imap_headerinfo($imap_stream, $i);  
                     67: 
                     68:                if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
                     69:                        echo "Id of msg just sent is $i\n"; 
                     70:                        echo ".. delete it\n"; 
                     71:                        imap_delete($imap_stream, $i);
                     72:                        $found = true;
                     73:                        break; 
                     74:                }
                     75:        }
                     76:        
                     77:        $repeat_count -= 1;
                     78: }
                     79: 
                     80: if (!$found) { 
                     81:        echo "TEST FAILED: email not delivered\n"; 
                     82: } else {
                     83:        echo "TEST PASSED: Msgs sent and deleted OK\n";
                     84: }
                     85: 
                     86: imap_close($imap_stream, CL_EXPUNGE);
                     87: ?>
                     88: ===Done===
                     89: --EXPECTF--
                     90: *** Testing mail() : basic functionality ***
                     91: Msg sent OK
                     92: Id of msg just sent is %d
                     93: .. delete it
                     94: TEST PASSED: Msgs sent and deleted OK
                     95: ===Done===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>