Post by drag84 » Wed Aug 14, 2024 1:41 pm

Hello,

I have a problem that when I change the status of an order and select to inform the customer by email I get the following error:

Code: Select all

SyntaxError: JSON Parse error: Unrecognized token '<'
parsererror
<b>Warning</b>: mail() has been disabled for security reasons in <b>/home/abc/public_html/system/library/mail/mail.php</b> on line <b>75</b>{"success":"J\u016bs s\u0117kmingai modifikavote u\u017esakymus"}
my SMTP settings:

Image

OC: 3.0.3.8

Please help me solve the problem

Newbie

Posts

Joined
Thu Aug 04, 2022 4:56 pm

Post by softmonke » Wed Aug 14, 2024 2:00 pm

The warning is because your web host has disabled "mail()" probably to prevent spam or abuse.

But strange that you are getting this error despite using SMTP already. Anyway, try changing "ssl:/" to "ssl://" for your SMTP Hostname field.

Check out our ever-growing list of extensions for OpenCart here.
Some useful extensions for a better admin experience: Image File Manager ProDrag & Drop Sort Order

Reach out to us at hello@softmonke.com for your OpenCart web development needs or feedback for our extensions.


User avatar
Active Member

Posts

Joined
Tue May 23, 2023 4:42 am


Post by paulfeakins » Wed Aug 14, 2024 7:57 pm

drag84 wrote:
Wed Aug 14, 2024 1:41 pm
Please help me solve the problem
It literally tells you the problem:

Code: Select all

mail() has been disabled for security reasons
So ask your web host to enable it, or use SMTP instead.

Here are instructions on how to use SMTP: https://www.antropy.co.uk/blog/stop-ope ... spam-smtp/

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by drag84 » Mon Aug 19, 2024 2:21 am

softmonke wrote:
Wed Aug 14, 2024 2:00 pm
The warning is because your web host has disabled "mail()" probably to prevent spam or abuse.

But strange that you are getting this error despite using SMTP already. Anyway, try changing "ssl:/" to "ssl://" for your SMTP Hostname field.
Thank you, I have changed it to "ssl://".

I made a test purchase but did not receive an email from my e-shop.
I have also changed the order status, no error is displayed but I don't get an email to my gmail. What could be the problem?

Briefly:
  • As a customer, I don't receive a letter.
    As an admin, I don't get an email about my order either.

Newbie

Posts

Joined
Thu Aug 04, 2022 4:56 pm

Post by ADD Creative » Mon Aug 19, 2024 4:04 pm

Check both your PHP and OpenCart error logs. Check you mail server logs to see it the emails are reaching your mail server. Use and online email deliverability checker, such as mail-tester.com to check your outgoing emails.

www.add-creative.co.uk


Guru Member

Posts

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

Post by khnaz35 » Tue Aug 20, 2024 2:02 pm

Emails related issues are well know in OC. Lets do the follow test.
use your sftp/ftp to login to your site and headtowards your
public_html/system/library/mail here rename your old file smtp.php and then create a new file with the same name smtp.php

and add this content in the file.

Code: Select all

<?php
namespace Mail;

class Smtp {
    public $smtp_hostname;
    public $smtp_username;
    public $smtp_password;
    public $smtp_port = 25;
    public $smtp_timeout = 5;
    public $max_attempts = 3;
    public $verp = false;
    private $log;

    // Constructor - no need to pass the Log object
    public function __construct() {
        $this->log = new \Log('mail.log'); // Create a log instance directly here
    }

    public function send() {
        $this->log->write('SMTP send method started.');

        if (is_array($this->to)) {
            $to = implode(',', $this->to);
        } else {
            $to = $this->to;
        }

        $boundary = '----=_NextPart_' . md5(time());

        $header = 'MIME-Version: 1.0' . PHP_EOL;
        $header .= 'To: <' . $to . '>' . PHP_EOL;
        $header .= 'Subject: =?UTF-8?B?' . base64_encode($this->subject) . '?=' . PHP_EOL;
        $header .= 'Date: ' . date('D, d M Y H:i:s O') . PHP_EOL;
        $header .= 'From: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;

        if (!$this->reply_to) {
            $header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;
        } else {
            $header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->reply_to) . '?= <' . $this->reply_to . '>' . PHP_EOL;
        }

        $header .= 'Return-Path: ' . $this->from . PHP_EOL;
        $header .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;
        $header .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . PHP_EOL . PHP_EOL;

        if (!$this->html) {
            $message = '--' . $boundary . PHP_EOL;
            $message .= 'Content-Type: text/plain; charset="utf-8"' . PHP_EOL;
            $message .= 'Content-Transfer-Encoding: base64' . PHP_EOL . PHP_EOL;
            $message .= base64_encode($this->text) . PHP_EOL;
        } else {
            $message = '--' . $boundary . PHP_EOL;
            $message .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '_alt"' . PHP_EOL . PHP_EOL;
            $message .= '--' . $boundary . '_alt' . PHP_EOL;
            $message .= 'Content-Type: text/plain; charset="utf-8"' . PHP_EOL;
            $message .= 'Content-Transfer-Encoding: base64' . PHP_EOL . PHP_EOL;

            if ($this->text) {
                $message .= base64_encode($this->text) . PHP_EOL;
            } else {
                $message .= base64_encode('This is a HTML email and your email client software does not support HTML email!') . PHP_EOL;
            }

            $message .= '--' . $boundary . '_alt' . PHP_EOL;
            $message .= 'Content-Type: text/html; charset="utf-8"' . PHP_EOL;
            $message .= 'Content-Transfer-Encoding: base64' . PHP_EOL . PHP_EOL;
            $message .= base64_encode($this->html) . PHP_EOL;
            $message .= '--' . $boundary . '_alt--' . PHP_EOL;
        }

        foreach ($this->attachments as $attachment) {
            if (file_exists($attachment)) {
                $handle = fopen($attachment, 'r');

                $content = fread($handle, filesize($attachment));

                fclose($handle);

                $message .= '--' . $boundary . PHP_EOL;
                $message .= 'Content-Type: application/octet-stream; name="' . basename($attachment) . '"' . PHP_EOL;
                $message .= 'Content-Transfer-Encoding: base64' . PHP_EOL;
                $message .= 'Content-Disposition: attachment; filename="' . basename($attachment) . '"' . PHP_EOL;
                $message .= 'Content-ID: <' . urlencode(basename($attachment)) . '>' . PHP_EOL;
                $message .= 'X-Attachment-Id: ' . urlencode(basename($attachment)) . PHP_EOL . PHP_EOL;
                $message .= chunk_split(base64_encode($content));
            }
        }

        $message .= '--' . $boundary . '--' . PHP_EOL;

        if (substr($this->smtp_hostname, 0, 3) == 'tls') {
            $hostname = substr($this->smtp_hostname, 6);
        } else {
            $hostname = $this->smtp_hostname;
        }

        $this->log->write('Connecting to SMTP server: ' . $hostname . ':' . $this->smtp_port);
        $handle = fsockopen($hostname, $this->smtp_port, $errno, $errstr, $this->smtp_timeout);

        if (!$handle) {
            $this->log->write('SMTP connection failed: ' . $errstr . ' (' . $errno . ')');
            throw new \Exception('Error: ' . $errstr . ' (' . $errno . ')');
        } else {
            $this->log->write('SMTP connection established.');

            if (substr(PHP_OS, 0, 3) != 'WIN') {
                socket_set_timeout($handle, $this->smtp_timeout, 0);
            }

            while ($line = fgets($handle, 515)) {
                $this->log->write('SMTP Response: ' . $line);
                if (substr($line, 3, 1) == ' ') {
                    break;
                }
            }

            fputs($handle, 'EHLO ' . getenv('SERVER_NAME') . "\r\n");

            $reply = '';

            while ($line = fgets($handle, 515)) {
                $reply .= $line;
                $this->log->write('SMTP EHLO Response: ' . $line);

                if (substr($reply, 0, 3) == 220 && substr($line, 3, 1) == ' ') {
                    $reply = '';
                    continue;
                } else if (substr($line, 3, 1) == ' ') {
                    break;
                }
            }

            if (substr($reply, 0, 3) != 250) {
                $this->log->write('EHLO not accepted from server: ' . $reply);
                throw new \Exception('Error: EHLO not accepted from server!');
            }

            if (substr($this->smtp_hostname, 0, 3) == 'tls') {
                $this->log->write('Starting TLS encryption.');
                fputs($handle, 'STARTTLS' . "\r\n");

                $this->handleReply($handle, 220, 'Error: STARTTLS not accepted from server!');

                stream_socket_enable_crypto($handle, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
            }

            if (!empty($this->smtp_username) && !empty($this->smtp_password)) {
                fputs($handle, 'EHLO ' . getenv('SERVER_NAME') . "\r\n");

                $this->handleReply($handle, 250, 'Error: EHLO not accepted from server!');

                fputs($handle, 'AUTH LOGIN' . "\r\n");

                $this->handleReply($handle, 334, 'Error: AUTH LOGIN not accepted from server!');

                fputs($handle, base64_encode($this->smtp_username) . "\r\n");

                $this->handleReply($handle, 334, 'Error: Username not accepted from server!');

                fputs($handle, base64_encode($this->smtp_password) . "\r\n");

                $this->handleReply($handle, 235, 'Error: Password not accepted from server!');
            } else {
                fputs($handle, 'HELO ' . getenv('SERVER_NAME') . "\r\n");

                $this->handleReply($handle, 250, 'Error: HELO not accepted from server!');
            }

            if ($this->verp) {
                fputs($handle, 'MAIL FROM: <' . $this->from . '>XVERP' . "\r\n");
            } else {
                fputs($handle, 'MAIL FROM: <' . $this->from . '>' . "\r\n");
            }

            $this->handleReply($handle, 250, 'Error: MAIL FROM not accepted from server!');

            if (!is_array($this->to)) {
                fputs($handle, 'RCPT TO: <' . $this->to . '>' . "\r\n");

                $reply = $this->handleReply($handle, false, 'RCPT TO [!array]');

                if ((substr($reply, 0, 3) != 250) && (substr($reply, 0, 3) != 251)) {
                    $this->log->write('RCPT TO not accepted from server: ' . $reply);
                    throw new \Exception('Error: RCPT TO not accepted from server!');
                }
            } else {
                foreach ($this->to as $recipient) {
                    fputs($handle, 'RCPT TO: <' . $recipient . '>' . "\r\n");

                    $reply = $this->handleReply($handle, false, 'RCPT TO [array]');

                    if ((substr($reply, 0, 3) != 250) && (substr($reply, 0, 3) != 251)) {
                        $this->log->write('RCPT TO not accepted from server: ' . $reply);
                        throw new \Exception('Error: RCPT TO not accepted from server!');
                    }
                }
            }

            fputs($handle, 'DATA' . "\r\n");

            $this->handleReply($handle, 354, 'Error: DATA not accepted from server!');

            $message = str_replace("\r\n", "\n", $header . $message);
            $message = str_replace("\r", "\n", $message);

            $length = (mb_detect_encoding($message, mb_detect_order(), true) == 'ASCII') ? 998 : 249;

            $lines = explode("\n", $message);

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

                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");
                    }
                }
            }

            fputs($handle, '.' . "\r\n");

            $this->handleReply($handle, 250, 'Error: DATA not accepted from server!');

            fputs($handle, 'QUIT' . "\r\n");

            $this->handleReply($handle, 221, 'Error: QUIT not accepted from server!');

            $this->log->write('SMTP mail sent successfully.');

            fclose($handle);
        }
    }

    private function handleReply($handle, $status_code = false, $error_text = false, $counter = 0) {
        $reply = '';

        while (($line = fgets($handle, 515)) !== false) {
            $reply .= $line;

            if (substr($line, 3, 1) == ' ') {
                break;
            }
        }

        // Handle slowish server responses (generally due to policy servers)
        if (!$line && empty($reply) && $counter < $this->max_attempts) {
            sleep(1);

            $counter++;
            $this->log->write('Slow server response, retry attempt: ' . $counter);

            return $this->handleReply($handle, $status_code, $error_text, $counter);
        }

        if ($status_code && substr($reply, 0, 3) != $status_code) {
            $this->log->write('Expected status code ' . $status_code . ' but received ' . substr($reply, 0, 3) . ': ' . $reply);
            throw new \Exception($error_text . ' - Received: ' . $reply);
        }

        $this->log->write('SMTP Reply: ' . $reply);

        return $reply;
    }
}
Once you done it refresh your modification/theme cache and make a test order or send a test email via marketing . once done head towards your public_html_backu/system/storage/logs you should see a new log file name mail.log share that with us back here.

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by JNeuhoff » Tue Aug 20, 2024 5:21 pm

Your SMTP Hostname setting should start with 'ssl://', not 'ssl:/' !

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by khnaz35 » Tue Aug 20, 2024 6:14 pm

JNeuhoff wrote:
Tue Aug 20, 2024 5:21 pm
Your SMTP Hostname setting should start with 'ssl://', not 'ssl:/' !
OP did mention that he changed it

Code: Select all

Thank you, I have changed it to "ssl://".

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by drag84 » Wed Aug 21, 2024 9:03 pm

khnaz35 wrote:
Tue Aug 20, 2024 6:14 pm
JNeuhoff wrote:
Tue Aug 20, 2024 5:21 pm
Your SMTP Hostname setting should start with 'ssl://', not 'ssl:/' !
OP did mention that he changed it

Code: Select all

Thank you, I have changed it to "ssl://".
Yes, I changed it, but I haven't found the problem yet

Newbie

Posts

Joined
Thu Aug 04, 2022 4:56 pm

Post by khnaz35 » Mon Nov 04, 2024 10:43 pm

drag84 wrote:
Wed Aug 21, 2024 9:03 pm
Yes, I changed it, but I haven't found the problem yet
Have you tested with my shared code?

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

User avatar
Legendary Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by carlswart@gmail.com » Wed Nov 27, 2024 6:02 am

khnaz35 wrote:
Tue Aug 20, 2024 2:02 pm
Thank you ... This helped me discover the problem in why my OC was not sending emails. :dance: :good:


Posts

Joined
Sat Aug 13, 2022 7:22 pm

Post by khnaz35 » Wed Nov 27, 2024 5:11 pm

carlswart@gmail.com wrote:
Wed Nov 27, 2024 6:02 am
Thank you ... This helped me discover the problem in why my OC was not sending emails. :dance: :good:
Glad could be of help

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia
Who is online

Users browsing this forum: lockiedownunder and 15 guests