Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

SMTP Authentication and OSCommerce


bscanzoni

Recommended Posts

@@Flotec

 

In the older php mailer versions you had somewhere following line in file includes/classes/email.php

require_once 'ext/modules/phpmailer/class.phpmailer.php';

For the newest php mailer version you need this here instead

 

includes/classes/email.php

  require_once('ext/modules/phpmailer/PHPMailerAutoload.php');

admin/includes/classes/email.php

  require_once(DIR_FS_CATALOG . 'ext/modules/phpmailer/PHPMailerAutoload.php');

There are also some changes in the function names etc within the phpmailer classes, so you need to change the way you are calling them

 

Here is an example of a site that use that within function send()

        require_once('ext/modules/phpmailer/PHPMailerAutoload.php');

        $pmail = new PHPMailer;
        $pmail->isSMTP();
        $pmail->isHTML(true);

        $pmail->Host = "";
        $pmail->Port = 25;
        $pmail->SMTPAuth = true;
        $mail->Username = "";
        $mail->Password = "";
        
        $pmail->CharSet = "utf-8";

        $pmail->setFrom($from_addr, $from_name);
        $pmail->addAddress($to_addr, $to_name);
        $pmail->Subject = $subject;
        $pmail->Body = $this->html;
        $pmail->AltBody = $this->text;;

        if (!$pmail->send()) {
          return false;
        } else {
          $pmail->clearAddresses();
          $pmail->clearAttachments();	 
	  return true;
        }

Your code may be different, this is just for reference not to copy/paste

Link to comment
Share on other sites

  • Replies 104
  • Created
  • Last Reply

When I changed includes/classes/email.php I got this error

 

Warning: require_once(/home/flotecmari2/public_html/ext/modules/phpmailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in /home/flotecmari2/public_html/admin/includes/classes/email.php on line 16

Fatal error: require_once(): Failed opening required '/home/flotecmari2/public_html/ext/modules/phpmailer/PHPMailerAutoload.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/flotecmari2/public_html/admin/includes/classes/email.php on line 16

 

I don't understand the last part.

Link to comment
Share on other sites

@@Flotec

 

Make sure the path to the file you are using is correct, it may be different than what I posted

 

According to your previous post, the paths should be for you

 

includes/classes/email.php

  require_once('ext/modules/PHPMailer/PHPMailerAutoload.php');
admin/includes/classes/email.php
  require_once(DIR_FS_CATALOG . 'ext/modules/PHPMailer/PHPMailerAutoload.php');
Link to comment
Share on other sites

When I use contact us I receive this new error message:

 

Warning: stream_socket_enable_crypto(): Peer certificate CN=`*.anx.se' did not match expected CN=`my_smtp_server' in /home/flotecmari2/public_html/ext/modules/PHPMailer/class.smtp.php on line 344

 

Again the email.php files I have does not look like the example you gave me before. I think the problem is in these files. Last time I got the recommendation from Gergely to download new ones here: https://github.com/G...asses/email.php That link does not work anymore.

Link to comment
Share on other sites

This is my includes/classes/email.php

<?php
/*
$Id$

osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com

Copyright (c) 2014 osCommerce

Released under the GNU General Public License

email is a class to assist with PHPmailer
sendmail, SMTP and gmail compatibility
*/

  require_once('ext/modules/PHPMailer/PHPMailerAutoload.php');
  $phpMail = new PHPMailer();

  class email {
    var $html;
    var $text;
    var $html_text;
    var $lf;
    var $debug = 0;
    var $debug_output = 'error_log';

    function email($headers = '') {
      global $phpMail;

      $phpMail->XMailer = 'osCommerce ' . tep_get_version();
      $phpMail->SMTPDebug = $this->debug;
      $phpMail->Debugoutput = $this->debug_output;
      $phpMail->CharSet = CHARSET;
      $phpMail->WordWrap = 998;

      if (EMAIL_LINEFEED == 'CRLF') {
        $this->lf = "\r\n";
      } else {
        $this->lf = "\n";
      }
    }

    function add_text($text = '') {
      global $phpMail;

      $phpMail->IsHTML(false);
      $this->text = tep_convert_linefeeds(array("\r\n", "\n", "\r"), $this->lf, $text);
    }

    function add_html($html, $text = NULL, $images_dir = NULL) {
      global $phpMail;

      $phpMail->IsHTML(true);

      $this->html = tep_convert_linefeeds(array("\r\n", "\n", "\r"), '<br />', $html);
      $this->html_text = tep_convert_linefeeds(array("\r\n", "\n", "\r"), $this->lf, $text);

      if (isset($images_dir)) $this->html = $phpMail->msgHTML($this->html, $images_dir);
    }

    function add_attachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment') {
      global $phpMail;

      $phpMail->AddAttachment($path, $name, $encoding, $type, $disposition);
    }

    function build_message() {
      //out of work function
    }

    function send($to_name, $to_addr, $from_name, $from_addr, $subject = '', $reply_to = false) {
      global $phpMail;

      if ((strstr($to_name, "\n") != false) || (strstr($to_name, "\r") != false)) {
        return false;
      }

      if ((strstr($to_addr, "\n") != false) || (strstr($to_addr, "\r") != false)) {
        return false;
      }

      if ((strstr($subject, "\n") != false) || (strstr($subject, "\r") != false)) {
        return false;
      }

      if ((strstr($from_name, "\n") != false) || (strstr($from_name, "\r") != false)) {
        return false;
      }

      if ((strstr($from_addr, "\n") != false) || (strstr($from_addr, "\r") != false)) {
        return false;
      }

      $phpMail->From = $from_addr;
      $phpMail->FromName = $from_name;
      $phpMail->AddAddress($to_addr, $to_name);

      if ($reply_to) {
        $phpMail->AddReplyTo(EMAIL_SMTP_REPLYTO, STORE_NAME);
      } else {
        $phpMail->AddReplyTo($from_addr, $from_name);
      }

      $phpMail->Subject = $subject;

      if (!empty($this->html)) {
        $phpMail->Body = $this->html;
        $phpMail->AltBody = $this->html_text;
      } else {
        $phpMail->Body = $this->text;
      }

      if (EMAIL_TRANSPORT == 'smtp' || EMAIL_TRANSPORT == 'gmail') {
        $phpMail->IsSMTP();

        $phpMail->Host = EMAIL_SMTP_HOSTS;
        $phpMail->SMTPAuth = EMAIL_SMTP_AUTHENTICATION;

        $phpMail->Username = EMAIL_SMTP_USER;
        $phpMail->Password = EMAIL_SMTP_PASSWORD;

        if (EMAIL_TRANSPORT == 'gmail') {
          $phpMail->Port = 465;
          $phpMail->SMTPSecure = 'ssl';
        }
      } else {
        $phpMail->isSendmail();
      }

      if (!$phpMail->Send()) {
                return false;
          }
          $phpMail->clearAddresses();
          return true;
        }
  }
?>
Link to comment
Share on other sites

As I told you before I get this error:

Warning: stream_socket_enable_crypto(): Peer certificate CN=`*.anx.se' did not match expected CN=`my_smtp_server' in /home/flotecmari2/public_html/ext/modules/PHPMailer/class.smtp.php on line 344

 

I some way I have to remove the verification. Found this on Internet: http://blog.zot24.com/how-to-solve-peer-certificate-cn-not-matching-in-php-with-cakephp/

 

Where can I insert this?: 'ssl_verify_host' => false

 

I'm suprised that not more people are interested in this topic. Sending mails and using SMTP for this must be the most important thing for an e-shop to handle.

Link to comment
Share on other sites

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Link to comment
Share on other sites

Hello Gergely

 

Thank you for your answer but the file is wrong. Should start with this: require_once '../ext/modules/PHPMailer/PHPMailerAutoload.php';

 

If I change that and with debug activated (2) I get a time out:

 

2015-11-17 08:34:41 SMTP ERROR: Failed to connect to server: Connection timed out (110) 2015-11-17 08:34:41 SMTP connect() failed.

 

Where do I set the port for outgoing mails? Before I had "$phpMail->Port = 465;"

Link to comment
Share on other sites

I think I made an error when I copied your email.php file. I now have this file and have made two corrections:

 

- I changed first line to: require_once '../ext/modules/PHPMailer/PHPMailerAutoload.php';

- I changed line 35 from $phpMail->Port = EMAIL_SMTP_PORT; to $phpMail->Port = 465;

 

When I sent an email from admin it was succes. Mail has been sent but I have still not received it. Waiting for that.

 

It has to be an includes/classes/email.php also. Can you send that also?

Link to comment
Share on other sites

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Link to comment
Share on other sites

I belive you but this project works on :

 

$Version = '5.2.7';

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Link to comment
Share on other sites

Is that PHP version you talk about. I am on a PHP 5.6.14 server and on that I get a fatal error.

 

Anyway there are some undefined parameters included in your email.php files:

 

- EMAIL_TRANSPORT

- EMAIL_SMTP_PORT

- EMAI_SMTP_SECURE

 

Should be included in either the admin side or defined by running some mysql commands? There can be more?

Link to comment
Share on other sites

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Link to comment
Share on other sites

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Link to comment
Share on other sites

  • 9 months later...

@@Gergely I'm trying to install your mod along with your HTML emails. For any reason email is only being sent from the contact us page, not from any of the templated pages. Do I need to modify something for making both mods work together?

Link to comment
Share on other sites

@@Gergely I'm trying to install your mod along with your HTML emails. For any reason email is only being sent from the contact us page, not from any of the templated pages. Do I need to modify something for making both mods work together?

contact_us page was not templated. As a shop owner I dont want templated messages to me. :) The mail conversation will be mixed so there is no reason to be "templated" contact emails. Would you like to send templated emails to admin?

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Link to comment
Share on other sites

contact_us page was not templated. As a shop owner I dont want templated messages to me. :) The mail conversation will be mixed so there is no reason to be "templated" contact emails. Would you like to send templated emails to admin?

 

I know, I meant the only page that sends emails is the contact us page, that has not template. No errors are displayed, but all the other email from other pages are not sent (no order confirmation or status changes). That's why I was asking if both contribs are compatible.

Link to comment
Share on other sites

Yes its working together. Have you tried the SMTP debug first?

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Link to comment
Share on other sites

Yes its working together. Have you tried the SMTP debug first?

 

I did but no output was there. I've uninstalled the templates on the orders page and it works again; Will reinstall it and test in deep!

Link to comment
Share on other sites

I did but no output was there. I've uninstalled the templates on the orders page and it works again; Will reinstall it and test in deep!

It could be languages or another global variable issue. I used to set breakpoint in tp_ modules and print the mimemessage class.

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Link to comment
Share on other sites

  • 3 weeks later...

@@Gergely I'm testing this issue in depth. For now the error logs shows:

 

With email templates active:

[26-Sep-2016 04:00:46 Europe/Madrid] Invalid address:  (addAnAddress Reply-To): "NAME" <[email protected]>
[26-Sep-2016 04:00:46 Europe/Madrid] Invalid address:  (punyEncode) "NAME" <[email protected]>
[26-Sep-2016 04:00:46 Europe/Madrid] Invalid address:  (addAnAddress to): "NAME" <[email protected]>
[26-Sep-2016 04:00:46 Europe/Madrid] Invalid address:  (addAnAddress Reply-To): "NAME" <[email protected]>

Without email templates:

[26-Sep-2016 04:23:44 Europe/Madrid] SERVER -> CLIENT: ***.***.com ESMTP Exim 4.87 #1 Sun, 25 Sep 2016 22:23:44 -0400 
220-We do not authorize the use of this system to transport unsolicited, 
220 and/or bulk e-mail.

[26-Sep-2016 04:23:44 Europe/Madrid] CLIENT -> SERVER: EHLO domain.com

[...]

[26-Sep-2016 04:23:44 Europe/Madrid] SERVER -> CLIENT: 250 OK id=4boZe4-0005sR-20

[26-Sep-2016 04:23:44 Europe/Madrid] CLIENT -> SERVER: QUIT

[26-Sep-2016 04:23:44 Europe/Madrid] SERVER -> CLIENT: 221 ***.***.*** closing connection

[26-Sep-2016 04:23:44 Europe/Madrid] Invalid address:  (addAnAddress to): "NAME" <[email protected]>

Email is being sent without templates and only shows one of four errors (addAnAddress to) shown with templates active. Will dig to see where to set the breakpoint you mention and how templates work. I'm sure it's a silly thing that makes the email not being sent.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...