mail_basic_alt4-win32.phpt 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. $extra_parameters = "addons"; // should be ignored
  32. $res = mail($to, $subject, $message, $extra_headers, $extra_parameters);
  33. if ($res !== true) {
  34. exit("TEST FAILED : Unable to send test email\n");
  35. } else {
  36. echo "Msg sent OK\n";
  37. }
  38. // Search for email message on the mail server using imap.
  39. $imap_stream = imap_open($default_mailbox, $username, $password);
  40. if ($imap_stream === false) {
  41. echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
  42. return false;
  43. }
  44. $found = false;
  45. $repeat_count = 20; // we will repeat a max of 20 times
  46. while (!$found && $repeat_count > 0) {
  47. // sleep for a while to allow msg to be delivered
  48. sleep(1);
  49. $current_msg_count = imap_check($imap_stream)->Nmsgs;
  50. // Iterate over recent msgs to find the one we sent above
  51. for ($i = 1; $i <= $current_msg_count; $i++) {
  52. // get hdr details
  53. $hdr = imap_headerinfo($imap_stream, $i);
  54. if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
  55. echo "Id of msg just sent is $i\n";
  56. echo ".. delete it\n";
  57. imap_delete($imap_stream, $i);
  58. $found = true;
  59. break;
  60. }
  61. }
  62. $repeat_count -= 1;
  63. }
  64. if (!$found) {
  65. echo "TEST FAILED: email not delivered\n";
  66. } else {
  67. echo "TEST PASSED: Msgs sent and deleted OK\n";
  68. }
  69. imap_close($imap_stream, CL_EXPUNGE);
  70. ?>
  71. ===Done===
  72. --EXPECTF--
  73. *** Testing mail() : basic functionality ***
  74. Msg sent OK
  75. Id of msg just sent is %d
  76. .. delete it
  77. TEST PASSED: Msgs sent and deleted OK
  78. ===Done===