NOTE:: Before reporting an issue, make sure you are running the latest version, currently 3.3.1

View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0008590phplist applicationMessage Send Processpublic22-11-06 04:1826-03-09 17:21
PlatformOSOS Version
Product Version2.10.3 
Target Version2.10.10Fixed in Version 
Summary0008590: SMTP code is partially broken
DescriptionHi everyone!

I'm posting this because I noticed that SMTP is not working correctly in PHPList (at least with version 2.10.2 and 2.10.3. I've not tried others)

First I'll explain my network configuration: I have a Web server in one computer where I often develop HTML & PHP and I have a mail server configured on another computer in the intranet which I contact via SMTP for doing tests. I refer to the mail server without fancy names, i.e. I call it by its IP address :

The problem arises when I configure PHPList to contact the mail server with SMTP. PHPList simply does ignore that setting and tries to contact the server via the normal "mail" command.

I have configured then SMTP address in config.php:

Here I just have to say that PHPMAILERHOST is a bit confusing (I thougth it was the computer on which the PHPMailer script was) and should be named something like SMTPServerAddress or something, as I think thats the main purpose of this setting.

The thing is, when I define these settings, PHPList ALWAYS tries to contact the mail server via "mail" command and not via SMTP, because of this code (located on admin/class.phplistmailer.php):

$this->Host = PHPMAILERHOST;
// that is the mail server name or address
. . .
$ip = gethostbyname($this->Host);
// resolve name to IP. It is already resolved
. . .
// so this next line is always true
// because $ip=$this->Host
// = !!!
if (!$this->Host || $ip == $this->Host)
// Send via "mail"
// Send via "SMTP"

And PHPList tries to connect the server always with the "mail" command, resulting in the server not being contacted in any way and getting these errors on the eventlog:

Mailer Error: Language string failed to load: instantiate

Mailer Error: Could not instantiate mail function

So I did a quickfix and replaced the problematic line
if (!$this->Host || $ip == $this->Host)
with this one:
if (!$this->Host)

Meaning that if you have the SMTP server configured on config.php it will always try to contact it via SMTP, if not, it will try to contact it via "mail" on localhost.

I have not studied other cases nor any possible side effects in code. I repeat, it's a quick fix and it works for me, so it would work for you too "if you have this problem".

Use it at your own risk if you feel happy with it.

I hope this could help anyone...
TagsNo tags attached.
Attached Files

- Relationships
related to 0003721closed phplist 2.10.x 
related to 0015325resolvedmichiel SMTP code is partially broken (revisited) 

-  Notes
michiel (manager)
22-11-06 12:01

thanks for finding the fix
melsea (reporter)
22-03-07 16:05

Thanks for this. It fixed the 'Mailer Error: Could not instantiate mail function.' error for me.
h2b2 (manager)
16-04-07 22:41

Fix confirmed to be working as an SMTP workaround for 'bare linefeed' issue with sendmail. See: [^]
03-08-07 19:31

can you try the fix and see if it works for you using smtp and common mail() function?
Then we can discuss how to implement thi is it doesn't do what we expect to.


h2b2 (manager)
28-02-09 14:44

Also related to this post by simlan, with his suggested fixes:
source: [^]



I figured out a problem with using PHPMailer in combination with external SMTP servers (that is if you don't want to use the build-in PHP mail() function). This problem has already been reported but it's still not fixed.

See this Mantis entry: mantis . phplist . com/view.php?id=8590 (thanks for not being able to send URLs)

The problem is located in "admin/class.phplistmailer.php", which derives from PHPMailer but show inappropriate usage of the parent.

The first problem is related to setting the language for PHPMailer, which results in stupid errors to be produced, like "Error: Language string failed to load".

parent::SetLanguage('en', dirname(__FILE__) . 'phpmailer/language/');

This is missing a separator "/", and the correct line looks like:

parent::SetLanguage('en', dirname(__FILE__) . '/phpmailer/language/');

Note that problems can also arise if you set PHPMailer to use your dedicated SMTP server but your Webhosting Service does not allow invocation of the fsockopen() PHP function. You can test this with a small script I wrote (store it outside of PHPList because .htaccess forbids execution). If your host does not allow fsockopen(), you'll get "Connection refused" or similar. PHPMailer depends on this function to work!

$host = "your.mailserver.tld";
$port = 25;
$tval = 15;

$smtp_conn = fsockopen($host, $port, $errno, $errstr, $tval);

if (empty($smtp_conn))
  print("Error connecting: ". $errno .": ". $errstr);
} else {
  print("Connect seems good!\n");

Other issues are related to inappropriate usage of $this->Host, $ip and wrong usage of "if", especially if the host is already in IP format. I propose the following code for the constructor of the class, which is not well tested but works for me and seems to be more sensible.

    function PHPlistMailer($messageid,$email) {
    # parent::PHPMailer();
      parent::SetLanguage('en', dirname(__FILE__) . '/phpmailer/language/');
      $this->addCustomHeader("X-Mailer: phplist v".VERSION);
      $this->addCustomHeader("X-MessageID: $messageid");
      $this->addCustomHeader("X-ListMember: $email");
      $this->addCustomHeader("Precedence: bulk");
      $this->CharSet = getConfig("html_charset");

      /* Check if there is a global SMTP host defined. */
      if (defined('PHPMAILERHOST') && PHPMAILERHOST != ''
          && isset($GLOBALS['phpmailer_smtpuser'])
          && $GLOBALS['phpmailer_smtpuser'] != '')
        //logEvent('Sending authenticated email via '.PHPMAILERHOST);
        //$this->addCustomHeader("X-Mailer-Method: Dedicated SMTP");
        $this->SMTPAuth = true;
        $this->Helo = getConfig("website");
        $this->Host = PHPMAILERHOST;
        $this->Username = $GLOBALS['phpmailer_smtpuser'];
        $this->Password = $GLOBALS['phpmailer_smtppassword'];
        $this->Mailer = "smtp";
        //logEvent('Sending email using PHP mail()');
        $this->Mailer = "mail";

      if ($GLOBALS["message_envelope"]) {
        $this->Sender = $GLOBALS["message_envelope"];
        $this->addCustomHeader("Errors-To: ".$GLOBALS["message_envelope"]);

Dear PHPList guys, please fix this issue.


====END QUOTE====
26-03-09 17:21

fixing condition to decide the use of an external SMTP server or not and fixing the bad use of the lkanguage setting in the class where PHPlist send the email.

Copyright © 2000 - 2017 MantisBT Team
Powered by Mantis Bugtracker