Отправка почты в Opencart (проблемы и решения)

Opencart – fixing “Notice: Error: RCPT TO not accepted from server!” (tutorial)

Это патч, чтобы исправить проблемы с отправкой контактную форму в OpenCart 1.5 и 2.0.

Статья оригинал — толмача не надо 🙂

If you get the following message:

Notice: Error: RCPT TO not accepted from server! in system/library/mail.php on line 308

in your Opencart installation, be it v 1.5.x or 2.0.x, then probably your email provider has SPF policy (Sender Policy Framework) verifying the so-called FROM address. This is a good thing, it means that your email provider has a properly configured server that protects from spam messages and other improper uses.
With SPF policy, you cannot put anything you want in the FROM field, it needs to match your account address or at least your email domain.
In other words, if your email address for the shop is, let’s say, moc.niamodruoy@pohs, it will probably only allow moc.niamodruoy@pohs as a sender address or in the best case scenario moc.niamodruoy@GNIHTYNA

The error listed above is caused by the fact that OpenCart for some reason is using another approach. In OpenCart solution, the email address that your client is putting in the contact form is automatically assigned by the OpenCart system as the FROM field of the message. It means that the contact form message is forcefully interpreted as a message coming from your client’s email account (which is not the case, your client is not sending this message from his email account, he only gives you his email address so that you can reply to him).This means that a properly configured server will not send such a message and your client will not be able to contact you.

So should you ask your email account provider to change this SPF or whatsoever setting so that you’re able to use OpenCart way of doing things?

Well, there is a slight problem with this solution. Most providers won’t change their SPF policy.
And they are right. Their approach is 100% correct according to email configuration standards (see RFC 4408 https://www.ietf.org/rfc/rfc4408.txt). It is also a good practice when fighting spammers.

What is the right solution, then?

The best thing to do is to modify your OpenCart emailing library to make it act properly 🙂

This is really easy as you only need to change just a few lines of code in 2 files.

Below you have 2 tutorials how to change it for OC 1.5 and 2.0 versions. If you don’t feel like doing it on your own, I have written simple vqmods that will do the same thing for you. You can download them hereNotice: Error: RCPT TO not accepted from server! – fix (VQMOD)
If you don’t have Vqmod installed or you don’t want to install it just follow the steps in the tutorials.

Opencart 1.5 Fix

1.First edit the file catalog/controller/information/contact.php
Look for line:

$mail->setFrom($this->request->post['email']);

in my version it is line 20
Change it to:

$mail->setFrom($this->config->get('config_email'));

What this will do is set the FROM field to be the same as your shop’s main email address.
You can hardcode (but I wouldn’t recommend it) an email adress here if you want by changing this line to ie:

$mail->setFrom('shop@mydomain.com');:

2.Now find the line:

$mail->setSender($this->request->post['name']);

It should be below the line we just edited or somwhere near.
Change it to:

$mail->setReplyTo($this->request->post['email']);
$mail->setSender($this->config->get('config_email'));

What this will do is set your client’s email provided by him in the contact form as reply-to email, so that you’re able to respond automatically to contact form messages by clicking on Reply button.
It is also setting your shop email address as sender’s name.

3.OK so now we need to edit system/library/mail.php file
In the beginning you will have line:

protected $subject;

Just add this before it:

protected $replyto;

Find line:

public function setSender($sender) {

and before it add:

public function setReplyTo($reply_to) {
$this->replyto = html_entity_decode($reply_to, ENT_QUOTES, 'UTF-8');}

What we did here is to add REPLY-TO function which is missing in 1.5 (but is present in 2.0) and allows us to set different reply-to addresses than FROM address.

Finally find this line:

$header .= 'Reply-To: ' . '=?UTF-8?B?' . base64_encode($this->sender) . '?=' . ' <' . $this->from . '>' . $this->newline;

and change it to:

if ($this->replyto){
$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->replyto) . '?=' . ' <' . $this->replyto . '>' . $this->newline;
}

Here we are correcting the way reply-to address is set (it will use the email address your client introduced in the contact form).
And that’s it!

Opencart 2.0 fix

It is simplier to change in the newest version of OC because there is already a funciton to set Reply-To address.

  1. First edit the file catalog/controller/information/contact.php
    Look for line:

    $mail->setFrom($this->request->post['email']);in my version it is line 20

    Change it to:

    $mail->setFrom($this->config->get('config_email'));

    What this will do is set the FROM field to be the same as your shop’s main email address.
    You can hardcode (but I wouldn’t recommend it) an email adress here if you want by changing this line to ie:

    $mail->setFrom('shop@mydomain.com');
  2. Now find this line:
    $mail->setSender($this->request->post['name']); 

    It should be below the line we just edited or somwhere around.
    Change it to:

    $mail->setReplyTo($this->request->post['email']);
    $mail->setSender($this->config->get('config_email'));

    What this will do is set your client’s email provided by him in the contact form as reply-to email, so that you’re able to respond automatically to contact form messages by clicking on Reply button.
    It is also setting your shop email address as sender’s name.

  3. Now we need to edit system/library/mail.php file
    You just need to change this line:

    $header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->replyto) . '?=' . ' <' . $this->from . '>' . $this->newline;

    change it to:

    $header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->replyto) . '?=' . ' <' . $this->replyto . '>' . $this->newline;

    Here we are correcting the way reply-to address is set (it will use the email address your client introduced in the contact form).

  4. And this line to correct annoying bug with Reply-to being not set correctly when notifying customer about new order:
    $this->setReplyTo($this->sender);

    Replace it with this:

    $this->setReplyTo($this->from);

    Refresh your contact form and try sending a test email.

VQMOD FIX 1.5 \ 2.0

[sociallocker]

[/sociallocker]

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest
2 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
miniacruh
miniacruh
7 лет назад

I just wanna say hi to you all

επιμηκυνση πεους με χαπια
επιμηκυνση πεους με χαπια
5 лет назад

Thanks for your personal marvelous posting!
I actually enjoyed reading it, you are a great author.I
will be sure to bookmark your blog and may come back someday.
I want to encourage yourself to continue your great work, have a nice holiday weekend!

× iOs app

To install this Web App in your iPhone/iPad press iOs sourse and then Add to Home Screen.