- $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>";
+ if(!count($this->contactData)) {
+ $this->SetLang(user_language());
+ display_error(_("You have no email contact defined for this type of document"));
+ } else {
+ $sent = 0;
+ foreach($this->contactData as $contact) {
+ if (!isset($contact['email']))
+ continue;
+ $emailtype = true;
+ $this->SetLang($contact['lang']);
+ include("includes/doctext.inc");
+
+ 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 = $doc_Dear_Sirs . " " . $contact['name2'] . ",\n\n"
+ . $doc_AttachedFile . " " . $subject ."\n\n";
+ if (isset($myrow['dimension_id']) && $myrow['dimension_id'] > 0 && $doctype == ST_SALESINVOICE) // 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";
+ }
+ }
+ $msg .= $doc_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);
+ $mail->subject($subject);
+ $mail->text($msg . $sender);
+ $mail->attachment($fname);
+ if ($mail->send()) $sent++;
+ } // foreach contact
+ unlink($fname);
+ $this->SetLang(user_language());
+ if (!$sent)
+ display_error(_("Sending document by email failed"));
+ else
+ display_notification($this->title . " " . $myrow['reference'] . " "
+ . _("has been sent by email to destination."));
+ }