简体   繁体   中英

How to send an email to multiple receivers in opencart?

This is how I'm currently sending notifications to the (two) admin of the shop

$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');     

$mailText = html_entity_decode($mailText,ENT_QUOTES, 'UTF-8');
/* Email para el admins Alcudia */
$mail->setFrom($this->request->post['email']);
$mail->setSender($this->request->post['name']);
$mail->setTo($admin_alcudia);
$mail->setSubject(html_entity_decode('Se ha realizado una solicitud de reserva', ENT_QUOTES, 'UTF-8'));
$mail->setHtml($mailText);
$mail->send();
/* Email para el admin de palma */
$mail->setFrom($this->request->post['email']);
$mail->setSender($this->request->post['name']);
$mail->setTo($admin_palma);
$mail->setSubject(html_entity_decode('Se ha realizado una solicitud de reserva', ENT_QUOTES, 'UTF-8'));
$mail->setHtml($mailText);
$mail->send();

The thing is that they're saying that the second one is not reciving it...

Any idea how to improve this? is there any CC functionality?

I've been waiting all day but http://docs.opencart.com/ won't get back to life..

Try separating the sendTo() function with commas in a string:

$mail = new Mail();

$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');     

$mailText = html_entity_decode($mailText,ENT_QUOTES, 'UTF-8');

$mail->setFrom($this->request->post['email']);
$mail->setSender($this->request->post['name']);
$mail->setTo($admin_alcudia.','.$admin_palma);
$mail->setSubject(html_entity_decode('Se ha realizado una solicitud de reserva', ENT_QUOTES, 'UTF-8'));
$mail->setHtml($mailText);

$mail->send();

This should eliminate the need to have duplicate code.

在OpenCart 2.x中,您需要将数组传递给setTo setTo()方法。

$mail->setTo(array(0 => 'name@domain.com', 1 => 'name2@domain.com'));

The other option is to not have to modify any code and to change it in the settings,

If you go to system and then into settings and then click edit on your store it will open up the settings for your store...

You then need to go across to the mail tab ans then scroll down to the "Additional Alert E-Mails" text box and then simply add the additional email address

No change in coding necessary...

Hope this helps,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM