phpemailopencartcarbon-copy

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


Solution

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