OpenCart - not sending emails (notifications or contact page)

前端 未结 5 2023
走了就别回头了
走了就别回头了 2021-01-15 17:03

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

相关标签:
5条回答
  • 2021-01-15 17:08

    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);
    }
    
    0 讨论(0)
  • 2021-01-15 17:14

    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

    0 讨论(0)
  • 2021-01-15 17:21

    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).

    0 讨论(0)
  • 2021-01-15 17:27

    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;
    
    0 讨论(0)
  • 2021-01-15 17:31

    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 test@mydomain.com 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.

    0 讨论(0)
提交回复
热议问题