您需要htmlspecialchars()
在 to/from 上应用功能:
// You need to apply htmlspecialchars() function on to/from:
$from = htmlspecialchars($Parser->getHeader('from'));
$to = htmlspecialchars($Parser->getHeader('to'));
// the above code will give you something like:
// John Smith <john@smith.com>
// so to get the email address we need to use explode() function:
function get_email_address($input){
$input = explode('<', $input);
$output = str_replace('>', '', $input);
$name = $output[0]; // THE NAME
$email = $output[1]; // THE EMAIL ADDRESS
return $email;
}
$from = htmlspecialchars($Parser->getHeader('from'));
echo $from = get_email_address($from); // NOW THIS IS THE EMAIL
$to = htmlspecialchars($Parser->getHeader('to'));
echo $from = get_email_address($to) // NOW THIS IS THE EMAIL