Post by arrakis99 » Wed Dec 02, 2009 7:25 pm

Hello,
I've changed the mail.php class as suggested by Daniel in the followinf thread (Mail problem fix)

http://forum.opencart.com/viewtopic.php?f=31&t=8075

BUT, after some testing I can tell you that the problem is still alive :-[

Here is my setup and what is happening:

- My server is Suse Linux based

- OC is configured to send mails through "mail" function (not SMTP)

- If from OC I send an email to a customer that has a gmail or yahoo account and he/she reads the email through the web mail, then the mail is READABLE
- If the customer use Outlook to read the emails, then the mails sent by OC are UNREADABLE
- The same thing happen with "confirmation" emails

Obviously I cannot tell to my customer to not use Outlook and the UNREADABLE MAIL PROBLEM
is a really big one...

Please help me...

Thanks a lot for you efforts

P.S.: OpenCart is a wonderful thing !

New member

Posts

Joined
Thu Jul 16, 2009 5:50 pm

Post by flawless » Wed Dec 02, 2009 10:21 pm

I have the same problem!

Newbie

Posts

Joined
Mon Oct 26, 2009 8:58 pm

Post by fido-x » Wed Dec 02, 2009 11:08 pm

The bug is not in OpenCart. The bug is Outlook (I mean in Outlook ;D )! It seems to be the only email client that has problems with emails sent out by OpenCart.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Xsecrets » Thu Dec 03, 2009 12:34 am

fido-x wrote:The bug is not in OpenCart. The bug is Outlook (I mean in Outlook ;D )! It seems to be the only email client that has problems with emails sent out by OpenCart.
well unfortunately it is also the most used mail client on the planet probably, so just saying sorry it doesn't work won't cut it. it works just fine with mail from all other ecommerce/cms/whatever and it needs to work with opencart. I know it may be a pain to deal with, but email not working with outlook is pretty much a dealbreaker for ecommerce.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by gilbe » Thu Dec 03, 2009 1:57 am

Hi,

Ok so I dont know how well coded or safe this is, so someone let me know. But what I've done is taken off the "base64" encryption from the emails in the header and changed it to 8bit. This seems to have cured the visible problem with outlook (and other MS products) not working however, in the header source code i am still seeing a parse error which I dont know how to shake.

Im not going to loose sleep over it as the problem is fixed ... on the outside anyway.

New member

Posts

Joined
Wed Aug 05, 2009 11:00 pm


Post by flawless » Thu Dec 03, 2009 9:52 pm

I've resolved the problem.

In file system/library/mail.php the string
public $eol = "\r\n";
has been changed to
public $eol = "\n";

I'm using the linux webhosting and it resolve the problem.
Last edited by flawless on Thu Dec 03, 2009 10:34 pm, edited 1 time in total.

Newbie

Posts

Joined
Mon Oct 26, 2009 8:58 pm

Post by gilbe » Thu Dec 03, 2009 9:56 pm

Yeah thats similar to what ive done.. but didnt change the EOL part.. just the base64 to 8bit... in your case 7bit

oh and I got the parse error to go away... they were caused by the boundary's ... a little bit of tweaking sorted them out

New member

Posts

Joined
Wed Aug 05, 2009 11:00 pm


Post by flawless » Thu Dec 03, 2009 10:39 pm

Thanks Glibe
The problem has been resolved.

In file system/library/mail.php the follwing string has been changed:
//public $eol = "\r\n";
public $eol = "\n";

On linux webhosting it is working properly.

Newbie

Posts

Joined
Mon Oct 26, 2009 8:58 pm

Post by arrakis99 » Fri Dec 04, 2009 3:29 pm

I've resolved the problem.

In file system/library/mail.php the string
public $eol = "\r\n";
has been changed to
public $eol = "\n";

I'm using the linux webhosting and it resolve the problem.
Hello... I cannot find such a string in the recent mail.php class published by Daniel...
in which mail.php I must replace the string that you have suggested ?

Could you please paste here the right mail.php class to resolve the problem ?

Thanks a lot !

New member

Posts

Joined
Thu Jul 16, 2009 5:50 pm

Post by Daniel » Fri Dec 04, 2009 4:57 pm

What would be the 100~% fix for this sort of problem?

reciving email works fine for me via outlook.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by arrakis99 » Fri Dec 04, 2009 9:33 pm

Hello Daniel,
I don't really know what would be the 100% fix of this problem.
The customers of mine that use outlook receive weird and unreadable emails.
I've have replaced the mail.php class as you suggested but the problem is still here.

I asked for the right and latest mail.php class and I think I have it (I think because I have replaced and tested several mail.php classes published here but without seccess)

The best solution to avoid confusion would be to make a "sticky" post with the right php mail class.

One question: I have OC 1.3.2 ... if I "grab" the mail.php class from OC 1.3.4 would it work in OC 1.3.2 ?

Thanks Daniel

New member

Posts

Joined
Thu Jul 16, 2009 5:50 pm

Post by gilbe » Fri Dec 04, 2009 10:19 pm

Code: Select all

<?php
final class Mail {
   protected $to;
     protected $from;
     protected $sender;
     protected $subject;
     protected $text;
     protected $html;
     protected $attachments = array();
   protected $protocol = 'mail';
   protected $hostname;
   protected $username;
   protected $password;
   protected $port = 25;
   protected $timeout = 5;

   public function __construct($protocol = 'mail', $hostname = '', $username = '', $password = '', $port = '25', $timeout = '5') {
      $this->protocol = $protocol;
      $this->hostname = $hostname;
      $this->username = $username;
      $this->password = $password;
      $this->port = $port;
      $this->timeout = $timeout;   
   }
   
   public function setTo($to) {
       $this->to = $to;
     }
   
     public function setFrom($from) {
       $this->from = $from;
     }
   
   public function addheader($header, $value) {
      $this->headers[$header] = $value;
   }
   
     public function setSender($sender) {
       $this->sender = $sender;
     }

     public function setSubject($subject) {
       $this->subject = $subject;
     }
   
   public function setText($text) {
       $this->text = $text;
     }

     public function setHtml($html) {
       $this->html = $html;
     }
   
     public function addAttachment($attachment) {
      if (!is_array($attachment)) {
         $this->attachments[] = $attachment;
      } else{
         $this->attachments = array_merge($this->attachments, $attachment);
      }
     }

     public function send() {   
       if (!$this->to) {
            exit('Error: E-Mail to required!');
       }
   
       if (!$this->from) {
            exit('Error: E-Mail from required!');
       }
   
       if (!$this->sender) {
            exit('Error: E-Mail sender required!');
       }
      
      if (!$this->subject) {
            exit('Error: E-Mail subject required!');
       }
         
      if ((!$this->text) && (!$this->html)) {
            exit('Error: E-Mail message required!');
       }

      if (is_array($this->to)) {
            $to = implode(',', $this->to);
       } else {
            $to = $this->to;
       }
        
      $boundary = '----=_NextPart_' . md5(time()); 

      if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) {
            $eol = "\r\n";
       } elseif (strtoupper(substr(PHP_OS, 0, 3)=='MAC')) {
            $eol = "\r";
       } else {
            $eol = "\n";
       }    
      
      $header = '';
      
      if ($this->protocol != 'mail') {
         $header .= 'To: ' . $to . $eol;
         $header .= 'Subject: ' . $this->subject . $eol;
      }
      
      $header .= 'From: ' . $this->sender . '<' . $this->from . '>' . $eol;
       $header .= 'Reply-To: ' . $this->sender . '<' . $this->from . '>' . $eol;   
      $header .= 'Return-Path: ' . $this->from . $eol;
     $header .= 'X-Mailer: PHP/' . phpversion() . $eol; 
       $header .= 'MIME-Version: 1.0' . $eol;
      $header .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '"' . $eol; 
   
      if (!$this->html) {
           $message  = '--' . $boundary . $eol; 
           $message .= 'Content-Type: text/plain; charset="utf-8"' . $eol;
           $message .= 'Content-Transfer-Encoding: 8bit' . $eol . $eol;
            $message .= $this->text . $eol;
      } else {
           $message  = '--' . $boundary . $eol;
          //$message .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '_alt"' . $eol . $eol;
           //$message .= '--' . $boundary . '_alt' . $eol;
           $message .= 'Content-Type: text/plain; charset="utf-8"' . $eol;
           $message .= 'Content-Transfer-Encoding: 8bit' . $eol;
    
           if ($this->text) {
              $message .= $this->text . $eol;
           } else {
             $message .= 'This is a HTML email and your email client software does not support HTML email!' . $eol;
            }   
    
           $message .= '--' . $boundary . $eol;
            $message .= 'Content-Type: text/html; charset="utf-8"' . $eol;
            $message .= 'Content-Transfer-Encoding: 8bit' . $eol . $eol;
           $message .= $this->html . $eol;
         $message .= '--' . $boundary . '--' . $eol;      
      }
      
       foreach ($this->attachments as $attachment) { 
            $filename = basename($attachment); 
            $handle = fopen($attachment, 'r');
            $content = fread($handle, filesize($attachment));
     
           fclose($handle); 
    
            $message .= '--' . $boundary . $eol;
            $message .= 'Content-Type: application/octetstream' . $eol;   
            $message .= 'Content-Transfer-Encoding: 8bit' . $eol;
            $message .= 'Content-Disposition: attachment; filename="' . $filename . '"' . $eol;
            $message .= 'Content-ID: <' . $filename . '>' . $eol . $eol;
            $message .= $content . $eol;
       } 

      if ($this->protocol == 'mail') {
         ini_set('sendmail_from', $this->from);
      
          mail($to, $this->subject, $message, $header); 
      } elseif ($this->protocol == 'smtp') {
         $handle = fsockopen($this->hostname, $this->port, $errno, $errstr, $this->timeout);   
         
         if (!$handle) {
            error_log('Error: ' . $errstr . ' (' . $errno . ')');
         } else {
            if (substr(PHP_OS, 0, 3) != 'WIN') {
               socket_set_timeout($handle, $this->timeout, 0);
            }
            
            while ($line = fgets($handle, 515)) {
               if (substr($line, 3, 1) == ' ') {
                  break;
               }
            }
         
            if (substr($this->hostname, 0, 3) == 'tls') {
               fputs($handle, 'STARTTLS' . $eol);
               
               
               while ($line = fgets($handle, 515)) {
                  $reply .= $line;
               
                  if (substr($line, 3, 1) == ' ') {
                     break;
                  }
               }
            
               if (substr($reply, 0, 3) != 220) {
                  error_log('Error: STARTTLS not accepted from server!');
               }               
            }
         
            if (!empty($this->username)  && !empty($this->password)) {
               fputs($handle, 'EHLO ' . getenv('SERVER_NAME') . $eol);
               
               $reply = '';
            
               while ($line = fgets($handle, 515)) {
                  $reply .= $line;
               
                  if (substr($line, 3, 1) == ' ') {
                     break;
                  }
               }
            
               if (substr($reply, 0, 3) != 250) {
                  error_log('Error: EHLO not accepted from server!');
               }
               
               fputs($handle, 'AUTH LOGIN' . $eol);
   
               $reply = '';
            
               while ($line = fgets($handle, 515)) {
                  $reply .= $line;
               
                  if (substr($line, 3, 1) == ' ') {
                     break;
                  }
               }
               
               if (substr($reply, 0, 3) != 334) {
                  error_log('Error: AUTH LOGIN not accepted from server!');
               }
   
               fputs($handle, base64_encode($this->username) . $eol);
   
               $reply = '';
            
               while ($line = fgets($handle, 515)) {
                  $reply .= $line;
               
                  if (substr($line, 3, 1) == ' ') {
                     break;
                  }
               }
               
               if (substr($reply, 0, 3) != 334) {
                  error_log('Error: Username not accepted from server!');
               }            
   
               fputs($handle, base64_encode($this->password) . $eol);
   
               $reply = '';
            
               while ($line = fgets($handle, 515)) {
                  $reply .= $line;
               
                  if (substr($line, 3, 1) == ' ') {
                     break;
                  }
               }
               
               if (substr($reply, 0, 3) != 235) {
                  error_log('Error: Password not accepted from server!');               
               }   
            } else {
               fputs($handle, 'HELO ' . getenv('SERVER_NAME') . $eol);
   
               $reply = '';
            
               while ($line = fgets($handle, 515)) {
                  $reply .= $line;
               
                  if (substr($line, 3, 1) == ' ') {
                     break;
                  }
               }
               
               if (substr($reply, 0, 3) != 250) {
                  error_log('Error: HELO not accepted from server!');
               }            
            }
   
            fputs($handle, 'MAIL FROM: <' . $this->from . '>XVERP' . $eol);
   
            $reply = '';
         
            while ($line = fgets($handle, 515)) {
               $reply .= $line;
            
               if (substr($line, 3, 1) == ' ') {
                  break;
               }
            }
            
            if (substr($reply, 0, 3) != 250) {
               error_log('Error: MAIL FROM not accepted from server!');
            }
            
            if (!is_array($this->to)) {
               fputs($handle, 'RCPT TO: <' . $this->to . '>' . $eol);
      
               $reply = '';
            
               while ($line = fgets($handle, 515)) {
                  $reply .= $line;
               
                  if (substr($line, 3, 1) == ' ') {
                     break;
                  }
               }
            
               if ((substr($reply, 0, 3) != 250) && (substr($reply, 0, 3) != 251)) {
                  error_log('Error: RCPT TO not accepted from server!');
               }         
            } else {
               foreach ($this->to as $recipient) {
                  fputs($handle, 'RCPT TO: <' . $recipient . '>' . $eol);
         
                  $reply = '';
               
                  while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                  
                     if (substr($line, 3, 1) == ' ') {
                        break;
                     }
                  }
               
                  if ((substr($reply, 0, 3) != 250) && (substr($reply, 0, 3) != 251)) {
                     error_log('Error: RCPT TO not accepted from server!');
                  }                  
               }
            }
   
            fputs($handle, 'DATA' . $eol);
   
            $reply = '';
         
            while ($line = fgets($handle, 515)) {
               $reply .= $line;
            
               if (substr($line, 3, 1) == ' ') {
                  break;
               }
            }
                  
            if (substr($reply, 0, 3) != 354) {
               error_log('Error: DATA not accepted from server!');
            }
            
            fputs($handle, $header . $message . $eol);
            fputs($handle, '.' . $eol);
            
            $reply = '';
         
            while ($line = fgets($handle, 515)) {
               $reply .= $line;
            
               if (substr($line, 3, 1) == ' ') {
                  break;
               }
            }
            
            if (substr($reply, 0, 3) != 250) {
               error_log('Error: DATA not accepted from server!');
            }
   
            fputs($handle, 'QUIT' . $eol);
   
            $reply = '';
         
            while ($line = fgets($handle, 515)) {
               $reply .= $line;
            
               if (substr($line, 3, 1) == ' ') {
                  break;
               }
            }
            
            if (substr($reply, 0, 3) != 221) {
               error_log('Error: QUIT not accepted from server!');
            }         
            
            fclose($handle);
         }
      }
   }
}
?>
This is the mail.php Im now using with 1.3.2 and it works well. I have taken of the base64 encryption though as I didn't think it was necessary for the emails that Im sending. Have also changed the boundarys around a little bit to stop parsing errors in the mail clients.

Might want to have Daniel check over it though to make sure it wont break anything else in the system though.

New member

Posts

Joined
Wed Aug 05, 2009 11:00 pm


Post by iloveopencart » Sun Dec 06, 2009 1:35 am

Nice job, gilbe! Worked for me, too.

User avatar
Global Moderator

Posts

Joined
Thu Mar 05, 2009 11:15 pm
Location - Phoenix, AZ

Post by maema » Wed Dec 09, 2009 3:12 am

SUPER ! WORK ON ME ... I'm using mail fom apple !

New member

Posts

Joined
Fri Nov 27, 2009 3:38 am

Post by deeve » Wed Dec 09, 2009 8:45 am

Worked as PHP MAIL for me in plain text but for some reason I can't get SMTP to work on my host, UK2net. If I select SMTP I get this php header error in Admin:

Code: Select all

Warning: fsockopen() [function.fsockopen]: unable to connect to mail.uptightrecords.co.uk:25 (Connection refused) in /mypath/system/library/mail.php on line 158
imagine it's something to do with the smtp timeout.

Also the CSS in Admin Nav goes all screwy!

Active Member

Posts

Joined
Tue Oct 20, 2009 4:31 pm

Post by Daniel » Wed Dec 09, 2009 9:55 am

I think its to do with not using the right setting. port maybe or maybe need ssl://

try googling the mail settings for your provider.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by deeve » Wed Dec 09, 2009 4:20 pm

I've sent my client's ISP a support ticket & will inform others of the result, just in case there's any more UK2.net customers on here - port setting was correct. His last store ran on ZenCart which used PHP mail with no probs.

Active Member

Posts

Joined
Tue Oct 20, 2009 4:31 pm

Post by deeve » Wed Dec 09, 2009 5:36 pm

re: UK2.net & mail probs

Doh! Sometimes the answer is just staring me in the face.. :o

Turns out Outlook was placing my emails into Junk E-Mail folder as unrecognized. This then made them appear as plain text as Outlook strips Junk mail by default. When returned to Inbox, they regain their HTML attributes & all's well!

Active Member

Posts

Joined
Tue Oct 20, 2009 4:31 pm

Post by flawless » Fri Dec 11, 2009 5:39 am

gilbe wrote: This is the mail.php Im now using with 1.3.2 and it works well. I have taken of the base64 encryption though as I didn't think it was necessary for the emails that Im sending. Have also changed the boundarys around a little bit to stop parsing errors in the mail clients.

Might want to have Daniel check over it though to make sure it wont break anything else in the system though.
I have non-english site and some my clients received the messages with headers
From: ?ds? ?ds? <info@mydomain>
Subject: ?ness??d?

The following strings should be added right after the string:
$header = '';
to correct "Subject" and "From" headers for some mail servers:
$this->subject = '=?UTF-8?B?'. base64_encode($this->subject) .'?=';
$this->sender = '=?UTF-8?B?'. base64_encode($this->sender) .'?=';

It fixed the bug.

Newbie

Posts

Joined
Mon Oct 26, 2009 8:58 pm
Who is online

Users browsing this forum: No registered users and 18 guests