Post by scottyboyyy » Sat Apr 04, 2020 7:34 pm

On a clean install, I am getting this error when adding an account as an affiliate. Here is my error:

Code: Select all

Fatal error: Uncaught exception 'Exception' with message 'Error: DATA not accepted from server!' in 
.../system/library/mail/smtp.php:328 
Stack trace: 
#0 .../system/library/mail.php(142): Mail\Smtp->send() 
#1 .../catalog/controller/mail/affiliate.php(49): Mail->send() 
#2 [internal function]: ControllerMailAffiliate->index('account/custome...', Array, NULL) 
#3 .../system/engine/action.php(79): call_user_func_array(Array, Array) 
#4 .../system/engine/event.php(62): Action->execute(Object(Registry), Array) 
#5 .../system/engine/loader.php(255): Event->trigger('model/account/c...', Array) 
#6 [internal function]: Loader->{closure}(Array, Array) 
#7 .../system/engine/proxy.php(47): call_user_func_array(Object(Closure), Array) 
#8 .../catalog/controller/account/affiliate.php(19): Proxy->__call('addAffiliate', Array) 
#9 /h in .../system/library/mail/smtp.php on line 328
I can't see what would cause it. Is it an issue with my SMTP? It's working for everything else. Sending emails for when accounts are made, orders placed, etc. Just struggling with the affiliate add mail.

It is being added to the database correctly also despite the error.

Any ideas?
Last edited by straightlight on Sat Apr 04, 2020 8:34 pm, edited 1 time in total.

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by straightlight » Sat Apr 04, 2020 8:36 pm


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 scottyboyyy » Sat Apr 04, 2020 8:47 pm

straightlight wrote:
Sat Apr 04, 2020 8:36 pm
See this post: viewtopic.php?f=202&t=216498&p=779948&h ... 2F#p779948 .
Thanks for the reply.

I just checked and I am using "ssl://". I went through cpanel and it seems correct host.

Mail is working for everything else, even working for affiliate when added through affiliate/register. The only issue is when added through account/affiliate.

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by straightlight » Sat Apr 04, 2020 8:59 pm

A clue ...

The following has already been fixed on Github, however. In catalog/controller/mail/affiliate.php file,

find:

Code: Select all

$mail->setSubject(sprintf($this->language->get('text_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')));
		$mail->setText($this->load->view('mail/affiliate', $data));
replace with:

Code: Select all

$mail->setSubject(html_entity_decode(sprintf($this->language->get('text_subject'), $this->config->get('config_name')), ENT_QUOTES, 'UTF-8'));
		$mail->setHtml($this->load->view('mail/affiliate', $data));
Then, find:

Code: Select all

$mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'));			
			$mail->setSubject(html_entity_decode($this->language->get('text_new_affiliate'), ENT_QUOTES, 'UTF-8'));
			$mail->setText($this->load->view('mail/affiliate_alert', $data));
replace with:

Code: Select all

$mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'));
			$mail->setSubject($this->language->get('text_new_affiliate'));
			$mail->setHtml($this->load->view('mail/affiliate_alert', $data));
See if that solves the issue.

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 scottyboyyy » Sat Apr 04, 2020 9:15 pm

Thanks for sending that. I made the changes, but same exact error :(

The setup is working for everything else.

Code: Select all

if (substr($reply, 0, 3) != 250) {
				throw new \Exception('Error: DATA not accepted from server!');
			} 
This is line 328 of the smtp, what causes substr($reply, 0, 3) not to be 250? And what does that mean?

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by straightlight » Sat Apr 04, 2020 9:21 pm

Not a library issue. Please post your OC Mail form screenshot without password.

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 scottyboyyy » Sat Apr 04, 2020 9:42 pm

https://imgur.com/a/rYgowmI

Here is my setup beside a screenshot of the cpanel instructions.

Thanks again!

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by straightlight » Sat Apr 04, 2020 9:55 pm

The affiliate option at the bottom is unchecked.

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 letxobnav » Sat Apr 04, 2020 9:55 pm

$mail->setHtml($this->load->view('mail/affiliate', $data));
affiliate mail views are text not html.

you can try changing:

Code: Select all

if (substr($reply, 0, 3) != 250) {
				throw new \Exception('Error: DATA not accepted from server!');
			} 
to

Code: Select all

if (substr($reply, 0, 3) != 250) {
				throw new \Exception('Error: '.substr($reply, 0, 3).' DATA not accepted from server!');
			} 
to see what smtp return code is given when it is not the expected 250 OK code

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by straightlight » Sat Apr 04, 2020 9:57 pm

I would not suggest to apply the above solution if your store is running live. Also take note that text email mode was implicit on the first post prior to change it to html emails.

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 scottyboyyy » Sat Apr 04, 2020 10:02 pm

straightlight wrote:
Sat Apr 04, 2020 9:55 pm
The affiliate option at the bottom is unchecked.
I just tested with and without, to see if the error changed but it was the same whether checked or not.
letxobnav wrote:
Sat Apr 04, 2020 9:55 pm
$mail->setHtml($this->load->view('mail/affiliate', $data));
affiliate mail views are text not html.

you can try changing:

Code: Select all

if (substr($reply, 0, 3) != 250) {
				throw new \Exception('Error: DATA not accepted from server!');
			} 
to

Code: Select all

if (substr($reply, 0, 3) != 250) {
				throw new \Exception('Error: '.substr($reply, 0, 3).' DATA not accepted from server!');
			} 
to see what smtp return code is given when it is not the expected 250 OK code

Code: Select all

substr($reply, 0, 3)
must be null as it's not changing the error message. Why would it return null? Could this be the issue?

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by straightlight » Sat Apr 04, 2020 10:05 pm

must be null as it's not changing the error message. Why would it return null? Could this be the issue?
Your mail parameter is also empty in the form. Some servers still may require you enter your outgoing mail. address in the Mail Parameter of your OC Mail form.

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 scottyboyyy » Sat Apr 04, 2020 10:13 pm

straightlight wrote:
Sat Apr 04, 2020 10:05 pm
must be null as it's not changing the error message. Why would it return null? Could this be the issue?
Your mail parameter is also empty in the form. Some servers still may require you enter your outgoing mail. address in the Mail Parameter of your OC Mail form.
Same error :(

Code: Select all

throw new \Exception('Errort: '. substr($reply, 0, 3) .' DATA not accepted from server!');
Gives me this:
'Errort: DATA not accepted from server!'

I filled mail parameters with email address, outgoing mail name and with -f parameter infront. None of them affected the output.

Like I say its working for the rest of the mail, really confused as to why just this one it has the issue.

Thanks for all the help so far!

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by straightlight » Sat Apr 04, 2020 10:15 pm

scottyboyyy wrote:
Sat Apr 04, 2020 10:13 pm
straightlight wrote:
Sat Apr 04, 2020 10:05 pm
must be null as it's not changing the error message. Why would it return null? Could this be the issue?
Your mail parameter is also empty in the form. Some servers still may require you enter your outgoing mail. address in the Mail Parameter of your OC Mail form.
Same error :(

Code: Select all

throw new \Exception('Errort: '. substr($reply, 0, 3) .' DATA not accepted from server!');
Gives me this:
'Errort: DATA not accepted from server!'

I filled mail parameters with email address, outgoing mail name and with -f parameter infront. None of them affected the output.

Like I say its working for the rest of the mail, really confused as to why just this one it has the issue.

Thanks for all the help so far!
Send me a PM. I could take a look at this issue.

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 scottyboyyy » Sat Apr 04, 2020 10:31 pm

PM sent, thanks for helping me!

I have just done some extra tests.

If I create an account through affiliate/register it makes a new customer and adds affiliate details to `oc_customer_affiliate`.

If I delete its entry in `oc_customer_affiliate`and go to account/affiliate/add I am able to add it back and the mail sends correctly.

It is only for users that registered as a customer that it causes the issue.

So the mail setup I don't think is the issue. ???

Any ideas?

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by letxobnav » Sat Apr 04, 2020 10:34 pm

mail parameter is only used for php mail, not smtp.

you could try

Code: Select all

throw new \Exception('Error: '.$reply.' DATA not accepted from server!');
to show the entire reply to the period.

could just be a timeout issue.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by scottyboyyy » Sat Apr 04, 2020 10:40 pm

letxobnav wrote:
Sat Apr 04, 2020 10:34 pm
mail parameter is only used for php mail, not smtp.

you could try

Code: Select all

throw new \Exception('Error: '.$reply.' DATA not accepted from server!');
to show the entire reply to the period.

could just be a timeout issue.
Getting nothing for '.$reply.' too.

Is timeout something that I will be able to fix? Or how do I test for that?

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by letxobnav » Sat Apr 04, 2020 10:49 pm

are you sure you have the right

DATA not accepted from server line?

there are two in there.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by scottyboyyy » Sat Apr 04, 2020 10:54 pm

letxobnav wrote:
Sat Apr 04, 2020 10:49 pm
are you sure you have the right

DATA not accepted from server line?

there are two in there.
I think so?

Code: Select all

Uncaught exception 'Exception' with message 'Error: DATA nnot accepted from server!' in /system/library/mail/smtp.php:328
Line 328 in SMTP:

Code: Select all

if (substr($reply, 0, 3) != 250) {
				throw new \Exception('Error: DATA  '.$reply.'nnot accepted from server!');
			}
I just tried adding it to both the error message. Error remains the same, no additional values as I would expect to see from $reply.

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by letxobnav » Sat Apr 04, 2020 11:12 pm

yep, looks like it.
you could try replacing the smtp class with the one from version 3.1.0.0.
It is basically the same but it has a function (handleReply) which promises to handle the replies better from slow mail server responses.
you can set the attempts counter in the class.
Not sure this is your problem but it looks like it.

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;

	public function send() {
		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: 8bit' . PHP_EOL . PHP_EOL;
			$message .= $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: 8bit' . PHP_EOL . PHP_EOL;

			if ($this->text) {
				$message .= $this->text . PHP_EOL;
			} else {
				$message .= '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: 8bit' . PHP_EOL . PHP_EOL;
			$message .= $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;
		}

		$handle = fsockopen($hostname, $this->smtp_port, $errno, $errstr, $this->smtp_timeout);

		if (!$handle) {
			throw new \Exception('Error: ' . $errstr . ' (' . $errno . ')');
		} else {
			if (substr(PHP_OS, 0, 3) != 'WIN') {
				socket_set_timeout($handle, $this->smtp_timeout, 0);
			}

			while ($line = fgets($handle, 515)) {
				if (substr($line, 3, 1) == ' ') {
					break;
				}
			}

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

			$reply = '';

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

				//some SMTP servers respond with 220 code before responding with 250. hence, we need to ignore 220 response string
				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) {
				throw new \Exception('Error: EHLO not accepted from server!');
			}

			if (substr($this->smtp_hostname, 0, 3) == 'tls') {
				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)) {
					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)) {
						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!');

			// According to rfc 821 we should not send more than 1000 including the CRLF
			$message = str_replace("\r\n", "\n", $header . $message);
			$message = str_replace("\r", "\n", $message);

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

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

				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!');

			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++;

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

		if ($status_code) {
			if (substr($reply, 0, 3) != $status_code) {
				throw new \Exception($error_text);
			}
		}

		return $reply;
	}
}

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan
Who is online

Users browsing this forum: No registered users and 6 guests