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