OpenCart - not sending emails (notifications or contact page)

◇◆丶佛笑我妖孽 提交于 2019-12-01 07:52:49

问题


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:

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==?=


回答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;



回答2:


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




回答3:


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.




回答4:


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);
}



回答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 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.



来源:https://stackoverflow.com/questions/14306766/opencart-not-sending-emails-notifications-or-contact-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!