- $emailtype = true;
- if ($this->currency != $myrow['curr_code'])
- {
- include("doctext2.inc");
- }
- else
- {
- include("doctext.inc");
- }
- require_once($path_to_root . "/reporting/includes/class.mail.inc");
- $mail = new email($this->company['coy_name'], $this->company['email']);
- if (!isset($myrow['email']) || $myrow['email'] == '')
- $myrow['email'] = isset($myrow['contact_email']) ? $myrow['contact_email'] : '';
- $to = $myrow['DebtorName'] . " <" . $myrow['email'] . ">";
- $msg = $doc_Dear_Sirs . " " . $myrow['DebtorName'] . ",\n\n" . $doc_AttachedFile . " " . $subject .
- "\n\n";
- if (isset($myrow['dimension_id']) && $myrow['dimension_id'] > 0 && $doctype == 10) // helper for payment links
- {
- if ($myrow['dimension_id'] == 1)
- {
- $amt = number_format($myrow["ov_freight"] + $myrow["ov_gst"] + $myrow["ov_amount"], user_price_dec());
- $txt = $doc_Payment_Link . " PayPal: ";
- $nn = urlencode($this->title . " " . $myrow['reference']);
- $url = "https://www.paypal.com/xclick/business=" . $this->company['email'] . "&item_name=" .
- $nn . "&amount=" . $amt . "¤cy_code=" . $myrow['curr_code'];
- $msg .= $txt . $url . "\n\n";
- }
+ $contactData = array();
+ if ($this->contactData)
+ foreach($this->contactData as $contact)
+ if (!empty($contact['email']))
+ $contactData[] = $contact;
+
+ if(!count($contactData)) {
+ $this->SetLang(user_language());
+ display_warning(sprintf(_("You have no email contact defined for this type of document for '%s'."), $this->formData['recipient_name']));
+ } else {
+ $sent = $try = 0;
+ $emails = "";
+ if(!$subject)
+ $subject = $this->formData['document_name'] . ' '. $this->formData['document_number'];
+ foreach($contactData as $contact) {
+ if (!isset($contact['email']))
+ continue;
+ $emailtype = true;
+ $this->SetLang($contact['lang']);
+
+ require_once($path_to_root . "/reporting/includes/class.mail.inc");
+ $mail = new email(str_replace(",", "", $this->company['coy_name']),
+ $this->company['email']);
+ $mail->charset = $this->encoding;
+
+ $to = str_replace(",", "", $contact['name'].' '.$contact['name2'])
+ ." <" . $contact['email'] . ">";
+ $msg = _("Dear") . " " . $contact['name2'] . ",\n\n"
+ . _("Attached you will find ") . " " . $subject ."\n\n";
+
+ if (isset($this->formData['payment_service']))
+ {
+ $amt = number_format($this->formData['document_amount'], user_price_dec());
+ $service = $this->formData['payment_service'];
+ $url = payment_link($service, array(
+ 'company_email' => $this->company['email'],
+ 'amount' => $amt,
+ 'currency' => $this->formData['curr_code'],
+ 'comment' => $this->title . " " . $this->formData['document_number']
+ ));
+ if ($url)
+ $msg.= _("You can pay through"). " $service: $url\n\n";
+ }
+
+ $msg .= _("Kindest regards") . "\n\n";
+ $sender = $this->user . "\n" . $this->company['coy_name'] . "\n" . $this->company['postal_address'] . "\n" . $this->company['email'] . "\n" . $this->company['phone'];
+ $mail->to($to); $try++;
+ $mail->subject($subject);
+ $mail->text($msg . $sender);
+ $mail->attachment($fname, $this->filename);
+ $emails .= " " . $contact['email'];
+ if ($mail->send()) $sent++;
+ } // foreach contact
+ unlink($fname);
+ $this->SetLang(user_language());
+ if (!$try) {
+ display_warning(sprintf(_("You have no email contact defined for this type of document for '%s'."), $this->formData['recipient_name']));
+ } elseif (!$sent)
+ display_warning($this->title . " " . $this->formData['document_number'] . ". "
+ . _("Sending document by email failed") . ". " . _("Email:") . $emails);
+ else
+ display_notification($this->title . " " . $this->formData['document_number'] . " "
+ . _("has been sent by email to destination.") . " " . _("Email:") . $emails);