note 87653 modified in function.mail by danbrown

From: Date: Mon, 15 Dec 2008 15:00:18 +0000
Subject: note 87653 modified in function.mail by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148171@lists.php.net to get a copy of this message
I tried the example provided by [hn at nesland dot net] but it didn't quite work, as the error: Fatal error: Cannot redeclare mail() was encountered. Also, the runkit_function_rename() caused apache to exit with Segmentation fault (11) This works like a charm: <?PHP @dl("runkit.so"); @runkit_function_copy("mail", "__org_mail"); @runkit_function_remove("mail"); @runkit_function_copy("__new_mail", "mail"); @runkit_function_remove("__new_mail"); function __new_mail($to, $subject, $message, $additional_headers = null, $additional_parameters = null) { /* do your own mail function checks here */ return __org_mail($to, $subject, $message, $additional_headers, $additional_parameters); } ?> Atleast it worked for me, stripping newlines from $to, $subject, removing unwanted headers from $additional_headers and adding new headers to $additional_headers for debugging - this way I'll be able to track the origin of the mail using the headers. You'll need enable_dl = On in your php.ini and also runkit.internal_override = "1" I wanted to remove the execution of __org_mail(), so I tried to add this to disable_functions in php.ini but that didn't seem to work, so be aware that the original function can still be executed, and found by using get_defined_functions(). --was-- I tried the example provided by <a href="#78934">[hn at nesland dot net]</a> but it didn't quite work, as the error: Fatal error: Cannot redeclare mail() was encountered. Also, the runkit_function_rename() caused apache to exit with Segmentation fault (11) This works like a charm: <?PHP @dl("runkit.so"); @runkit_function_copy("mail", "__org_mail"); @runkit_function_remove("mail"); @runkit_function_copy("__new_mail", "mail"); @runkit_function_remove("__new_mail"); function __new_mail($to, $subject, $message, $additional_headers = null, $additional_parameters = null) { /* do your own mail function checks here */ return __org_mail($to, $subject, $message, $additional_headers, $additional_parameters); } ?> Atleast it worked for me, stripping newlines from $to, $subject, removing unwanted headers from $additional_headers and adding new headers to $additional_headers for debugging - this way I'll be able to track the origin of the mail using the headers. You'll need enable_dl = On in your php.ini and also runkit.internal_override = "1" I wanted to remove the execution of __org_mail(), so I tried to add this to disable_functions in php.ini but that didn't seem to work, so be aware that the original function can still be executed, and found by using get_defined_functions(). http://php.net/manual/en/function.mail.php

« previous php.notes (#148171) next »