Forum Moderators: coopster
The template looks like this:
--Begin Template
To: Joe McCarthy <joe@home.net>
From: Me <me@myhouse.net>
Subject: Hey!
This is the body of the message.
--End Template
And here it is some code for illustration.
# These are the fields I want to find (there are more)
$EmailFields[0] = 'To';
$EmailFields[1] = 'From';
$EmailFields[2] = 'Subject';# Load in the template
$file = file("MessageTemplate.txt");# Take each line, and regexp each header field
foreach ($file as $line_num => $line) {
foreach ($EmailFields as $Field) {if (preg_match("/^$Field {0,1}: {0,1}(.+)$/", $line, $matches)) {
# Got a match, record the
$Headers["$Field"] = $matches[1];
echo $Headers["$Field"] . "<BR>";
}
}
}
As I said, It works just fine as long as there are not brackets. Assuming the first line of the template is
"To: Joe McCarthy joe@home.net"
then the first entry in $Header would be
"Joe McCarthy joe@home.net"
But if I enclose an email address in brackets
"To: Joe McCarthy <joe@home.net>"
then the email address (and brackets) is not added to $Headers
"Joe McCarthy " (WITH the space at the end)
Anybody have an idea why? Thanks.
<?php
$a="To: Joe McCarthy <joe@home.net>";
echo($a."<br>");
$a= explode('<', $a);
$a=implode("", $a);
$a= explode('>', $a);
$a=implode("", $a);
echo($a);
?>
Browser output:
To: Joe McCarthy
To: Joe McCarthy joe@home.net
I'm sure this can be done more efficiently and with less code than mine.