Hello,
I have a issue and have searched everywhere and cannot seem to come up with a
solution. I am assuming there is a regex I could use to fix this problem however
I am not very good with regex.
What I am trying to do is add to the scripot below to get the email address
from the person who sent the email. I got this script from the web and all
works great other than the fact I cannot get the actual email address from
the from field. It only give the 'Name' of the person.
I am also trying to figurew out a way to parse the email if it is in HTML and not
plain text.
PHP Code:
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// handle email
$lines = explode("\n", $email);
// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i = 0; $i < count($lines); $i++) {
if ($splittingheaders) {
// this is a header
$headers .= $lines[$i] . "\n";
// look out for special headers
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
// not a header, but message
$message .= $lines[$i] . "\n";
}
if (trim($lines[$i]) == "") {
// empty line, header section has ended
$splittingheaders = false;
}
}
If anyone could help me it would be greatly appreciated it.
Thanks in advance.
Regards,
Ray