currently I develop email module at opencart and I need to add cc and bcc at my email. How can I add cc and BCC at opencart 3? thank you
Asked
Active
Viewed 1,109 times
2 Answers
0
In your module, find:
$mail->send();
Add after:
$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();
}
}

DigitCart
- 2,980
- 2
- 18
- 28
-
Hello, thank you before.. but the code not working.. and by the code u mean that it will send another email to email at emails variable right? – Budi Sep 07 '18 at 13:51
-
This will send the same email, to other email addresses. – DigitCart Sep 07 '18 at 15:53
-
Yeah.. but is there a way to send email to the cc? I make some changes to smtp.php before like this : $header .= 'Cc: <' . $cc . '>' . PHP_EOL; and it works like this To : my email Cc : cc email address subject : ..... etc... but I dont get the email at cc email.. – Budi Sep 07 '18 at 17:22
0
As you mentioned, you can edit the smtp.php and add
$header .= 'Cc: "' . $cc . '" <' . $cc . '>' . PHP_EOL;
but it will just add the cc to the header and not send the actual message. Therefore, you must also edit the actual sending part, which is somewhere on line 253 to 287. You have to add another set of sending code, something like this:
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!');
}
I honestly don't know what they are called, hence I called them "sending code". I am also uncertain if this can cause a critical impact on the performance over all, but it works for me. So please use at your own risk.

Gellie Ann
- 439
- 1
- 6
- 10