Opencart:如何在电子邮件中添加抄送和密件抄送?

Opencart : How to add CC and BCC at email?

目前我在 opencart 开发电子邮件模块,我需要在我的电子邮件中添加抄送和密件抄送。如何在 opencart 3 中添加抄送和密件抄送? 谢谢

在您的模块中,找到:

$mail->send();

在之后添加:

$emails = array(
    'test@gmail.com',
    'test2@gmail.com'
);

foreach ($emails as $email) {
    if ($email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $mail->setTo($email);
        $mail->send();
    }
}

如您所述,您可以编辑 smtp.php 并添加

$header .= 'Cc: "' . $cc . '" <' . $cc . '>' . PHP_EOL;

但它只会将抄送添加到 header 而不会发送实际消息。因此,您还必须编辑实际的发送部分,即第 253 到 287 行的某处。您必须添加另一组发送代码,如下所示:

            fputs($handle, 'RCPT TO: <' . $cc . '>' . "\r\n");

            $reply = '';

            while ($line = fgets($handle, 515)) {
                $reply .= $line;

                if (substr($line, 3, 1) == ' ') {
                    break;
                }
            }

            if ((substr($reply, 0, 3) != 250) && (substr($reply, 0, 3) != 251)) {
                throw new \Exception('Error: RCPT TO CC not accepted from server!');
            }

老实说我不知道​​他们叫什么,所以我叫他们"sending code"。我也不确定这是否会对整体性能产生重大影响,但它对我有用。所以请自行承担使用风险。