This is a patch to fix problems with sending contact form in Opencart 1.5 and 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 http://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 here – Notice: 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
-
First edit the file catalog/controller/information/contact.php
Look for line:
in my version it is line 20$mail->setFrom($this->request->post['email']);
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');
-
Now find the line:
It should be below the line we just edited or somwhere near.$mail->setSender($this->request->post['name']);
Change it to:
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.$mail->setReplyTo($this->request->post['email']); $mail->setSender($this->config->get('config_email'));
It is also setting your shop email address as sender’s name. - OK so now we need to edit system/library/mail.php file
In the beginning you will have line:
Just add this before it:protected $subject;
Find line:protected $replyto;
and before it add:public function setSender($sender) {
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.public function setReplyTo($reply_to) { $this->replyto = html_entity_decode($reply_to, ENT_QUOTES, 'UTF-8');}
- Finally find this line:
and change it to:$header .= 'Reply-To: ' . '=?UTF-8?B?' . base64_encode($this->sender) . '?=' . ' <' . $this->from . '>' . $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).if ($this->replyto){ $header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->replyto) . '?=' . ' <' . $this->replyto . '>' . $this->newline; }
And that’s it!
If you have any problems with OC and need professional help or support
Contact us for a free consultation or quote
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.
- First edit the file catalog/controller/information/contact.php
Look for line:
Change it to:$mail->setFrom($this->request->post['email']);in my version it is line 20
What this will do is set the FROM field to be the same as your shop’s main email address.$mail->setFrom($this->config->get('config_email'));
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');
- Now find this line:
It should be below the line we just edited or somwhere around.$mail->setSender($this->request->post['name']);
Change it to:
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.$mail->setReplyTo($this->request->post['email']); $mail->setSender($this->config->get('config_email'));
It is also setting your shop email address as sender’s name. - Now we need to edit system/library/mail.php file
You just need to change this line:
change it to:$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->replyto) . '?=' . ' <' . $this->from . '>' . $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).$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->replyto) . '?=' . ' <' . $this->replyto . '>' . $this->newline;
- And this line to correct annoying bug with Reply-to being not set correctly when notifying customer about new order:
Replace it with this:$this->setReplyTo($this->sender);
Refresh your contact form and try sending a test email.$this->setReplyTo($this->from);