- $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']);
- $from = $this->company['coy_name'] . " <" . $this->company['email'] . ">";
- $to = $myrow['DebtorName'] . " <" . $myrow['email'] . ">";
- $msg = $doc_Dear_Sirs . ",\n\n" . $doc_AttachedFile . " " . $subject .
- "\n\n" . $doc_Kindest_regards . "\n\n";
- $sender = $this->user . "\n" . $this->company['coy_name'];
- $mail->to($to);
- $mail->subject($subject);
- $mail->text($msg . $sender);
- $mail->attachment($fname);
- $ret = $mail->send();
- if (1 == 1) // just for fun and for debugging purposes!!
- {
- $from = str_replace("<", "(", $from);
- $from = str_replace(">", ")", $from);
- $to = str_replace("<", "(", $to);
- $to = str_replace(">", ")", $to);
- $msg2 = "<br>From: " . $from;
- $msg2 .= "<br>To: " . $to;
- $msg2 .= "<br>Subject: " . $subject;
- $msg2 .= "<br>Msg: " . nl2br($msg);
- $msg2 .= nl2br($sender) . "<br>";
- $msg2 .= "<br>Filepath: " . $fname . "<br>Filename: " . $this->filename . "<br>";
- }
- if ($ret)
- $str = "<br>" . $this->title . " " . $myrow['reference'] . " " . _("sent to") . " ";
- else
- $str = "<br>" . $this->title . " " . $myrow['reference'] . " " . _("NOT sent to") . " ";
- $msg2 .= $str . $myrow['DebtorName'] . " - " . $myrow['email'];
- echo "<html><body>";
- echo $msg2;
- echo "</body></html>";
+ $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);
+ $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);
+ }