Invoice multiple email

Contrib type: 
Code/CSS Snippet
Status: 
Bug testing
Moderation: 
Awaiting moderation

Downloads

Compatibility: 
Ubercart 2.x

This snippet allows to send multiple email at once using the form at admin/store/orders/%invoice/invoice/mail by separating the mail with ",".

Just modify the functions in ubercart/uc_orderuc_order/uc_order.admin.inc starting at line 1723.

<?php
function uc_order_mail_invoice_form_validate($form, &$form_state) {
 
$recipient = check_plain($form_state['values']['email']);
  if (empty(
$recipient)) {
   
form_set_error('email', t('Invalid e-mail address.'));
  }
 
$recipients = explode(',', $recipient);
  foreach (
$recipients as $recipient) {
   
$recipient = trim($recipient);
    if (empty(
$recipient) || !valid_email_address($recipient)) {
     
form_set_error('email', t('Invalid e-mail address.'));
    }
  }
}
?>

and

<?php
function uc_order_mail_invoice_form_submit($form, &$form_state) {
 
$order = uc_order_load($form_state['values']['order_id']);
 
  if (
$order === FALSE) {
   
drupal_set_message(t('Order @order_id does not exist.', array('@order_id' => $order_id)));
   
drupal_goto('admin/store/orders');
  }
 
 
$recipient = check_plain($form_state['values']['email']);
 
$params = array('order' => $order);
 
 
$recipients = explode(',', $recipient);
  foreach (
$recipients as $recipient) {
   
$recipient = trim($recipient);
   
$sent = drupal_mail('uc_order', 'invoice', $recipient, uc_store_mail_recipient_language($recipient), $params, uc_store_email_from());
   
    if (!
$sent) {
     
drupal_set_message(t('E-mail failed.'));
    }
    else {
     
$message = t('Invoice e-mailed to @email.', array('@email' => $recipient));
     
drupal_set_message($message);
     
uc_order_log_changes($order->order_id, array($message));
    }
  }
}
?>