php OpenCart - 不发送电子邮件(通知或联系页面)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14306766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:03:15  来源:igfitidea点击:

OpenCart - not sending emails (notifications or contact page)

phpemailbase64opencart

提问by Nick

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

  1. 更改为 SMTP,我收到错误消息,我的主机 (IXWebHosting) 说我需要在应用程序中禁用授权,但我看不到此选项

  2. 按照此处的建议在电子邮件前添加 -f 和 -F

  3. 将不同的电子邮件添加到“邮件”页面底部的“也发送到”框中

  4. 按照此处的建议手动定义代码中的“From”标头

  5. 尝试过@gmail.com、@googlemail.com 和@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)

不幸的是,我仍然没有收到来自 OpenCart 的任何电子邮件。我已经联系了我的主机并运行了测试脚本 - 服务器上的邮件功能或设置没有问题,而且我刚刚从 OpenCart 下载了最新版本的 mail.php(尽管这是六个月前的反正我用的那个)

Thanks

谢谢

UPDATE:

更新:

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

看起来 base64_encode 不起作用,因为此代码:

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

Outputs this:

输出这个:

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

来自:=?UTF-8?B?Tmljaw==?=

回答by Jay Gilford

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

老实说,不完全确定为什么使用 base 64 编码。打开system/library/mail.php并更改此行

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

to

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

回答by sensei

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.

问题确实出在您的服务器上...如果您使用邮件选项,则必须在本地主机上设置邮件服务器。但问题是您的 ISP 是否支持 25 端口的 smtp。如果没有,那么你就有问题了。

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.

第二种选择是使用 gmail smtp 或 hotmail smtp。我尝试过但惨遭失败.. 我不知道为什么 gmail 对我不起作用,但我在整个互联网上搜索了 google,发现人们随机遇到 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.

我正在搜索并尝试了最后的手段..来自我的ISP的smtp。我使用我的 ISP 的 smtp 并在 SMTP 上设置选项,发现东西有效。

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.

我给我的 ISP 打电话,他们不知道为什么 gmail 不起作用,但他们告诉我他们关闭了 25 端口以防止垃圾邮件发送者使用您的用户名发送邮件。

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

TL,DR:如果您在本地主机上工作,请尝试您自己的 isp smtp,如果不是,您可以要求您的托管服务提供商为您解决问题:)

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.

PS:您不能禁用授权。以前版本的opencart没有授权,这很有趣,他们为什么不添加选择授权或未经授权的选项。

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

如果您知道编码,您可以在 opencart 中编辑邮件类,否则,您唯一的解决方案是使用您的 ISP smtp 或转移到使用 smtp 授权设置其邮件服务器的主机(即使对于您当前的托管)。

回答by jaczjill

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.

它对我们有用,在 OpenCart 版本 1.5.5.3 中。

enter image description here

在此处输入图片说明

回答by Roberto Gerola

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.

我尝试了所有可能的修复,但没有一个对我有用(我在 Site5 上托管,在 Webfaction 上它起作用了)。我最终使用 SwiftMailer 在 system/library/mail.php 文件中重写了send()函数,我安装了 system/library/swiftmailer 目录。我的代码不完整,因为它假定身份验证总是必要的,但这应该是一个简单的修复。

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

回答by Rob

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.

这很清楚,因为当我填写[email protected]联系表格时,它起作用了,而且常规电子邮件也确实到达了。

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

文件: catalog/controller/information/contact.php

Function index, for me on line 21:

函数索引,对我来说在第 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.

这为我解决了它。