Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

SMTP Authentication and OSCommerce


YePix

Recommended Posts

Hi folks, I have installed the PhpMailer and everything so far ok and without errors. The problem is only the mails are shown as sent but do not arrive.

Does anyone have a suggestion for me?

 

 

 

Link to comment
Share on other sites

I do not know what it should bring but even if the mails were classified as spam, they would arrive.
I tested it with gmail and outlook. Emails do not arrive.
but still thank you. could someone help me?

Link to comment
Share on other sites

So first thanks to @raiwa and @Tsimi. With a few suggestions you helped me a lot.

Special thanks to @tgely for his challenging work!

The instructions for bootstrap with all changes and source code I will put in soon for other users.

The email-class has to be changed, the general.php in the admin has to be provided with a function and the corresponding php-mailer comes as a download.

Link to comment
Share on other sites

For those who want or need to send their emails with smtp through authentication.
Email not suitable for gmail accounts !!!

****************************************************

Step 1.

BACKUP ALL FILES BEFORE CHANGE !!!

****************************************************

Step 2.

Download:
www.pl-systeme.de/free_download/PHPMailer.zip

transferred to:
catalog/ext/modules/PHPMailer

****************************************************

Step 3.

change class files:
catalog/includes/classes.php

<?php
/*
  $Id$
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
  Copyright (c) 2014 osCommerce
    
*/
  require_once 'ext/modules/PHPMailer/class.phpmailer.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;
      }
      return true;
    }
  }
/* ** Altered for Mail Manager ** */
// eliminate line feeds as <br>
  class emailMailManager extends email { 
	function add_html($html, $text = NULL, $images_dir = NULL) {
	  $this->html = $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->find_html_images($images_dir);
	}
  }
/* ** EOF alterations for Mail Manager ** */  
?>

catalog/admin/includes/classes.php

<?php
/*
  $Id$
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
  Copyright (c) 2014 osCommerce
  Released under the GNU General Public License
  
*/
  require_once '../ext/modules/PHPMailer/class.phpmailer.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;
      }
      return true;
    }
  }
  /* ** Altered for Mail Manager ** */
  // eliminate line feeds as <br>
  class emailMailManager extends email { 
	function add_html($html, $text = NULL, $images_dir = NULL) {
	  $this->html = $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->find_html_images($images_dir);
	}
  }
  /* ** EOF alterations for Mail Manager ** */
?>

****************************************************

Step 4.

catalog/admin/functions/general.php

find:

////
// Sets the status of a product
  function tep_set_product_status($products_id, $status) {
    if ($status == '1') {
      return tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '1', products_last_modified = now() where products_id = '" . (int)$products_id . "'");
    } elseif ($status == '0') {
      return tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0', products_last_modified = now() where products_id = '" . (int)$products_id . "'");
    } else {
      return -1;
    }
  }

add below:

////
// Sets the password function for db
function tep_cfg_password($password) {
return preg_replace("|.|", "*", $password);
}
function tep_cfg_input_password($password) {
return tep_draw_password_field('configuration_value', $password);
}

****************************************************

Step 5.

Import sql:

INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('SMTP hosts', 'EMAIL_SMTP_HOSTS', '', 'Assign SMTP host senders', '12', '6', now());
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('SMTP authentication', 'EMAIL_SMTP_AUTHENTICATION', 'true', 'Do you want authenticated SMTP server?', '12', '7', 'tep_cfg_select_option(array(\'true\', \'false\'), ', now());
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('SMTP Password', 'EMAIL_SMTP_PASSWORD', '', 'Add SMTP Password for SMTP protocol', '12', '8', 'tep_cfg_password', 'tep_cfg_input_password(', now());
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('SMTP User', 'EMAIL_SMTP_USER', '', 'Add SMTP user for SMTP protocol', '12', '9', now());
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('SMTP Reply To', 'EMAIL_SMTP_REPLYTO', '', 'Add SMTP reply to address', '12', '10', now());

****************************************************

Step 6.

go to:

http://www.yourDomain.com/admin/configuration.php?gID=12

change the new SMTP email settings and set the email transport method to smtp

****************************************************

Step 7.

finished.

Link to comment
Share on other sites

  • 2 months later...
Hello guys, I have a big problem. When I send e-mails to all customers or newsletters, the e-mail arrives, 
but the header displays all the e-mail addresses of all customers. Do you have an aura, what goes wrong?
Link to comment
Share on other sites

The email system is not the best to put it politely. Use something that is designed to send emails like mailchimp. All you have to do then is to figure out a way to sync the subscribers, which is not too hard. It may also save your site from being blacklisted. Mailchimp allows you to send nice pretty emails and its free up to a certain level of subscribers.

REMEMBER BACKUP, BACKUP AND BACKUP

Link to comment
Share on other sites

  • 7 months later...

the new classes email.php

<?php
/*
  $Id$
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
  Copyright (c) 2014 osCommerce
    
*/
  require_once 'ext/modules/PHPMailer/class.phpmailer.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 = 'PL-Gastrosystem ' . 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;
    }
  }
/* ** Altered for Mail Manager ** */
// eliminate line feeds as <br>
  class emailMailManager extends email { 
	function add_html($html, $text = NULL, $images_dir = NULL) {
	  $this->html = $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->find_html_images($images_dir);
	}
  }
/* ** EOF alterations for Mail Manager ** */  
?>

 

Link to comment
Share on other sites

  • 6 months later...

If anyone is still struggling to get osC to send emails using SMTP (I spent way too long today fighting this), here's another answer ...

*IF* it's your own server (I'm using a WAMP test server here in-house), there's a program called 'Fake Sendmail.' It's very simple to install. I created a directory C:/wamp/sendmail/, copied in 4 files, edited the sendmail.ini file with all of my SMTP info (server name, port, authentication user name, password, etc), and restarted Apache.

Configure osC to use Sendmail, and you're all set! No core file changes!

Now, as others have mentioned, the shop's email address and from address needs to match, and match the domain of the shop.

HTH!

Malcolm

Link to comment
Share on other sites

  • 3 months later...
On 1/7/2019 at 9:34 PM, YePix said:

For those who want or need to send their emails with smtp through authentication.
Email not suitable for gmail accounts !!!

Hello Peter, is this valid for the latest Phoenix? 

Also, the link to PHPMailer download returns a 404 error...

Link to comment
Share on other sites

  • 6 months later...

Hi,

we also can`t send mails from the shop since a week. I understand the work mentioned above but i don`t understand where i have to go for smpt account or if i need it and what it is.

br

stefan

Link to comment
Share on other sites

  • 6 months later...

Hi, I don't have catalog/includes/classes.php  file in my OSC2.3.4

I have catalog/includes/classes/email.php

Is that the same ? I copy paste your code into my catalog/includes/classes/email.php ?

I tries this but i get an error it says fatal erro PHPMAILER class not found

Link to comment
Share on other sites

Am 16.10.2021 um 13:45 schrieb Psytanium:

Hi, I don't have catalog/includes/classes.php  file in my OSC2.3.4

I have catalog/includes/classes/email.php

Is that the same ? I copy paste your code into my catalog/includes/classes/email.php ?

I tries this but i get an error it says fatal erro PHPMAILER class not found


 

Yes you are right.
includes/classes/email.php

Download and upload to your server the PHP-Mailer.
PHP-Mailer you find here:

https://www.oscommerce.com/forums/topic/94340-smtp-authentication-and-oscommerce/?page=3

Link to comment
Share on other sites

I downloaded the latest version of PHPMailer, I found 5 files inside it :

  • Exception.php
  • OAuth.php
  • PHPMailer.php
  • POP3.php
  • SMTP.php

Uploaded to ext/modules/PHPMailer

But in your admin/includes/classes/mail.php filem the first line started with :

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

There is no such file (class.phpmailer.php) in PHPMailer folder.

If I change the line to

require_once '../ext/modules/PHPMailer/PHPMailer.php';

I get an error when I open the backend:

Fatal error: Class 'PHPMailer' not found in /home/user/public_html/backend/includes/classes/email.php on line 11

Link to comment
Share on other sites

I removed : namespace PHPMailer\PHPMailer; from PHPMailer.php

Is that OK to  remove it ?

Anyway, now I have another error:

Fatal error: Class 'SMTP' not found in /home/woodandgasleb/public_html/ext/modules/PHPMailer/PHPMailer.php on line 1939

Any idea ? I appreciate your help. Because apparently all the docs and topics I already found are for older version of PHPMailer.

Link to comment
Share on other sites

Am 23.10.2021 um 11:37 schrieb Psytanium:

I removed : namespace PHPMailer\PHPMailer; from PHPMailer.php

Is that OK to  remove it ?

Anyway, now I have another error:

Fatal error: Class 'SMTP' not found in /home/woodandgasleb/public_html/ext/modules/PHPMailer/PHPMailer.php on line 1939

Any idea ? I appreciate your help. Because apparently all the docs and topics I already found are for older version of PHPMailer.

I hope it works now;)
For everyone in the future. Write by PM. You can get the required PHPMailer via the download link

Link to comment
Share on other sites

Turned out Godaddy server block all outbound emails on ports 25, 465 and 587, except their own server. So I'm not able to use any SMTP while hosted on Godaddy servers, this is very annoying. Now I'm looking for other VPS server provider.

I tired your files on localhost using WAMP, works well, thanks for your help by sending me the necessary files, appreciated :)

Link to comment
Share on other sites

vor 11 Stunden schrieb Psytanium:

Turned out Godaddy server block all outbound emails on ports 25, 465 and 587, except their own server. So I'm not able to use any SMTP while hosted on Godaddy servers, this is very annoying. Now I'm looking for other VPS server provider.

I tired your files on localhost using WAMP, works well, thanks for your help by sending me the necessary files, appreciated :)

👍

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...