Post by HamadaRh » Sun Sep 12, 2021 12:27 am

Hello,
I have an issue when use SMTP as send mails at opencart
https://prnt.sc/1rue7mp , https://prnt.sc/1rue9og

as same here if I use mail() it works fine but if I enable SMTP got an error at encoding message as the previous screen
posting.php?mode=quote&f=161&p=674540 ,, How to solve that database and language encoding well as utf8

source of message which have issue at encoding
https://prnt.sc/1rue0ku have utf8 correctly

Open version is 3.0.2.0

Newbie

Posts

Joined
Mon Aug 19, 2019 4:57 pm

Post by straightlight » Mon Sep 13, 2021 5:44 pm

Lack. Email error messages. The link you referred is a posting link. I would not suggest that. Rather post the referenced posted link rather than the posting page itself to avoid security issues. In addition, this topic may help but might also be related to server-specifics configuration in order to gather a proper response from SMTP: viewtopic.php?t=199510 .

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by ADD Creative » Mon Sep 13, 2021 9:47 pm

Could be this issue. https://github.com/opencart/opencart/issues/6880

The posted fix never worked. But this one might help.
https://github.com/opencart/opencart/pull/9460/files
Last edited by ADD Creative on Tue Sep 14, 2021 12:03 am, edited 1 time in total.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by by mona » Mon Sep 13, 2021 11:32 pm

you can try this

instead of this:

Code: Select all

			foreach ($lines as $line) {
				$results = str_split($line, 998);

Code: Select all

			// message splitting length adjustment based on encoding
			$length = (mb_detect_encoding($message, mb_detect_order(), true) == 'ASCII') ? 998 : 249;
			
			foreach ($lines as $line) {
				// split the line
				$results = str_split($line, $length);
				...

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by straightlight » Mon Sep 13, 2021 11:36 pm

mb_detect_encoding needs to be installed for this and not all servers supports it by default.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by ADD Creative » Tue Sep 14, 2021 12:03 am

by mona wrote:
Mon Sep 13, 2021 11:32 pm
you can try this

instead of this:

Code: Select all

			foreach ($lines as $line) {
				$results = str_split($line, 998);

Code: Select all

			// message splitting length adjustment based on encoding
			$length = (mb_detect_encoding($message, mb_detect_order(), true) == 'ASCII') ? 998 : 249;
			
			foreach ($lines as $line) {
				// split the line
				$results = str_split($line, $length);
				...
That will make things worse. Splitting the data into smaller chunks just increases the chance that the split occurs in the middle of a multi-byte character.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by by mona » Tue Sep 14, 2021 6:34 pm

you can also use:

Code: Select all

		$lines = explode("\n", $message);
			$length = 998;
			foreach ($lines as $line) {
				$results = array();
				$line_len = mb_strlen($line);
				// split the line on characters instead of bytes if needed.
				while ($line_len) {
					$results[] = mb_substr($line,0,$length,"UTF-8");
					$line = mb_substr($line,$length,$line_len,"UTF-8");
					$line_len = mb_strlen($line);
				}
				
				foreach ($results as $result) {
					if (substr(PHP_OS, 0, 3) != 'WIN') {
						fputs($handle, $result . "\r\n");
					} else {
						fputs($handle, str_replace("\n", "\r\n", $result) . "\r\n");
					}
				}
			}

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by ADD Creative » Tue Sep 14, 2021 8:00 pm

by mona wrote:
Tue Sep 14, 2021 6:34 pm
you can also use:

Code: Select all

		$lines = explode("\n", $message);
			$length = 998;
			foreach ($lines as $line) {
				$results = array();
				$line_len = mb_strlen($line);
				// split the line on characters instead of bytes if needed.
				while ($line_len) {
					$results[] = mb_substr($line,0,$length,"UTF-8");
					$line = mb_substr($line,$length,$line_len,"UTF-8");
					$line_len = mb_strlen($line);
				}
				
				foreach ($results as $result) {
					if (substr(PHP_OS, 0, 3) != 'WIN') {
						fputs($handle, $result . "\r\n");
					} else {
						fputs($handle, str_replace("\n", "\r\n", $result) . "\r\n");
					}
				}
			}
That is still wrong. The 998 limit is in bytes. mb_substr works in characters and could return a string longer than 998 bytes, as each character could be up to 4 bytes. You could set the length to 249 (998 / 4).

I think it would just be easier to encode as base64, which is not multi-byte, as already done in 3.0.3.8.
https://github.com/opencart/opencart/pull/9460/files

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by by mona » Fri Sep 17, 2021 2:59 am

I think “wrong” is rather a strong word when base64 text can be flagged as spam by service providers.
It is an alternative suggestion, maybe not perfect, but one which may be useful to someone in light of the above.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by ADD Creative » Fri Sep 17, 2021 5:57 am

It's wrong in a sense that the length MUST not be greater than 998 bytes and some mail servers won't accept the email if a line is over 998 bytes long. Which makes it pointless to split the line into lengths that could be greater than 998 bytes.
Have a read of the RFC. https://datatracker.ietf.org/doc/html/r ... tion-2.1.1

Whereas a unnecessary base64 encoded message MIGHT be weighted towards spam.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by by mona » Fri Sep 17, 2021 6:08 am

So all in all one might be rejected and one could go into spam.
Conclusion - issue not resolved

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by mikeinterserv » Fri Sep 17, 2021 7:20 am

The HTML of that email is complete BS
Send a plain text via SMTP and if that works its the HTML.
Then you need to look at what is causing that HTML to be so FUBARED

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by ADD Creative » Fri Sep 17, 2021 7:46 am

by mona wrote:
Fri Sep 17, 2021 6:08 am
So all in all one might be rejected and one could go into spam.
Conclusion - issue not resolved
I disagree. One is in violation of the standards and will cause issues. The other unlikely to be a issue as encoding an 8-bit or multi-byte character set, shouldn't be treated as unnecessary.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom
Who is online

Users browsing this forum: sidclel and 84 guests