Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Mail Function does not work with my gallery but test script does  (Read 27933 times)

0 Members and 1 Guest are viewing this topic.

rafiki

  • Coppermine newbie
  • Offline Offline
  • Posts: 10

Good afternoon,
I'm hitting a dead end.
I've set up a new gallery on a new webhost. URL: http://petitadrien.fr/photos/
Everything works fine except the emails that are never sent out.

I did try the following test script placed in the root folder of my gallery, it worked fine and sent out the email with the correct sender.
Code: [Select]
<?php
// Mettez ici votre adresse valide
$to "removed@nonemail.com";
// Sujet du message 
$subject "Test fonction mail() de PHP";
// Corps du message, écrit en texte et encodage iso-8859-1
$message "Bonjour,\nl'envoi du mail via PHP a reussi. Le webmaster\n";
// Entêtes du message
$headers ""// on vide la variable
$headers "From: Webmaster Site <removed@nonemail.com>\n"// ajout du champ From
// $headers = $headers."MIME-Version: 1.0\n"; // ajout du champ de version MIME
$headers $headers."Content-type: text/plain; charset=iso-8859-1\n"// ajout du type d'encodage du corps
// Appel à la fonction mail
if ( mail($to$subject$message$headers) == TRUE )
{
   echo 
"Envoi du mail reussi.";
}
else
{
   echo 
"Erreur : l'envoi du mail a echoue.";
}
?>

I left all email settings blank in my gallery configuration and tested several times with the e-cards.
Here's what I get in the debug output:
Quote
/include/mailer.inc.php•Warning line 588: mail() [function.mail]: Unable to retrieve servername infos
•CPG Notice line 1694: Could not instantiate mail function.

I searched the forum for the similar error but could not find a similar case.
Can you please provide assistance to solve that issue?
Thank you
« Last Edit: September 14, 2012, 01:14:43 am by Joe Carver »
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Mail Function does not work with my gallery but test script does
« Reply #1 on: September 10, 2012, 03:47:00 pm »

I left all email settings blank in my gallery configuration
As a quick fix you could try to use an SMTP server, if that's possible. If not, please reply and we'll try to fix your issue.
Logged

rafiki

  • Coppermine newbie
  • Offline Offline
  • Posts: 10
Re: Mail Function does not work with my gallery but test script does
« Reply #2 on: September 10, 2012, 05:44:17 pm »

I did try the SMTP settings with a gmail account.
It triggered another type of error.

I did not want to mix the 2 issues, but here's what I get with a gmail test in the debug output:
Quote
•Warning line 2113: fsockopen() [function.fsockopen]: SSL: Success
•Warning line 2113: fsockopen() [function.fsockopen]: Failed to enable crypto
•Warning line 2113: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unknown error)
•CPG Notice line 1694: SMTP Error: Could not connect to SMTP host.

Does this help?
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Mail Function does not work with my gallery but test script does
« Reply #3 on: September 11, 2012, 09:23:58 am »

Let's try to fix the non-SMTP version. In include/mailer.inc.php you'll find
Code: [Select]
  function MailSend($header, $body) {

    $to = '';
    for($i = 0; $i < count($this->to); $i++) {
      if($i != 0) { $to .= ', '; }
      $to .= $this->AddrFormat($this->to[$i]);
    }

    $toArr = split(',', $to);
   
    if ($this->Sender != '' && strtolower(ini_get('safe_mode')) != 'on' && ini_get('safe_mode') != 1) {
      $old_from = ini_get('sendmail_from');
      ini_set('sendmail_from', $this->Sender);
      $params = sprintf("-oi -f %s", $this->Sender);
      if ($this->SingleTo === true && count($toArr) > 1) {
        foreach ($toArr as $key => $val) {
          $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
        }
      } else {
        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
      }
      ini_set('sendmail_from', $old_from);
    } else {
      if ($this->SingleTo === true && count($toArr) > 1) {
        foreach ($toArr as $key => $val) {
          $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
        }
      } else {
        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
      }
    }

    if(!$rt) {
      $this->SetError($this->Lang('instantiate'));
      return false;
    }

    return true;
  }

which is used if no SMTP data is set. If I remember correctly we already had a similar issue, unfortunately I wasn't able to find that thread. However, I assume that some parameter breaks Coppermine's mail function (i.e. the mail server doesn't like them), but it should be possible to fix it.

First of all I'd try if it works if you remove $params at all occurrences and if that doesn't work additionally remove $header. Please report the result.
« Last Edit: September 11, 2012, 09:44:48 am by Αndré »
Logged

rafiki

  • Coppermine newbie
  • Offline Offline
  • Posts: 10
Re: Re: Mail Function does not work with my gallery but test script does
« Reply #4 on: September 11, 2012, 03:55:39 pm »

First of all I'd try if it works if you remove $params at all occurrences and if that doesn't work additionally remove $header. Please report the result.

Hello André,
I did try to remove the variables as you specified in the MailSend function to end up with this syntax
Code: [Select]
function MailSend($body) {

    $to = '';
    for($i = 0; $i < count($this->to); $i++) {
      if($i != 0) { $to .= ', '; }
      $to .= $this->AddrFormat($this->to[$i]);
    }

    $toArr = split(',', $to);
   
    if ($this->Sender != '' && strtolower(ini_get('safe_mode')) != 'on' && ini_get('safe_mode') != 1) {
      $old_from = ini_get('sendmail_from');
      ini_set('sendmail_from', $this->Sender);
      $params = sprintf("-oi -f %s", $this->Sender);
      if ($this->SingleTo === true && count($toArr) > 1) {
        foreach ($toArr as $key => $val) {
          $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body);
        }
      } else {
        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body);
      }
      ini_set('sendmail_from', $old_from);
    } else {
      if ($this->SingleTo === true && count($toArr) > 1) {
        foreach ($toArr as $key => $val) {
          $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body);
        }
      } else {
        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body);
      }
    }

    if(!$rt) {
      $this->SetError($this->Lang('instantiate'));
      return false;
    }

    return true;
  }

I tried first removing only the $params and then the $header
In both cases I got the following output
Quote
/include/mailer.inc.php•Warning line 588: mail() [function.mail]: Unable to retrieve servername infos
•CPG Notice line 1694: Could not instantiate mail function.

Additional info if helpful on this host:
sendmail_path /usr/sbin/pxsendmail
safe mode is off
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Mail Function does not work with my gallery but test script does
« Reply #5 on: September 12, 2012, 09:53:16 am »

To be honest I'm not very experienced with such email troubleshooting. I just recognized that line:
Quote
Warning line 588: mail() [function.mail]: Unable to retrieve servername infos

Line 588 reads
Code: [Select]
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
Please change the parameters so they are equal to your test script:
Code: [Select]
// Mettez ici votre adresse valide
$to = "testemail@gmail.com";
// Sujet du message
$subject = "Test fonction mail() de PHP";
// Corps du message, écrit en texte et encodage iso-8859-1
$message = "Bonjour,\nl'envoi du mail via PHP a reussi. Le webmaster\n";
// Entêtes du message
$headers = ""; // on vide la variable
$headers = "From: Webmaster Site <photos@petitadrien.fr>\n"; // ajout du champ From
// $headers = $headers."MIME-Version: 1.0\n"; // ajout du champ de version MIME
$headers = $headers."Content-type: text/plain; charset=iso-8859-1\n"; // ajout du type d'encodage du corps
// Appel à la fonction mail
$rt = @mail($to, $subject, $message, $headers);

Please report if it works with that hard-coded parameters.
Logged

rafiki

  • Coppermine newbie
  • Offline Offline
  • Posts: 10
Re: Mail Function does not work with my gallery but test script does
« Reply #6 on: September 12, 2012, 03:30:14 pm »

Thank you for the proposal.
I tried to hardcode, and replace line 588 by my script.

This leads to the following output:
Quote
/include/mailer.inc.php•Warning line 600: mail() [function.mail]: Unable to retrieve servername infos
•CPG Notice line 1706: Could not instantiate mail function.

Line 600 reads:
Code: [Select]
$rt = @mail($to, $subject, $message, $headers);
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Mail Function does not work with my gallery but test script does
« Reply #7 on: September 12, 2012, 03:40:09 pm »

Try to replace the whole function with
Code: [Select]
  function MailSend($header, $body) {

    $to = '';
    for($i = 0; $i < count($this->to); $i++) {
      if($i != 0) { $to .= ', '; }
      $to .= $this->AddrFormat($this->to[$i]);
    }

    $toArr = split(',', $to);
   
    if ($this->Sender != '' && strtolower(ini_get('safe_mode')) != 'on' && ini_get('safe_mode') != 1) {
      //$old_from = ini_get('sendmail_from');
      //ini_set('sendmail_from', $this->Sender);
      //$params = sprintf("-oi -f %s", $this->Sender);
      if ($this->SingleTo === true && count($toArr) > 1) {
        foreach ($toArr as $key => $val) {
          $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
        }
      } else {
        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
      }
      //ini_set('sendmail_from', $old_from);
    } else {
      if ($this->SingleTo === true && count($toArr) > 1) {
        foreach ($toArr as $key => $val) {
          $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
        }
      } else {
        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
      }
    }

    if(!$rt) {
      $this->SetError($this->Lang('instantiate'));
      return false;
    }

    return true;
  }
Logged

rafiki

  • Coppermine newbie
  • Offline Offline
  • Posts: 10
Re: Mail Function does not work with my gallery but test script does
« Reply #8 on: September 12, 2012, 05:02:08 pm »

Hello André
I did start from a fresh cpg 1.5.20 mailer.inc.php file.
I replaced the whole function with the proposed code.

Still no luck:
Quote
/include/mailer.inc.php
    Notice line 588: Undefined variable: params
    Warning line 588: mail() [function.mail]: Unable to retrieve servername infos
    CPG Notice line 1694: Could not instantiate mail function.
Logged

Joe Carver

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 1545
  • aka 'i-imagine'
    • Home Page
Re: Mail Function does not work with my gallery but test script does
« Reply #9 on: September 13, 2012, 01:09:50 am »

I did try the following test script placed in the root folder of my gallery, it worked fine and sent out the email with the correct sender.

Did you actually receive the mail?

(and...by the way, if the mail addresses are real in your test script, they can be deleted on request)


I did try the SMTP settings with a gmail account.

Does gmail allow the use of it's servers for SMTP?
Can you retry with mail account(s) you have set up on your own server? (to lessen the possibility of getting caught in a spam filter...)

Have you asked your host for help? Some hosts place limitations on email to reduce spammers.

rafiki

  • Coppermine newbie
  • Offline Offline
  • Posts: 10
Re: Re: Mail Function does not work with my gallery but test script does
« Reply #10 on: September 13, 2012, 05:59:29 pm »

Did you actually receive the mail?
Yes I received it on a gmail account.
(and...by the way, if the mail addresses are real in your test script, they can be deleted on request)
Thank you for pointing it out, I have put the real email I have setup for the gallery, I will avoid next time.

Does gmail allow the use of it's servers for SMTP?
Can you retry with mail account(s) you have set up on your own server? (to lessen the possibility of getting caught in a spam filter...)

Have you asked your host for help? Some hosts place limitations on email to reduce spammers.
I don't know for Gmail, I tried to follow the coppermine's doc and it sounds like the simplest approach.

The host is not really helpful, I did ask them for guidance with their smtp settings and they sent me for the moment only copypaste type of answers pointing to their configuration guide.
That's why I was counting on using the standard function which works fine on a gallery I have a on free host, but I did not expect it to be different this time. I was too optimistic.
I will retry and insist with the host support in the mean time.
Logged

Joe Carver

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 1545
  • aka 'i-imagine'
    • Home Page
Re: Mail Function does not work with my gallery but test script does
« Reply #11 on: September 14, 2012, 01:21:23 am »

I removed your email address from the first post.

To be somewhat more complete in testing, I suggest:
  • Run versioncheck.php on your site (note: not all errors are important)
  • Try the mail function with Register or, even easier Contact
  • phpinfo.php might reveal something (I can't be sure)
  • Try the test script with mail account(s) you have set up on your own server

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Mail Function does not work with my gallery but test script does
« Reply #12 on: September 14, 2012, 10:05:02 am »

I still wonder where the following error message is generated and why I cannot find it with Google:
Code: [Select]
[function.mail]: Unable to retrieve servername infos
As far as I can see it isn't generated by Coppermine, at least such a string doesn't exist in any file.
Logged

rafiki

  • Coppermine newbie
  • Offline Offline
  • Posts: 10
Re: Mail Function does not work with my gallery but test script does
« Reply #13 on: November 24, 2012, 04:16:51 pm »

Thank you all for your effort and suggestions.
I tried a couple of times but the webhost was not really helpful and blamed the CMS (Coppermine in this case) instead of trying to assist me.
I moved my gallery to a slower but free webhost and it worked like a charm.

This ticket can be closed.
Logged
Pages: [1]   Go Up
 

Page created in 0.034 seconds with 20 queries.