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