mail_variation_alt1-win32.phpt 2.5 KB

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