OpenCart - not sending emails (notifications or contact page)

43,153

Solution 1

Not totally sure why the base 64 encode is there to be honest. Open system/library/mail.php and change this line

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

to

$header .= 'From: ' . $this->sender . ' <' . $this->from . '>' . $this->newline;

Solution 2

Try adding multiple email addresses in the settings menu of your site. (site administration).

It worked for us, in OpenCart version 1.5.5.3.

enter image description here

Solution 3

I tried every fix possible, bit none worked for me (I am hosted on Site5, on Webfaction it worked). I ended up rewriting the send() function in system/library/mail.php file using SwiftMailer I installed system/library/swiftmailer directory. My code is not complete, because it assumes authentication is always necessary, but this should be an easy fix.

public function send() {
    require_once(DIR_SYSTEM . 'library/swiftmailer/swift_required.php');

    if (!$this->to) {
        trigger_error('Error: E-Mail to required!');
        exit();         
    }

    if (!$this->from) {
        trigger_error('Error: E-Mail from required!');
        exit();                 
    }

    if (!$this->sender) {
        trigger_error('Error: E-Mail sender required!');
        exit();                 
    }

    if (!$this->subject) {
        trigger_error('Error: E-Mail subject required!');
        exit();                 
    }

    if ((!$this->text) && (!$this->html)) {
        trigger_error('Error: E-Mail message required!');
        exit();                 
    }

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

    $message = Swift_Message::newInstance()
      ->setSubject($this->subject)
      ->setFrom(array($this->from => $this->sender))
      ->setTo(array($to))
      ->setBody($this->text);

    if($this->html){
        $message->addPart($this->html, 'text/html');
    }

    foreach ($this->attachments as $attachment) {
        if (file_exists($attachment)) {
            $message->attach(Swift_Attachment::fromPath($attachment));
        }
    }

    $transport = Swift_SmtpTransport::newInstance('localhost', 25)
    ->setUsername($this->username)
    ->setPassword($this->password);

    $mailer = Swift_Mailer::newInstance($transport);
    $mailer->send($message);
}

Solution 4

I had really big frustration with that..

The problem is really with your server... If you use mail option, than you have to setup mail server on your localhost. But the question is if your ISP supports 25 port for smtp. If not, than you got a problem.

Second option is to use gmail smtp or hotmail smtp. I tried and failed miserably.. I don't know why gmail doesn't work for me, but I googled whole internet, and found out that people randomly have problems with gmail.

I was searching and tried last resort.. smtp from my isp. I used smtp of my ISP and set option on SMTP, found out stuff works.

I called my ISP and they didn't know why gmail doesn't work, but they said to me that they closed 25 port to prevent spammers to send mail with your username.

TL,DR: Try your own isp smtp if you are working on localhost, if not you ask your hosting provider to fix things for you :)

PS: You can't disable authorization. PRevious versions of opencart didn't have authorization, which is funny, why didn't they add option to choose with or without authorization.

If you know coding you can edit mail class in opencart, if not, your only solution is to use your ISP smtp or move to hosting that has their mail server set up with smtp authorization(which is not hard to set up even for your current hosting).

Solution 5

The solution for me was that e-mails could not be sent by my server when they had a domain in the "from" that wasn't the same as the host.

This was clear because when i filled in [email protected] in the contact form, it works, and also the regular emails did arrive.

In order to force the mails being sent from my own host instead of the filled in email address, I've edited the contact controller.

Please do not continue with this if you do not know how to edit source code, I'm leaving out some simple steps. If you don't know these steps, dont ask, but ask a professional to look this up. (Just for your own protection)

File: catalog/controller/information/contact.php

Function index, for me on line 21:

ORIGINAL:

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

NEW:

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

This solved it for me.

Share:
43,153
Nick
Author by

Nick

Updated on July 11, 2022

Comments

  • Nick
    Nick almost 2 years

    As far as I can tell, my mail settings are configured correctly but I'm not receiving any emails, not through the contact form, nor for new customers or any orders that are placed.

    Here are my current settings:

    enter image description here

    I've tried:

    1. Changing to SMTP, I get an error and my host (IXWebHosting) says I need to disable Authorization within the application, and I cannot see an option to this

    2. Adding -f and -F before the email as suggested here

    3. Adding different emails to the 'also send to' box at the bottom of the Mail page

    4. Manually defining the 'From' header in the code as suggested here

    5. Tried @gmail.com, @googlemail.com and @arabel.co.uk

    And unfortunately I still don't receive any email from OpenCart. I've contacted my host and run test scripts - there isn't a problem with the mail function or setup on the server, and I've just downloaded the latest version of mail.php from OpenCart (although this is six months old and the one I was using anyway)

    Thanks

    UPDATE:

    It looks like base64_encode isn't working, because this code:

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

    Outputs this:

    From: =?UTF-8?B?Tmljaw==?=

  • c.s.
    c.s. over 10 years
    +1 Additionally it seems that the 'Reply-To' header (in just the next line after 'From') suffers from the same problem. After modifying it to: $header .= 'Reply-To: ' . $this->sender . ' <' . $this->from . '>' . $this->newline; it seems to work fine. However the mail host used in the php.ini must have to do something with this issue since e-mail notifications used to work fine for me until they suddenly stopped working anymore
  • David Taiaroa
    David Taiaroa over 10 years
    Go figure ... this helped one of my clients as well. Probably because theres a config issue with the first email account but your tip got us unstuck. Thanks ;)