Umm, ok. I'll get more specific then since I thought in my last post using that solution, which does echo the string properly, would fix things. Still got a problem. Posting rather long pre-written response here (sorry, I just don't want to be ommissive in details!)
I'll have to go into some detail so others can reproduce this issue that I thought was resolved. Basically, a page has a form that gets filled in with a name and email address. Both of those fields are to be used to send authenticated SMTP email per the example given at http://www.phpmaniac.net/wiki/index.php/Pear_Mail#Sending_using_authenticated_SMTP (this same example is actually all over the web).
I sometimes get email where the email client (OE in my case) will display the To column as a name such as, just for example, "Site Admin" instead of something like "username@mydomain.com". In other words, if you look at the header of the email message properties you'd exactly see:
To: Site Admin <username@mydomain.com>
and the same thing can occur with the email From header as in:
From: My Emailer <username@mydomain.com>
Anyway, based on that Pear Mail example shown at the above link I used a slight modificatin of it in this way to build email headers:
// Constructing the email
$sender = "myaccount@mydomain.com";
$from = "This Application <myaccount@mydomain.com>";
$replyto = "forsorting@mydomain.com";
// $recipient=htmlspecialchars($POST[newname]." <".$POST['newemail'].">");
$TheEmail=$_POST['newemail'];
$recipient = "$TheEmail";
$subject = "Your Login information.";
$text = "$TheText";
$html = $TheHTML;
...
$headers = array(
'Sender' => $sender,
'Return-Path' => $sender,
'Reply-To' => $replyto,
'From' => $from,
'Subject' => $subject,
'To' => $recipient
);
It works fine, when I receive the test email in the client the From header shows in message properties as:
This Application <myaccount@mydomain.com>
But here's where the problem comes in. Notice that in my code I had to comment out one way of sending the $recipient header. That's because if I use it instead of using the way I do it as shown, I'll get a validation error from the email server being connectd to. Even though the commented out section for $recipient will echo with the proper looking fomat as in:
User Name <useraccount@userdomain.com>
it just will not validate (so says the server). However, if I simply put the same exact text manually in normal quotes:
$recipient="User Name <useraccount@userdomain.com>";
as I similarly do it in the $from variable, it doesn't have any validation problem! But, these 2 values must be computed, it cannot be static like that.
I thought the "htmlspecialchars" parameter would get rid of this issue, since it does echo exactly like what I put in quotes manually, but it isn't. Somehow it seems to be passing non prinatble characters to the email server regardless. I know this problem is occcuring because of the < character immediately to the left of the $_POST['newemail'] variable, but I don't know how to overcome this problem.
I don't know exactly what causes the problem, but I suspect it's in the way PHP is handing off the computed string to the $recipient variable. I'm asking if someone can duplicate this too (requires install of Pear Mail on your server) and determine where the problem lies. Is it a bug? Is there a workaround? Is my fairly new exposure to properly using PHP at fault? I'm wrongly using htmlspecialchars?
(I wanted to mark this thread unresolved, but I cannot. I previously thought it was resolved.)