mail_basic7.phpt 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. --TEST--
  2. Test mail() function : array extra header basic functionality
  3. --INI--
  4. sendmail_path={MAIL:mailBasic7.out}
  5. mail.add_x_header = Off
  6. --FILE--
  7. <?php
  8. error_reporting(-1);
  9. echo "*** Testing mail() : basic functionality ***\n";
  10. echo "\n\n************* TEST ******************\n";
  11. // Should pass
  12. // Initialise all required variables
  13. $to = 'user@example.com';
  14. $subject = 'Test Subject';
  15. $message = 'A Message';
  16. $additional_headers = array(
  17. 'KHeaders' => 'aaaa',
  18. 'bcc'=>'foo@bar',
  19. 'foo'=>
  20. array(
  21. "bar\r\n hoge",
  22. "bar\r\n\t fuga",
  23. ),
  24. );
  25. $outFile = "mailBasic7.out";
  26. @unlink($outFile);
  27. echo "-- All Mail Content Parameters --\n";
  28. // Calling mail() with all additional headers
  29. var_dump(mail($to, $subject, $message, $additional_headers));
  30. echo file_get_contents($outFile);
  31. unlink($outFile);
  32. echo "\n\n************* TEST ******************\n";
  33. // Should fail all
  34. // Initialise all required variables
  35. $to = 'user@example.com';
  36. $subject = 'Test Subject';
  37. $message = 'A Message';
  38. try {
  39. mail($to, $subject, $message, ['orig-date' => array('foo1')]);
  40. } catch (TypeError|ValueError $exception) {
  41. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  42. }
  43. try {
  44. mail($to, $subject, $message, ['from' => array('foo2')]);
  45. } catch (TypeError|ValueError $exception) {
  46. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  47. }
  48. try {
  49. mail($to, $subject, $message, ['sender' => array('foo3')]);
  50. } catch (TypeError|ValueError $exception) {
  51. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  52. }
  53. try {
  54. mail($to, $subject, $message, ['reply-to' => array('foo4')]);
  55. } catch (TypeError|ValueError $exception) {
  56. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  57. }
  58. try {
  59. mail($to, $subject, $message, ['to' => array('foo5')]);
  60. } catch (TypeError|ValueError $exception) {
  61. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  62. }
  63. try {
  64. mail($to, $subject, $message, ['bcc' => array('foo6')]);
  65. } catch (TypeError|ValueError $exception) {
  66. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  67. }
  68. try {
  69. mail($to, $subject, $message, ['message-id' => array('foo7')]);
  70. } catch (TypeError|ValueError $exception) {
  71. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  72. }
  73. try {
  74. mail($to, $subject, $message, ['in-reply-to'=> array('foo8')]);
  75. } catch (TypeError|ValueError $exception) {
  76. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  77. }
  78. echo "\n\n************* TEST ******************\n";
  79. // Should fail all
  80. // Initialise all required variables
  81. $to = 'user@example.com';
  82. $subject = 'Test Subject';
  83. $message = 'A Message';
  84. try {
  85. mail($to, $subject, $message, ['foo1' => array('foo2'=>'bar1')]);
  86. } catch (TypeError|ValueError $exception) {
  87. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  88. }
  89. try {
  90. mail($to, $subject, $message, ['foo2' => array('foo2', array('foo3'))]);
  91. } catch (TypeError|ValueError $exception) {
  92. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  93. }
  94. try {
  95. mail($to, $subject, $message, ['foo3' => array(123)]);
  96. } catch (TypeError|ValueError $exception) {
  97. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  98. }
  99. try {
  100. mail($to, $subject, $message, ['foo4' => array(123.456)]);
  101. } catch (TypeError|ValueError $exception) {
  102. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  103. }
  104. try {
  105. mail($to, $subject, $message, ['foo5' => array(FALSE)]);
  106. } catch (TypeError|ValueError $exception) {
  107. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  108. }
  109. try {
  110. mail($to, $subject, $message, ['foo6' => array(NULL)]);
  111. } catch (TypeError|ValueError $exception) {
  112. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  113. }
  114. try {
  115. mail($to, $subject, $message, ['foo7' => array(new StdClass)]);
  116. } catch (TypeError|ValueError $exception) {
  117. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  118. }
  119. echo "\n\n************* TEST ******************\n";
  120. // Should fail most
  121. // Initialise all required variables
  122. $to = 'user@example.com';
  123. $subject = 'Test Subject';
  124. $message = 'A Message';
  125. $outFile = "mailBasic7.out";
  126. @unlink($outFile);
  127. try {
  128. mail($to, $subject, $message, ['*:foo1' => array('bar1')]);
  129. } catch (TypeError|ValueError $exception) {
  130. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  131. }
  132. try {
  133. mail($to, $subject, $message, ['foo2:::' => array('bar1')]);
  134. } catch (TypeError|ValueError $exception) {
  135. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  136. }
  137. try {
  138. mail($to, $subject, $message, ['foo3()' => array('bar1')]);
  139. } catch (TypeError|ValueError $exception) {
  140. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  141. }
  142. try {
  143. mail($to, $subject, $message, ['foo4@' => array('bar1')]);
  144. } catch (TypeError|ValueError $exception) {
  145. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  146. }
  147. try {
  148. mail($to, $subject, $message, ['foo5|' => array('bar1')]);
  149. } catch (TypeError|ValueError $exception) {
  150. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  151. }
  152. try {
  153. mail($to, $subject, $message, ["\0foo6" => array('bar1')]);
  154. } catch (TypeError|ValueError $exception) {
  155. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  156. }
  157. try {
  158. mail($to, $subject, $message, ["foo7\0" => array('bar1')]);
  159. } catch (TypeError|ValueError $exception) {
  160. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  161. }
  162. try {
  163. mail($to, $subject, $message, ["foo8" => array()]);
  164. } catch (TypeError|ValueError $exception) {
  165. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  166. }
  167. var_dump(mail($to, $subject, $message, ["foo9" => '%&$#!']));
  168. echo file_get_contents($outFile);
  169. unlink($outFile);
  170. try {
  171. mail($to, $subject, $message, ["foo10" => "abc\0\tdef"]);
  172. } catch (TypeError|ValueError $exception) {
  173. echo get_class($exception) . ": " . $exception->getMessage() . "\n";
  174. }
  175. ?>
  176. --EXPECTF--
  177. *** Testing mail() : basic functionality ***
  178. ************* TEST ******************
  179. -- All Mail Content Parameters --
  180. bool(true)
  181. To: user@example.com
  182. Subject: Test Subject
  183. KHeaders: aaaa
  184. bcc: foo@bar
  185. foo: bar
  186. hoge
  187. foo: bar
  188. fuga
  189. A Message
  190. ************* TEST ******************
  191. TypeError: Header "orig-date" must be of type string, array given
  192. TypeError: Header "from" must be of type string, array given
  193. TypeError: Header "sender" must be of type string, array given
  194. TypeError: Header "reply-to" must be of type string, array given
  195. ValueError: The additional headers cannot contain the "To" header
  196. TypeError: Header "bcc" must be of type string, array given
  197. TypeError: Header "message-id" must be of type string, array given
  198. TypeError: Header "in-reply-to" must be of type string, array given
  199. ************* TEST ******************
  200. TypeError: Header "foo1" must only contain numeric keys, "foo2" found
  201. TypeError: Header "foo2" must only contain values of type string, array found
  202. TypeError: Header "foo3" must only contain values of type string, int found
  203. TypeError: Header "foo4" must only contain values of type string, float found
  204. TypeError: Header "foo5" must only contain values of type string, bool found
  205. TypeError: Header "foo6" must only contain values of type string, null found
  206. TypeError: Header "foo7" must only contain values of type string, stdClass found
  207. ************* TEST ******************
  208. ValueError: Header name "*:foo1" contains invalid characters
  209. ValueError: Header name "foo2:::" contains invalid characters
  210. ValueError: Header name "" contains invalid characters
  211. ValueError: Header name "foo7" contains invalid characters
  212. bool(true)
  213. To: user@example.com
  214. Subject: Test Subject
  215. foo9: %&$#!
  216. A Message
  217. ValueError: Header "foo10" has invalid format, or contains invalid characters