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