OpenCart - not sending emails (notifications or contact page)

前端 未结 5 2025
走了就别回头了
走了就别回头了 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);
    }
    

提交回复
热议问题