Index: uc_order.ca.inc =================================================================== --- uc_order.ca.inc (revision 1) +++ uc_order.ca.inc (working copy) @@ -1134,7 +1134,7 @@ /** * Send an email concerning an order. * - * The recipients, subject, and message fields take order token replacements. + * The from, recipients, subject, and message fields take order token replacements. * * @see uc_order_action_email_form() */ @@ -1149,21 +1149,32 @@ ); // Apply token replacements to from and recipient e-mail addressses. - $from = token_replace_multiple($settings['from'], $settings['replacements']); - $addresses = token_replace_multiple($settings['addresses'], $settings['replacements']); + $from = trim(token_replace_multiple($settings['from'], $settings['replacements'])); + $from = empty($from) ? uc_store_email_from() : $from; + if (empty($from)) { + drupal_set_message('Cannot send email without a "from" address. Setup in store settings (/admin/store/settings/store/edit/contact) or specify an optional email address in the conditional actions.'); + return; + } + + $addresses = token_replace_multiple(strip_tags($settings['addresses']), $settings['replacements']); + // Split up our recipient e-mail addresses. $recipients = array(); foreach (explode("\n", $addresses) as $address) { - $recipients[] = trim($address); + if (strlen(trim($address)) > 0) $recipients[] = trim($address); } foreach ($recipients as $email) { - $sent = drupal_mail('uc_order', 'action-mail', $email, uc_store_mail_recipient_language($email), $settings, empty($settings['from']) ? uc_store_email_from() : $settings['from']); - if (!$sent['result']) { - watchdog('ca', 'Attempt to e-mail @email concerning order @order_id failed.', array('@email' => $email, '@order_id' => $order->order_id), WATCHDOG_ERROR); - } + $sent = drupal_mail('uc_order', 'action-mail', $email, uc_store_mail_recipient_language($email), $settings, $from); + + if (!$sent['result']) { + watchdog('ca', 'Attempt to e-mail @email concerning order @order_id failed.', array('@email' => $email, '@order_id' => $order->order_id), WATCHDOG_ERROR); + } else { + watchdog('ca', 'E-mail sent to @email for order @order_id from @from', array('@email' => $email, '@order_id' => $order->order_id,'@from' => $from), WATCHDOG_INFO); + } + } } @@ -1175,8 +1186,8 @@ '#type' => 'textfield', '#title' => t('Sender'), '#default_value' => isset($settings['from']) ? $settings['from'] : uc_store_email_from(), - '#description' => t('The "From" address.'), - '#required' => TRUE, + '#description' => t('The "From" address. Leave blank to use your store email address. You may use order tokens for dynamic email addresses.'), + '#required' => FALSE, ); $form['addresses'] = array( '#type' => 'textarea', @@ -1237,10 +1248,18 @@ ); $recipients = array(); - $addresses = token_replace_multiple($settings['addresses'], $settings['replacements']); + $from = trim(token_replace_multiple($settings['from'], $settings['replacements'])); + $from = empty($from) ? uc_store_email_from() : $from; + + if (empty($from)) { + drupal_set_message('Cannot send email without a "from" address. Setup in store settings (/admin/store/settings/store/edit/contact) or specify an optional email address in the conditional actions.'); + return; + } + + $addresses = token_replace_multiple(strip_tags($settings['addresses']), $settings['replacements']); foreach (explode("\n", $addresses) as $address) { - $recipients[] = trim($address); + if (strlen(trim($address)) > 0) $recipients[] = trim($address); } $settings['message'] = theme('uc_order', $order, $settings['view'], $settings['template']); @@ -1251,11 +1270,14 @@ } foreach ($recipients as $email) { - $sent = drupal_mail('uc_order', 'action-mail', $email, uc_store_mail_recipient_language($email), $settings, empty($settings['from']) ? uc_store_email_from() : $settings['from']); + $sent = drupal_mail('uc_order', 'action-mail', $email, uc_store_mail_recipient_language($email), $settings, $from); + if (!$sent['result']) { watchdog('ca', 'Attempt to e-mail invoice for order @order_id to @email failed.', array('@email' => $email, '@order_id' => $order->order_id), WATCHDOG_ERROR); - } + } else { + watchdog('ca', 'Invoice emailed to @email for order @order_id from @from', array('@email' => $email, '@order_id' => $order->order_id,'@from' => $from), WATCHDOG_INFO); + } } } @@ -1267,8 +1289,8 @@ '#type' => 'textfield', '#title' => t('Sender'), '#default_value' => isset($settings['from']) ? $settings['from'] : uc_store_email_from(), - '#description' => t('The "From" address.'), - '#required' => TRUE, + '#description' => t('The "From" address. Leave blank to use the store email address. You may use order tokens for dynamic email addresses.'), + '#required' => FALSE, ); $form['addresses'] = array( '#type' => 'textarea',