Page 1 of 2

[SOLVED] - Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Fri Apr 10, 2020 4:52 am
by head_dunce
So I got another order yesterday where the card was charged, but somehow OC doesn't receive the response back from Authorize.net (or at least it's not tagged on the order history) and the order is stuck as "Missing" even though the card was actually charged. Customer said they were stuck on the final screen with a spinning arrow, never made it to the final order complete page.

Here's the apache logs that I think might be the problem - oddly -
access_log

Code: Select all

173.23.61.15 - - [08/Apr/2020:10:12:50 -0500] "POST /index.php?route=extension/payment/authorizenet_aim/send HTTP/1.1" 500 - "https://www.carguygarage.com/index.php?route=checkout/checkout" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0"
error_log

Code: Select all

[Wed Apr 08 10:12:52.655446 2020] [php7:error] [pid 24657] [client 173.23.61.15:65528] 
PHP Fatal error:  Uncaught Exception: Error: MAIL FROM not accepted from server! in /var/www/html/system/library/mail/smtp.php:242\n
Stack trace:\n
#0 /var/www/html/system/library/mail.php(142): Mail\\Smtp->send()\n
#1 /var/www/html/catalog/controller/mail/order.php(275): Mail->send()\n
#2 /var/www/html/catalog/controller/mail/order.php(34): ControllerMailOrder->add(Array, '2', 'Authorization C...', false)\n
#3 /var/www/storage/modification/system/engine/action.php(79): ControllerMailOrder->index('checkout/order/...', Array)\n
#4 /var/www/storage/modification/system/engine/event.php(67): Action->execute(Object(Registry), Array)\n
#5 /var/www/storage/modification/system/engine/loader.php(237): Event->trigger('model/checkout/...', Array)\n
#6 /var/www/html/system/engine/proxy.php(47): Loader->{closure}(Array, Array)\n
#7 /var/www/html/catalog/controller/extension/payment/authorizenet_aim.php(156): Proxy->__call('addOrderHistory', Array)\n
#8 /var/www/storage/modification/system/engine/action.php(79): ControllerExtensionPaymentAuthorizeNetAim->send() in /var/www/html/system/library/mail/smtp.php on line 242, referer: https://www.carguygarage.com/index.php?route=checkout/checkout
I'm not very familiar with this system yet, maybe someone here has some insight?
I am using SMTP via Gmail ssl://smtp-relay.gmail.com if that matters. And I have had many orders since this one without any problems.

Thanks for any help.

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Fri Apr 10, 2020 5:15 am
by head_dunce
Well, I don't see anything strange in the mail log. Only thing around that time is actually after the fact -

Code: Select all

Apr  8 10:12:56 opencart-carguygarage postfix/pickup[19906]: 0CDBE453CA4: uid=0 from=<root>
Apr  8 10:12:56 opencart-carguygarage postfix/cleanup[25710]: 0CDBE453CA4: message-id=<20200408151256.0CDBE453CA4@opencart-carguygarage.localdomain>
Apr  8 10:12:56 opencart-carguygarage postfix/qmgr[1421]: 0CDBE453CA4: from=<root@opencart-carguygarage.localdomain>, size=1256, nrcpt=1 (queue active)
Apr  8 10:12:56 opencart-carguygarage postfix/cleanup[25710]: 15C1F453B26: message-id=<20200408151256.0CDBE453CA4@opencart-carguygarage.localdomain>
Apr  8 10:12:56 opencart-carguygarage postfix/qmgr[1421]: 15C1F453B26: from=<root@opencart-carguygarage.localdomain>, size=1424, nrcpt=1 (queue active)
Apr  8 10:12:56 opencart-carguygarage postfix/local[25714]: 0CDBE453CA4: to=<root@opencart-carguygarage.localdomain>, orig_to=<root>, relay=local, delay=693, delays=693/0.01/0/0, dsn=2.0.0, status=sent (forwarded as 15C1F453B26)
Apr  8 10:12:56 opencart-carguygarage postfix/qmgr[1421]: 0CDBE453CA4: removed
Apr  8 10:12:56 opencart-carguygarage postfix/smtp[25715]: 15C1F453B26: to=<jim@carguygarage.com>, orig_to=<root>, relay=aspmx.l.google.com[172.217.212.27]:25, delay=0.51, delays=0/0.01/0.19/0.31, dsn=2.0.0, status=sent (250 2.0.0 OK  1586358776 u23si5756477jam.33 - gsmtp)
Apr  8 10:12:56 opencart-carguygarage postfix/qmgr[1421]: 15C1F453B26: removed
Looking at the code
/var/www/html/system/library/mail/smtp.php
My only guess right now is that the SMTP call timed out? I have the SMTP set to timeout after 5 seconds. Not sure if that's something that's logged somewhere...

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Fri Apr 10, 2020 5:29 am
by thekrotek
Error says for itself: "MAIL FROM not accepted from server!"

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Fri Apr 10, 2020 7:22 am
by straightlight
See this solution: viewtopic.php?f=202&t=216989 .

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 3:07 am
by head_dunce
Well, the solution in that post is to use SMTP and not free gmail -- and I use SMTP with paid Gmail (email at my domain configured at the DNS to go through Gmail at my domain.)

I made a bunch of changes to SELinux today, but being that most orders don't have a problem, I'm doubting that will make a difference.

I'll have to look at the OC code some more, but it seems if the email doesn't go out the whole order process just dies? I'm on old Perl geek, not sure if this can be done in PHP, but maybe the email sending process can be forked off so it doesn't slow down anything? --- In testing the affiliate sign up process yesterday, I noticed that affiliate registration takes about as long as the order process. I thought the bottleneck with the slow order processing was the gateway, but it seems it's actually the email sending?!?

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 3:13 am
by straightlight
head_dunce wrote:
Sat Apr 11, 2020 3:07 am
Well, the solution in that post is to use SMTP and not free gmail -- and I use SMTP with paid Gmail (email at my domain configured at the DNS to go through Gmail at my domain.)

I made a bunch of changes to SELinux today, but being that most orders don't have a problem, I'm doubting that will make a difference.

I'll have to look at the OC code some more, but it seems if the email doesn't go out the whole order process just dies? I'm on old Perl geek, not sure if this can be done in PHP, but maybe the email sending process can be forked off so it doesn't slow down anything? --- In testing the affiliate sign up process yesterday, I noticed that affiliate registration takes about as long as the order process. I thought the bottleneck with the slow order processing was the gateway, but it seems it's actually the email sending?!?
See this solution for slow time response with emails: viewtopic.php?f=202&t=216948&p=782228#p782228 . The original SMTP class file for v3.1.0.0 can be found here: https://github.com/opencart/opencart/bl ... l/smtp.php .

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 3:19 am
by head_dunce
thekrotek wrote:
Fri Apr 10, 2020 5:29 am
Error says for itself: "MAIL FROM not accepted from server!"
Ha, smart@$$ -- that's an OC generated error
If you look at /var/www/html/system/library/mail/smtp.php

Code: Select all

    241                         if (substr($reply, 0, 3) != 250) {
    242                                 throw new \Exception('Error: MAIL FROM not accepted from server!');
    243                         }
You'll see that error is thrown if it doesn't find 250, so there could be a few reasons 250 doesn't show up.

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 3:22 am
by head_dunce
straightlight wrote:
Sat Apr 11, 2020 3:13 am
See this solution for slow time response with emails: viewtopic.php?f=202&t=216948&p=782228#p782228 . The original SMTP class file for v3.1.0.0 can be found here: https://github.com/opencart/opencart/bl ... l/smtp.php .
Thanks, I'll poke around.

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 3:22 am
by straightlight
head_dunce wrote:
Sat Apr 11, 2020 3:19 am
thekrotek wrote:
Fri Apr 10, 2020 5:29 am
Error says for itself: "MAIL FROM not accepted from server!"
Ha, smart@$$ -- that's an OC generated error
If you look at /var/www/html/system/library/mail/smtp.php

Code: Select all

    241                         if (substr($reply, 0, 3) != 250) {
    242                                 throw new \Exception('Error: MAIL FROM not accepted from server!');
    243                         }
You'll see that error is thrown if it doesn't find 250, so there could be a few reasons 250 doesn't show up.
The solution posted from my previous reply is about line 250. See if it solves the issue.

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 4:44 am
by head_dunce
First, looked up forking in PHP and found out that you can't fork PHP unless it's called by command line. So that ain't gonna work here.

So I'm looking over -
/var/www/html/system/library/mail/smtp.php
But the send() function doesn't return anything to the caller, so why wait for it?
Seems that the line --

Code: Select all

$handle = fsockopen($hostname, $this->smtp_port, $errno, $errstr, $this->smtp_timeout);
And everything below it can be put into another file, then just called with
https://www.php.net/manual/en/function.exec.php
And toss the output to /dev/null so it doesn't wait for it to send the mail

Code: Select all

Note: If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
...but late in the day on Friday here, so project for another day

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 11:42 am
by letxobnav
That is a revolutionary idea, never mind that smtp is a hand-shake protocol, just throw the mail out there and move on.
Here's a thought, use the mail engine instead, it does exactly that.

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 8:11 pm
by head_dunce
letxobnav wrote:
Sat Apr 11, 2020 11:42 am
That is a revolutionary idea, never mind that smtp is a hand-shake protocol, just throw the mail out there and move on.
Here's a thought, use the mail engine instead, it does exactly that.
Sending the mail wouldn't change, it just wouldn't hold up or block the rest of the script so things like checkout and registration wouldn't wait for the email handshake before giving the customer the final checkout page. What's the point of having the rest of the code wait for the handshake and send? Seems that send() function doesn't return anything, so why make the customer wait?

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 8:16 pm
by head_dunce
Ah, I see from your post on the other similar topic you have a fancy extension that catches and queues the sends which would also accomplish separating the email sending from the checkout process -
https://www.opencart.com/index.php?rout ... n_id=37838
That's pretty cool

Re: [SOLVED] - Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 8:53 pm
by letxobnav
Sending the mail wouldn't change
I don't think you have completely understood how smtp mail works.

Re: Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 8:59 pm
by straightlight
letxobnav wrote:
Sat Apr 11, 2020 11:42 am
That is a revolutionary idea, never mind that smtp is a hand-shake protocol, just throw the mail out there and move on.
Here's a thought, use the mail engine instead, it does exactly that.
Using Mail protocol is not safe since there are more and more web hosting services using SMTP via SSL. Using Mail will only increase chances for recipients to receive emails under their SPAM folder or even not even able to receive them at all as opposed to SMTP outgoing emails.

Re: [SOLVED] - Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 9:25 pm
by head_dunce
Odd that this post was marked solved when nothing was solved. Sad this forum is so hostile.

Re: [SOLVED] - Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sat Apr 11, 2020 11:33 pm
by ADD Creative
Orders not completing because the sending of mail via SMTP failed can be really annoying for store owners. The root cause of the problem is the throwing of exceptions SMTP mail class, which are then not caught. Sure the store owner would like to know about the mail problem, but they wouldn't want it to stop the order completing. It's been reported, but sadly closed here. https://github.com/opencart/opencart/issues/7633

There are a few ways round this.
1. Use "Mail" instead of "SMTP" in the OpenCart mail settings. The "Mail" mail class doesn't throw exceptions so never hinders the completion of the order. A word of warning. Sometimes the server has the PHP mail function disabled or if the server isn't configured well you can have problems with mail going to spam.

2. Edit the SMTP mail class to remove all the exceptions. Just log the errors and return.

3. Edit the mail class to catch the exceptions and just log the errors.

4. Replace the mail class with something more fault tolerant. There are probably solutions in the marketplace that do this.

Re: [SOLVED] - Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sun Apr 12, 2020 1:15 am
by straightlight
head_dunce wrote:
Sat Apr 11, 2020 9:25 pm
Odd that this post was marked solved when nothing was solved. Sad this forum is so hostile.
The reason why it has been set to solved, without the hostilities, is because the reported issue has obviously nothing to do with Opencart itself at this point.

Re: [SOLVED] - Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Sun Apr 12, 2020 2:40 am
by ADD Creative
The reported issue is to do with OpenCart and the way it handles errors when sending email via SMTP. No SMTP server or connection is going to be 100% perfect, so for OpenCart to allow this to affect the completion of the order is just wrong.

Re: [SOLVED] - Order Doesn't Get Authorize.net Response - weird email issue?

Posted: Mon Apr 13, 2020 5:31 am
by head_dunce
ADD Creative wrote:
Sun Apr 12, 2020 2:40 am
The reported issue is to do with OpenCart and the way it handles errors when sending email via SMTP. No SMTP server or connection is going to be 100% perfect, so for OpenCart to allow this to affect the completion of the order is just wrong.
Thanks. I wrote the updated code to execute the sending of the mail as an external script so the order processing doesn't wait for it. Honestly pretty easy update, will post it once I finish it up - where I'm at now is below -

Basically....
copy /var/www/html/system/library/mail/smtp.php
to say /var/www/html/system/library/mail/smtp-send.php

smtp.php gets this in the send() function and delete the rest

Code: Select all

$shellsend = "php /var/www/html/system/library/mail/smtp-send.php --smtp_hostname='".$this->smtp_hostname."' --smtp_port='".$this->smtp_port."' --smtp_timeout='".$this->smtp_timeout."' --smtp_username='".$this->smtp_username."' --smtp_password='".$this->smtp_password."' --server_name='".getenv('SERVER_NAME')."' --from='".$this->from."' --to='[need to set up to for array]' --subject=".escapeshellarg($this->subject)." --sender='".$this->sender."' --reply_to='".$this->reply_to."' --html=".escapeshellarg($this->html)." --text=".escapeshellarg($this->text)." ";
exec($shellsend . " > /dev/null &");
smtp-send.php comment out the class and function and pick up the vars from the command line

Code: Select all

#namespace Mail;
#class Smtp {
#       public $smtp_hostname;
#       public $smtp_username;
#       public $smtp_password;
#       public $smtp_port = 25;
#       public $smtp_timeout = 5;
#       public $verp = false;
#
#       public function send() {

$this_smtp_hostname = (getopt(null, ['smtp_hostname:'] ))['smtp_hostname'];
$this_smtp_port = (getopt(null, ['smtp_port:']))['smtp_port'];
$this_smtp_timeout = (getopt(null, ['smtp_timeout:']))['smtp_timeout'];
$this_smtp_username = (getopt(null, ['smtp_username:']))['smtp_username'];
$this_smtp_password = (getopt(null, ['smtp_password:']))['smtp_password'];
$server_name = (getopt(null, ['server_name:']))['server_name'];
$this_from = (getopt(null, ['from:']))['from'];
$this_to = (getopt(null, ['to:']))['to'];
$this_subject = (getopt(null, ['subject:']))['subject'];
$this_sender = (getopt(null, ['sender:']))['sender'];
$this_reply_to = (getopt(null, ['reply_to:']))['reply_to'];
$this_html = (getopt(null, ['html:']))['html'];
$this_text = (getopt(null, ['text:']))['text'];

$this_attachments = [];
$this_verp = '';
Then edit the vars to change up $this-> to basically $this_
Eh, that's where I'm at now, and it's working.