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