mail_basic_alt3-win32.phpt 2.3 KB

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