27th Apr, 2007

phpMailer issue on IIS

I’ve just spent some time figuring our an issue I’ve had with PHPLinkDirectory running on IIS. I’m building a new directory site for SearchMann and decided to use an off-the-shelf package for doing this. The biggest problem I’m finding is that the majority of phpLD’s user base run the package on Apache where PHP runs better than on IIS. It’s not the language itself that’s the problem, more the capabilities of the platform. My biggest bug bear so far is the fact that there’s no equivalent of mod_rewrite on IIS, but that’s another story …

Anyway, the problem started when I tried sending email and started getting the following cryptic message:

Language string failed to load: instantiate

I spent some time trying to figure out why it wasn’t picking up the correct language file but then decided I should really be looking at the source of the problem. What was the error message it was trying to report?

Turns out the problem lay in the actual mail component not managing to send out email and trying to report an initialisation problem. I turned my attention to this and spent a substantial amount of time trying to figure out why.

Eventually the penny dropped! I had already come across this problem in the past while sending email from PHP. This is caused by the way the windows mail server interprets the headers being sent to it. The solution was simple (once you figure it out), and involves removing the “<” section that adds the sender name so that your mail program can describe the email address is receives.

So I found this code:

/**
* Formats an address correctly.
* @access private
* @return string
*/
function AddrFormat($addr) {
if(empty($addr[1]))
$formatted = $addr[0];
else
{
$formatted = $this->EncodeHeader($addr[1], ‘phrase’) . ” <” .
$addr[0] . “>”;
}

return $formatted;
}

and replaced it with:

/**
* Formats an address correctly.
* @access private
* @return string
*/
function AddrFormat($addr) {

$formatted = $addr[0];

return $formatted;
}

and voila’. Problem solved!

Just a quite note that this solution effectively changes the mail header to omit the senders name. I suspect this is due to my hosting provider’s configuration, but I’m led to believe it’s not an uncommon problem on Windows servers running php. If you run into a similar problem, I hope this post has been useful.

Best of luck!


Responses

Pages: [2] 1 » Show All

on August 16th, 2008 at 5:44 am

Brilliant! This works a treat. I had come across this a long time ago and couldn’t remember how I overcame it but this works perfectly.

Just have to remember to change this back should we move over to our Linux server!

Thanks for the post.

on August 5th, 2008 at 10:53 pm

I will do it for you. but I will charge for it. if you agree then send me a mail.

on August 5th, 2008 at 12:21 pm

Hello,

I’ve used the next instruction:
$mail->isSmtp(false/true);

(I don’t remember exactly how it was)

That’s working for me…

Try to use it.

-ByE-

on August 5th, 2008 at 12:02 pm

Hello I tried ur mod. But it still not working. I use phpld 3.3, 3.2. No version is working

on May 20th, 2008 at 7:35 pm

Stumbled upon the same error message on a similar installation on IIS - but it turned out that the problem wasn’t caused by IIS at all.

Our local ISP had changed its SMTP port from 25 to 587 - the program worked fine when we dealt with it by adding a $mail->Host = 587 in the script

on May 15th, 2008 at 9:50 am

didn’t work for me either. moving to linux host

on April 8th, 2008 at 2:43 pm

Hi !

I’m using PHPMailer without problems until this error appears…

I don’t know why appear… The other webpages that i have are uploaded and working fine…

This ’solution’ is not working for me neither…

Can you help me please ?

-ByE-

Pages: [2] 1 » Show All

Leave a response

Your response:

Categories