• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

Oscommerce website gives an emailing error.

I am using oscommerce on my commerce website. I am getting the following message at the point where the site send an email to a customer, like sending password to the customer. The site is on Windows 2003 with IIS 6.

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in e:\webaddress\shop\includes\classes\email.php on line 500

The related code on line 500 is: return mail($to, $subject, $this->output, 'From: '.$from.$this->lf.implode($this->lf, $this->headers).$this->lf.implode($this->lf, $xtra_headers));

The following is the subsequent codes around line 500.

if (EMAIL_TRANSPORT == 'smtp') {
       return mail($to, $subject, $this->output, 'From: '.$from.$this->lf.implode($this->lf, $this->headers).$this->lf.implode($this->lf, $xtra_headers));

       
       
        /*
        require_once(DIR_WS_CLASSES . "class.phpmailer.php");

            $pMail = PHPMailer();
            
            $pMail->From     = $from_addr;
            $pMail->FromName = $from_name;
                        
            $pMail->IsSMTP();
            $pMail->Host     = localhost;      // replace with your smtp server
                        
            $pMail->Subject = $subject;
            $pMail->Body    = $this->output;
            $pMail->AddAddress($to_addr, $to_name);
            $pMail->IsHTML(true);
                        
            return $pMail->Send();
            
            $pMail->ClearAddresses();
            $pMail->ClearAttachments();
            */
            
      } else {
        return mail($to, $subject, $this->output, 'From: '.$from.$this->lf.implode($this->lf, $this->headers).$this->lf.implode($this->lf, $xtra_headers));
      }
    }
 


Can someone help? Many thanks.

0
StockExpert
Asked:
StockExpert
  • 13
  • 5
  • 4
  • +1
5 Solutions
 
geowrianCommented:
Is there an email server running on the webserver hosting the script? Is it running on port 25? Does it accept unauthenticated relay requests? The best thing to do would be to verify the email settings from the web host and plug those values in.
0
 
StockExpertAuthor Commented:
webserver runs virtual smtp
running on port 25
it accepts unauthorized relay

Can you explain detail: " verify the email settings from the web host and plug those values in."

Thanks.
0
 
leakim971PluritechnicianCommented:
Hello StockExpert,

You probably need to change this line :

$pMail->Host     = localhost;      // replace with your smtp server

localhost by the smtp server of your web host.

Regards
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
geowrianCommented:
@StockExpert,
The error message means your code couldn't connect to an SMTP server. Specifically, it couldn't connect to port 25 on the localhost. As leakim971 pointed out, you likely need to change the "localhost" to the stmp server's address.
0
 
StockExpertAuthor Commented:
Changed it to the IP address of the server. it makes the error message different. now:

Warning: Cannot modify header information - headers already sent by (output started at e:\webaddress\shop\includes\classes\email.php:1) in e:\webaddress\shop\includes\functions\general.php on line 29

the line 29 in general.php isheader('Location: ' . $url);

what should i do now?

Thanks.

0
 
StockExpertAuthor Commented:
Here is more information around the line 29

// Redirect to another page or site
  function tep_redirect($url) {
    if ( (ENABLE_SSL == true) && (getenv('HTTPS') == 'on') ) { // We are loading an SSL page
      if (substr($url, 0, strlen(HTTP_SERVER)) == HTTP_SERVER) { // NONSSL url
        $url = HTTPS_SERVER . substr($url, strlen(HTTP_SERVER)); // Change it to SSL
      }
    }

    header('Location: ' . $url);   <b>***this is line 29***** </b>

    tep_exit();
  }

0
 
Jon BrelieSystem ArchitectCommented:
Strip out any whitespace at the end of the file and see if you still get the same error.

Weird, but I've seen this with some versions of PHP.
0
 
StockExpertAuthor Commented:
Enphyniti: I checked any white space, corrected and it still the same.

I have to change my comment above. After changing the localhost to the ip address it still generates the same error. I was using google chrole and saw this error.

Warning: mail() [function.mail]: Failed to connect to mailserver at "70.62.159.243" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in e:\webaddress\shop\includes\classes\email.php on line 500

Warning: Cannot modify header information - headers already sent by (output started at e:\webaddress\shop\includes\classes\email.php:1) in e:\webaddress\shop\includes\functions\general.php on line 29

Somehow, I changed the browser to IE and it didn't show the first error. I thought the change made the difference. I changed back to google chrome, it's now same as the original.

Any other idea? Thanks.
0
 
Jon BrelieSystem ArchitectCommented:
Do you have 'send mail from' defined in your php.ini?  

If so, try sending a message via telnet using that address with the follwing commands.

On your webserver, open a command prompt and type in the following:

telnet definedSMTPserver 25
helo smtptest
mail from: definedMailFromAddress
rcpt to: someTestEmailAddress
data
From: definedMailFromAddress
To: someTestEmailAddress
Subject: email test
Testing local mail with defined account
.

don't forget the " . " at the on the last line to send the message.

Note any errors you receive during this process.


0
 
StockExpertAuthor Commented:
telnet definedSMTPserver 25...
it says: could not connect to the host, on port 25: connect failed

hmmm... looks like the port doesnt have the definedsmtp...
0
 
leakim971PluritechnicianCommented:
What's your host ?
0
 
Jon BrelieSystem ArchitectCommented:
check services - is smtp running?
0
 
StockExpertAuthor Commented:
oh... I see what you mean now... I am trying again
0
 
StockExpertAuthor Commented:
the ip is 70.62.159.243

can you do that for me and let me know what's going on? i am getting errors...
0
 
geowrianCommented:
Looks like SMTP is not configured to accept on port 25, or a firewall may be interfering. Make sure the SMTP service is running and the port is open on any firewalls on the server.
0
 
StockExpertAuthor Commented:
try it again. the relay was off and it's on now. if you still think that the port is closed, let me know. the firewall was/is off. smtp service is running too.
0
 
leakim971PluritechnicianCommented:
Connexion to port 25 : OK
Connexion to mail server : Bad
0
 
StockExpertAuthor Commented:
the webserver sends email without problems in some asp web applications, using the smtp virtual server. the problem is only in this php website.
0
 
StockExpertAuthor Commented:
Connexion to mail server : Bad
how can i fix it? what is "Bad" mean?
0
 
Jon BrelieSystem ArchitectCommented:
Since your app and your mailserver are on the same system, don't use your external IP.  Use either localhost, 127.0.0.1, or the LAN ip.

I cannot connect to 70.62.159.243 on 25.  it drops the connection.
0
 
StockExpertAuthor Commented:
Enphyniti: can you try it again connecting to 70.62.159.243? it should work now.

i changed it to 127.0.0.1. it still the same...
0
 
StockExpertAuthor Commented:
this is the line 500:

 return mail($to, $subject, $this->output, 'From: '.$from.$this->lf.implode($this->lf, $this->headers).$this->lf.implode($this->lf, $xtra_headers));

if i remove this line from the code, it goes. and leave the following error


Warning: Cannot modify header information - headers already sent by (output started at e:\www.greencash.us\shop\includes\classes\email.php:1) in e:\www.greencash.us\shop\includes\functions\general.php on line 29
0
 
Jon BrelieSystem ArchitectCommented:
-
0
 
StockExpertAuthor Commented:
Solution: I found a blank space after the end of config.php file. sigh... removing this space solved this problem. I send many thanks to experts who helped me in this question. You guys are great!
0
 
leakim971PluritechnicianCommented:
Good news! Thanks for the points! Happy new year!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 13
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now