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!

23 comments

  1. All greek to me 🙂

    I only have one issue with PHP and emails. It sends out all of my emails fine, except the ones I am trying to send to notify of payment being received. Those always bounce back to me.

  2. Hi, just to let you know, I’ve tried your solution in wp-email and it did not worked for me 🙁

    I’ve modified the class-phpmailer.php according to your solution, but no luck.

  3. wordpress users: the wp-email author didn’t include the languages directory in his/her hack. you’ll need to download the entire php-mailer package and extract the languages directory then use the SetLanguage function to point to the correct directory.

    FUN!!

  4. @matt: One of the symptoms of Open Source I suppose. Multiple authors all with different coding and testing standards

  5. > …author didn?t include the languages
    > directory in his/her hack. you?ll need
    > to download the entire PHP-mailer
    > package and extract the languages
    > directory then use the SetLanguage
    > function to point to the correct directory.

    … “use the SetLanguage” by doing what? Thanks.

  6. 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-

  7. 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

  8. 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-

  9. 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.

  10. Thank you for posting this. It was a big help in fixing the error I was having with a new site installation (transfer) and getting my clients newsletter out to their 600 members.

    Very much appreciated!

    James

  11. Works an absolute treat – this is the first time I have ever encountered a problem and found a solution straight away.

    Thanks a lot.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.