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