Hello All,
I have made an e-mail forwarder that I want to filter out e-mail addresses.
It is all working except the REGEX.
I have NOT used REGEX before. Can someone tell me what I am doing wrong?
This script loads the e-mail as a file from the local e-mail folder on the
server.
$text = file_get_contents($directory . $filename);
$text = str_replace("\r\n", "\r", $text);
$text = str_replace("\r", "\n", $text);
$choppos = strpos($text, "\n\n");
$headers = substr($text, 0, $choppos);
$message = substr($text, $choppos + 2);
$subject = get_subject($headers);
$regex =
"/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?$/iD";
$message = preg_replace( $regex, '[e-mail prorected]', $message);
mail($to, $subject, $message, 'From: '. $from);
function get_subject($headers)
{
$headers = explode("\n", $headers);
foreach($headers as $header)
{
if(strtolower(substr($header, 0, 8)) == 'subject:')
{
$subject= substr($header, 8);
if(substr($subject, 0, 1) == ' ')
{
$subject = substr($subject, 1);
}
return $subject;
}
}
}