Jump to content
YePix

SMTP Authentication and OSCommerce

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?

 

 

 

Share this post


Link to post
Share on other sites
Posted (edited)

I have found this tool to be very helpful when troubleshooting phpmailer/email issues.

https://www.mail-tester.com/

 

Edited by Smoky Barnable

The water in a vessel is sparkling; the water in the sea is dark. The small truth has words which are clear; the great truth has great silence.

- Rabindranath Tagore

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Posted (edited)
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?
Edited by YePix

Share this post


Link to post
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

Get the latest Responsive osCommerce CE (community edition) here

It's very easy to over complicate what are simple things in life

Share this post


Link to post
Share on other sites

Whether it's good is not important. Important is why are all email addresses included in the header?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×