Jump to content
bodhizatfa

SMTP with authentication on Phoenix 1.0.5.0

Recommended Posts

HI,

First of all a big thanks to @burt and all the other contributors to Phoenix. 

I did a clean DB install and moved my old data over without a hitch. It was easy thanks to you! 

Has anyone set up SMTP mail with authentication successfully on Phoenix 1.0.5.0?

I'm on IIS and don't have the sendmail option.

I've had it running in 2.2 and I had it running in 234BS.

I'm an amateur and I have looked through previous addons to see if there is anything I can adapt to Phoenix. 

The code has obviously changed, in /includes/email.php and admin doesn't seem to have a classes/email.php either.

I've looked at both general.php files and see that the call to send mail is there but no if (EMAIL_TRANSPORT == 'smtp') in any of the files.

I've installed the latest PHPmailer.  I've changed $PHPmailer to $pmail as per the documentation.

I've been at this for over a week and I'm stuck.

Can anyone advise?

Thanks

Stewart

Share this post


Link to post
Share on other sites
On 4/25/2020 at 5:22 AM, PiLLaO said:

Hi @bodhizatfa

Did you follow this post? 

 

 

I think that Phoenix don't have support por SMTP

Hi Gustavo,

Thanks for responding. Yes I've looked through the topic, and read through pretty much every other post to see if I could find the answers. I still haven't found the answer. My amateur understanding of Phoenix is that the core will remain intact and there will be modules developed to expand Phoenix's functionality, kind of like WordPress.  Wordpress had the same issues and someone developed a  plugin to address SMTP functions. I'm exploring Phoenix 1.0.5.0 right now.  Even as an amateur, if I look at the updates leading up to 1.0.6.0, all of the previous SMTP patches simply won't work because the file structures have changed significantly.  The team is focusing on streamlining the core from what I can see. SMTP functionality and authentication are both realities that everyone lives with.   I am sure someone will develop an add-on solution.  I would develop one, but I am not even close to being a coder. 

Share this post


Link to post
Share on other sites
6 hours ago, bodhizatfa said:

the previous SMTP patches simply won't work because the file structures have changed significantly.

You might post what code used to need to be changed.  Because I don't think that things have changed that significantly.  You may just need to have it rewritten.  Or you may need to have someone write an adapter for the previous version of the code. 

And you might also want to be careful with your terms.  Reading your post, it seems that what you actually want is SMTP Authentication but you keep talking about SMTP.  That's two different things. As far as I know, SMTP works fine now if you have your server configured for it.  It's just that most people don't go through the effort to configure their servers to work with basic SMTP.  So you want a workaround that uses another server for the SMTP.  But to do that, you need the authentication.  What you want is not properly described as SMTP but as authenticated SMTP or remote SMTP. 

Anyway, my point is that if there are instructions that you don't know how to follow, you could get more help if you posted them.  As is, if I wanted to try to help, I'd have to go download the App.  And frankly, I'm too lazy to do that. 


Always back up before making changes.

Share this post


Link to post
Share on other sites
Posted (edited)
 
 
 
 
2
16 hours ago, ecartz said:
 
 
16 hours ago, ecartz said:
 
 
15 hours ago, ecartz said:

You might post what code used to need to be changed.  Because I don't think that things have changed that significantly.  You may just need to have it rewritten.  Or you may need to have someone write an adapter for the previous version of the code. 

And you might also want to be careful with your terms.  Reading your post, it seems that what you actually want is SMTP Authentication but you keep talking about SMTP.  That's two different things. As far as I know, SMTP works fine now if you have your server configured for it.  It's just that most people don't go through the effort to configure their servers to work with basic SMTP.  So you want a workaround that uses another server for the SMTP.  But to do that, you need the authentication.  What you want is not properly described as SMTP but as authenticated SMTP or remote SMTP. 

Anyway, my point is that if there are instructions that you don't know how to follow, you could get more help if you posted them.  As is, if I wanted to try to help, I'd have to go download the App.  And frankly, I'm too lazy to do that. 

I sincerely apologize for the poor choice of words Matt. The topic I posted here clearly says SMTP Authentication on Phoenix 1.0.5.0 I don't know how clearer I could be.  I am a supporter of Phoenix, and I believe in it 100%.  Yes, I have been working with my host trying to get them to set things configured correctly, and I quite frankly am contemplating switching hosts ASAP.  Matt, I am a complete newbie, but If I look at the changes that have been made going forward in phoenix on github I see that we have eliminated email.php in both the admin/includes/classes as well as in catalog/includes/classes.  Once upon a time, both those files, as well as application_top, and general.php,  had to be modified to enable the end-user to have authenticated SMTP, using PhpMailer or the like.  Here is an example of the email.php  I had used in the past on 231BS which worked like a charm using phpmailer.  No you're not lazy, you're busy. I get it.

<?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_TRANSPORT == 'smtp' || EMAIL_TRANSPORT == 'gmail') {
        $phpMail->IsSMTP();

        $phpMail->Port = EMAIL_SMTP_PORT;
        if (EMAIL_SMTP_SECURE !== 'no') {
          $phpMail->SMTPSecure = EMAIL_SMTP_SECURE;
        }

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

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

      } else {
        $phpMail->isSendmail();
      }

      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 = true) {
      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;
      }

      $error = false;
      if (!$phpMail->Send()) {
        $error = true;
      }

      $phpMail->clearAddresses();
      $phpMail->clearAttachments();

      if ($error == true) {
        return false;
      }

      return true;
    }
  }
?>
 

 

Edited by bodhizatfa

Share this post


Link to post
Share on other sites
17 hours ago, PiLLaO said:

You need SMTP to prevent your emails marked as spam?

No spam problems because my host uses smtp authentication and has for many years. Like many hosts, the like to point and say it's a programming problem, when in fact it's not.  I am going to have to change hosts if they can't fix their side of the server.

Share this post


Link to post
Share on other sites

99.99% of users are on a linux host using sendmail. 
The very few end-users not on that configuration...

It's sometimes better to walk a path with others (and therefore be able to get help/advice more easily) than it is to try to walk a path alone.

I have no experience with SMTP so cannot help.


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites

Searching for SMTP in the code base, gives this:

INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('E-Mail Transport Method', 'EMAIL_TRANSPORT', 'sendmail', 'Defines if this server uses a local connection to sendmail or uses an SMTP connection via TCP/IP. Servers running on Windows and MacOS should change this setting to SMTP.', '12', '1', 'tep_cfg_select_option(array(\'sendmail\', \'smtp\'),', now());

We then search for EMAIL_TRANSPORT which appears to be unused.  I checked back to an ancient 2.3.4 and finds a bit in the email class function that sends.  I don't recall when it was removed, but even so, it did not do anything (in terms of sending via SMTP) anyway - all it does is format the email in a way that SMTP understands. 

Never used SMTP, never want to.  


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites
7 minutes ago, burt said:

99.99% of users are on a linux host using sendmail. 
The very few end-users not on that configuration...

It's sometimes better to walk a path with others (and therefore be able to get help/advice more easily) than it is to try to walk a path alone.

I have no experience with SMTP so cannot help.

I hear you loud and clear.

Share this post


Link to post
Share on other sites
1 hour ago, bodhizatfa said:

No spam problems because my host uses smtp authentication and has for many years. Like many hosts, the like to point and say it's a programming problem, when in fact it's not.  I am going to have to change hosts if they can't fix their side of the server.

I found your post because I was having trouble with hotmail, They mark as spam my emails, and from my hosting tell to me that I should use SMTP.

After this, I checked on Phoenix v1.0.5.8 with sendmail and hotmail don't have marked as SPAM my emails, so... it's funny x'D

Share this post


Link to post
Share on other sites
Posted (edited)

I'm not sure why you would have needed to modify general.php with that class.  Presumably application_top.php was to load the class but Phoenix should do that automatically. 

<?php
/*
  $Id$

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

  Copyright (c) 2020 osCommerce

  Released under the GNU General Public License

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

  require_once DIR_FS_CATALOG . 'includes/apps/PHPMailer/PHPMailerAutoload.php';

  class email {

    private $lf, $mailer;
    private $debug = 0;
    private $debug_output = 'error_log';

    const LINEFEEDS = ["\r\n", "\n", "\r"];
    
    public function __construct($headers = '') {
      $this->mailer = new PHPMailer();

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

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

        $this->mailer->Port = EMAIL_SMTP_PORT;
        if (EMAIL_SMTP_SECURE !== 'no') {
          $this->mailer->SMTPSecure = EMAIL_SMTP_SECURE;
        }

        $this->mailer->Host = EMAIL_SMTP_HOSTS;
        $this->mailer->SMTPAuth = EMAIL_SMTP_AUTHENTICATION;

        $this->mailer->Username = EMAIL_SMTP_USER;
        $this->mailer->Password = EMAIL_SMTP_PASSWORD;

      } else {
        $this->mailer->isSendmail();
      }

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

    public function add_text($text = '') {
      $this->mailer->IsHTML(false);
      $this->mailer->Body = str_replace(static::LINEFEEDS, $this->lf, $text);
    }

    public function add_html($html, $text = NULL, $images_dir = NULL) {
      $this->mailer->IsHTML(true);
      
      $this->mailer->Body = str_replace(static::LINEFEEDS, '<br />', $html);
      $this->mailer->AltBody = str_replace(static::LINEFEEDS, $this->lf, $text);

      if (isset($images_dir)) {
        $this->mailer->Body = $this->mailer->msgHTML($this->mailer->Body, $images_dir);
      }
    }

    public function add_message($email_text) {
      // Build the text version
      $text = strip_tags($email_text);
      if (EMAIL_USE_HTML == 'true') {
        $this->add_html($email_text, $text);
      } else {
        $this->add_text($text);
      }
    }

    function add_attachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment') {
      $this->mailer->AddAttachment($path, $name, $encoding, $type, $disposition);
    }

    public function build_message() {
      // do nothing; needed for compatibility
    }

    public function send($to_name, $to_addr, $from_name, $from_addr, $subject = '') {
      // No need to check for "\r\n" separately as will match the other two
      foreach (["\n", "\r"] as $line_ending) {
        foreach ([$to_name, $to_addr, $subject, $from_name, $from_addr] as $header_value) {
          if (false !== strstr($header_value, $line_ending)) {
            return false;
          }
        }
      }

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

      if (defined('EMAIL_FROM')) {
        $this->mailer->From = EMAIL_FROM;
        $this->mailer->FromName = STORE_NAME;
        $this->mailer->AddReplyTo($from_addr, $from_name);
      } else {
        $this->mailer->From = $from_addr;
        $this->mailer->FromName = $from_name;
      }

      $this->mailer->Subject = $subject;

      $result = $this->mailer->Send();

      $this->mailer->clearAddresses();
      $this->mailer->clearAttachments();

      return $result;
    }

  }

Save this email.php file in a directory named includes/system/override (which you will probably have to create) and see if it starts working. 

Note that you may have to do some configuration somewhere.  And of course you need to upload the PHPMailer files.  I don't think that ext is the right place.  I'd put them in includes/apps/ or similar.  If you change that, change the require line. 

I replaced the EMAIL_SMTP_REPLYTO with the Phoenix equivalent along with other changes. 

Edited by ecartz

Always back up before making changes.

Share this post


Link to post
Share on other sites
27 minutes ago, ecartz said:

I'm not sure why you would have needed to modify general.php with that class.  Presumably application_top.php was to load the class but Phoenix should do that automatically. 


<?php
/*
  $Id$

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

  Copyright (c) 2020 osCommerce

  Released under the GNU General Public License

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

  require_once DIR_FS_CATALOG . 'includes/apps/PHPMailer/PHPMailerAutoload.php';

  class email {

    private $lf, $mailer;
    private $debug = 0;
    private $debug_output = 'error_log';

    const LINEFEEDS = ["\r\n", "\n", "\r"];
    
    public function __construct($headers = '') {
      $this->mailer = new PHPMailer();

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

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

        $this->mailer->Port = EMAIL_SMTP_PORT;
        if (EMAIL_SMTP_SECURE !== 'no') {
          $this->mailer->SMTPSecure = EMAIL_SMTP_SECURE;
        }

        $this->mailer->Host = EMAIL_SMTP_HOSTS;
        $this->mailer->SMTPAuth = EMAIL_SMTP_AUTHENTICATION;

        $this->mailer->Username = EMAIL_SMTP_USER;
        $this->mailer->Password = EMAIL_SMTP_PASSWORD;

      } else {
        $this->mailer->isSendmail();
      }

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

    public function add_text($text = '') {
      $this->mailer->IsHTML(false);
      $this->mailer->Body = str_replace(static::LINEFEEDS, $this->lf, $text);
    }

    public function add_html($html, $text = NULL, $images_dir = NULL) {
      $this->mailer->IsHTML(true);
      
      $this->mailer->Body = str_replace(static::LINEFEEDS, '<br />', $html);
      $this->mailer->AltBody = str_replace(static::LINEFEEDS, $this->lf, $text);

      if (isset($images_dir)) {
        $this->mailer->Body = $this->mailer->msgHTML($this->mailer->Body, $images_dir);
      }
    }

    public function add_message($email_text) {
      // Build the text version
      $text = strip_tags($email_text);
      if (EMAIL_USE_HTML == 'true') {
        $this->add_html($email_text, $text);
      } else {
        $this->add_text($text);
      }
    }

    function add_attachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment') {
      $this->mailer->AddAttachment($path, $name, $encoding, $type, $disposition);
    }

    public function build_message() {
      // do nothing; needed for compatibility
    }

    public function send($to_name, $to_addr, $from_name, $from_addr, $subject = '') {
      // No need to check for "\r\n" separately as will match the other two
      foreach (["\n", "\r"] as $line_ending) {
        foreach ([$to_name, $to_addr, $subject, $from_name, $from_addr] as $header_value) {
          if (false !== strstr($header_value, $line_ending)) {
            return false;
          }
        }
      }

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

      if (defined('EMAIL_FROM')) {
        $this->mailer->From = EMAIL_FROM;
        $this->mailer->FromName = STORE_NAME;
        $this->mailer->AddReplyTo($from_addr, $from_name);
      } else {
        $this->mailer->From = $from_addr;
        $this->mailer->FromName = $from_name;
      }

      $this->mailer->Subject = $subject;

      $result = $this->mailer->Send();

      $this->mailer->clearAddresses();
      $this->mailer->clearAttachments();

      return $result;
    }

  }

Save this email.php file in a directory named includes/system/override (which you will probably have to create) and see if it starts working. 

Note that you may have to do some configuration somewhere.  And of course you need to upload the PHPMailer files.  I don't think that ext is the right place.  I'd put them in includes/apps/ or similar.  If you change that, change the require line. 

I replaced the EMAIL_SMTP_REPLYTO with the Phoenix equivalent along with other changes. 

Thanks so much Matt!  It steers me in the right direction.  I will do what you said and let you know how it works out.

Regards

Share this post


Link to post
Share on other sites

The file absolutely works!  Thanks so much. You were right Matt that I will need to do some configuring to get Phoenix to switch to the override/email.php file.  I am here to learn so I will give it a try.  Also for anyone else wanting to do this, in the My Store configuration you need to change the "email from" setting  "your name" <info@ yourstore> to info@yourstore.  The reply-to's have to match.

 

Share this post


Link to post
Share on other sites

@bodhizatfa

There is a program called 'Fake Sendmail'. I have just installed it on my WAMP box here. You configure the sendmail.ini file with all of your SMTP mail configurations (server, port, authentication user name, password, etc), and then set osC to use Sendmail. No changes to any osC files!

I spent way too much time today trying to get the WAMP server to send SMTP mail. This was way simpler!

HTH

Malcolm


Get the latest Responsive osCommerce CE (community edition) here .

Share this post


Link to post
Share on other sites
On 5/13/2020 at 6:53 PM, ArtcoInc said:

@bodhizatfa

There is a program called 'Fake Sendmail'. I have just installed it on my WAMP box here. You configure the sendmail.ini file with all of your SMTP mail configurations (server, port, authentication user name, password, etc), and then set osC to use Sendmail. No changes to any osC files!

I spent way too much time today trying to get the WAMP server to send SMTP mail. This was way simpler!

HTH

Malcolm

Thanks, Malcolm, I was looking at this too actually.  Thanks for the heads-up! I give it a try too! Matt's code works like a charm as well!

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

×