@@ -181,6 +181,20 @@ static void php_mail_build_headers_elems(smart_str *s, zend_string *key, zval *v
181
181
} ZEND_HASH_FOREACH_END ();
182
182
}
183
183
184
+ #define PHP_MAIL_BUILD_HEADER_CHECK (target , s , key , val ) \
185
+ do { \
186
+ if (Z_TYPE_P(val) == IS_STRING) { \
187
+ php_mail_build_headers_elem(&s, key, val); \
188
+ } else if (Z_TYPE_P(val) == IS_ARRAY) { \
189
+ if (zend_string_equals_literal_ci(key, target)) { \
190
+ zend_type_error("Header \"%s\" must be of type string, array given", target); \
191
+ break; \
192
+ } \
193
+ php_mail_build_headers_elems(&s, key, val); \
194
+ } else { \
195
+ zend_type_error("Header \"%s\" must be of type array|string, %s given", ZSTR_VAL(key), zend_zval_value_name(val)); \
196
+ } \
197
+ } while(0)
184
198
185
199
PHPAPI zend_string * php_mail_build_headers (HashTable * headers )
186
200
{
@@ -219,7 +233,13 @@ PHPAPI zend_string *php_mail_build_headers(HashTable *headers)
219
233
} else if (zend_string_equals_literal_ci (key , "subject" )) {
220
234
zend_value_error ("The additional headers cannot contain the \"Subject\" header" );
221
235
} else {
222
- PHP_MAIL_BUILD_HEADER_DEFAULT (s , key , val );
236
+ if (Z_TYPE_P (val ) == IS_STRING ) {
237
+ php_mail_build_headers_elem (& s , key , val );
238
+ } else if (Z_TYPE_P (val ) == IS_ARRAY ) {
239
+ php_mail_build_headers_elems (& s , key , val );
240
+ } else {
241
+ zend_type_error ("Header \"%s\" must be of type array|string, %s given" , ZSTR_VAL (key ), zend_zval_value_name (val ));
242
+ }
223
243
}
224
244
225
245
if (EG (exception )) {
0 commit comments