both of the above examples are capable of having header injects if the variables for subject, msg, sender go unchecked.
here's an example of checking these fields for injections. you can call this function on any variable. use this function before forming your headers on the raw submitted fields.
it returns 1 if the variable pass's and 0 if it is finds an injection.
function SMTPInjectCheck($T_DATA_CLEAN)
{
if (!empty($T_DATA_CLEAN)) {
//check for header injection
$T_DATA_CLEAN=str_replace("%20", " ", $T_DATA_CLEAN);
if (eregi("\r", $T_DATA_CLEAN) || eregi("\n", $T_DATA_CLEAN) || eregi("Content-", $T_DATA_CLEAN)){
return 0;
} else {
return 1;
}
} else {
//empty
return 1;
}
}