28 if (is_a($mimemail, \Dcp\Mail\Message::className)) {
32 require_once
'PEAR.php';
34 include_once (
'Mail/mime.php');
35 include_once (
'Net/SMTP.php');
36 $rcpt = array_merge(explode(
',',
$to) , explode(
',',
$cc) , explode(
',',
$bcc));
38 $host =
getParam(
'SMTP_HOST',
'localhost');
41 $password =
getParam(
'SMTP_PASSWORD');
43 if (is_a($mimemail,
'Mail_Mime')) {
44 $mimemail->setFrom(
$from);
45 if (
$cc !=
'') $mimemail->addCc(
$cc);
50 if (!($smtp =
new Net_SMTP($host, $port))) {
51 die(
"Unable to instantiate Net_SMTP object\n");
53 $smtp->setDebug(
false);
55 if (PEAR::isError($e = $smtp->connect())) {
56 return (
"smtp connect:" . $e->getMessage());
60 if (PEAR::isError($e = $smtp->auth(
$login, $password))) {
61 return (
"smtp login:" . $e->getMessage());
66 if (preg_match(
'/<(?<from>[^>]*)>/',
$from, $reg)) {
67 $smtp_from = $reg[
'from'];
69 if (PEAR::isError($smtp->mailFrom($smtp_from))) {
70 return (
"Unable to set sender to <$smtp_from>");
73 foreach ($rcpt as $v) {
76 if (preg_match(
"/<([^>]*)>/", $v, $reg)) {
79 if (PEAR::isError($res = $smtp->rcptTo($v))) {
80 return (
"Unable to add recipient <$v>: " . $res->getMessage());
84 setlocale(LC_TIME,
'C');
88 if (is_a($mimemail,
'Fdl_Mail_mimePart')) {
90 $mm =
new Mail_Mime();
91 $mm->_build_params[
'head_charset'] =
'UTF-8';
100 $email = $mimemail->encode();
101 if (PEAR::isError($email)) {
102 $err = sprintf(
"Error encoding Fdl_Mail_mimePart : %s", $email->message);
103 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" " .
$err);
107 $txtHeaders = $mm->txtHeaders(array_merge($email[
'headers'], array(
110 'Date' => strftime(
"%a, %d %b %Y %H:%M:%S %z", time()) ,
111 'Message-Id' => sprintf(
"<%s@%s>", strftime(
"%Y%M%d%H%M%S-", time()) . rand(1, 65535) , $host) ,
112 'User-Agent' => sprintf(
"Dynacase Platform %s",
getParam(
'VERSION'))
115 $data = $txtHeaders . $mm->_build_params[
'eol'] . $email[
'body'];
118 $body = $mimemail->get();
120 $xh[
'Date'] = strftime(
"%a, %d %b %Y %H:%M:%S %z", time());
123 $xh[
'Message-Id'] =
'<' . strftime(
"%Y%M%d%H%M%S-", time()) . rand(1, 65535) .
"@$host>";
125 $xh[
'User-Agent'] = sprintf(
"Dynacase Platform %s",
getParam(
'VERSION'));
127 $h = $mimemail->headers($xh);
128 if ($multipart) $h[
'Content-Type'] = str_replace(
"mixed", $multipart, $h[
'Content-Type']);
130 foreach ($h as $k => $v) {
131 $data.=
"$k: $v\r\n";
134 $data.=
"\r\n" . $body;
137 if (PEAR::isError($smtp->data(
$data))) {
138 return (
"Unable to send data");
146 $message->setFrom(
$from);
147 $message->addTo(
$to);
148 $message->addCc(
$cc);
149 $message->addBcc(
$bcc);
151 return $message->send();
158 include_once (
'WHAT/Lib.Common.php');
164 $mailAddrParser = new \Dcp\Mail\MailAddrParser();
165 $res = $mailAddrParser->parse(
$from);
166 if (count($res) > 0) {
167 $from = $res[0]->address;
170 catch(\Dcp\Mail\MailAddrParserException $e) {
172 $msg->setValue(
"emsg_from",
$from);
174 $msg->setValue(
"emsg_subject",
$subject);
179 $msg->setValue(
"emsg_refid",
$doc->id);
180 $msg->profid =
$doc->profid;
183 foreach (explode(
',',
$to) as $v) {
184 if ($v) $msg->addArrayRow(
"emsg_t_recipient", array(
185 "emsg_sendtype" =>
"to",
186 "emsg_recipient" => $v
189 foreach (explode(
',',
$cc) as $v) {
190 if ($v) $msg->addArrayRow(
"emsg_t_recipient", array(
191 "emsg_sendtype" =>
"cc",
192 "emsg_recipient" => $v
195 foreach (explode(
',',
$bcc) as $v) {
196 if ($v) $msg->addArrayRow(
"emsg_t_recipient", array(
197 "emsg_sendtype" =>
"bcc",
198 "emsg_recipient" => $v
202 if (is_a($mimemail,
'Fdl_Mail_mimePart')) {
204 $partList = array(&$mimemail
207 while ($i < count($partList)) {
208 if (count($partList[$i]->_subparts) <= 0) {
212 $multipart = $partList[$i];
213 array_splice($partList, $i, 1);
214 foreach ($multipart->_subparts as & $part) {
215 $partList[] = & $part;
221 foreach ($partList as $i => & $part) {
222 if (preg_match(
"|^text/plain|", $part->_headers[
'Content-Type'])) {
224 array_splice($partList, $i, 1);
231 foreach ($partList as $i => & $part) {
232 if (preg_match(
"|^text/html|", $part->_headers[
'Content-Type'])) {
234 array_splice($partList, $i, 1);
241 if ($textPart !== null) {
245 if ($textPart->_body_file !=
'') {
246 $textBody = file_get_contents($textPart->_body_file);
248 $textBody = $textPart->_body;
250 $msg->setValue(
'emsg_textbody', $textBody);
254 if ($htmlPart !== null) {
258 if ($htmlPart->_body_file !=
'') {
259 $htmlBody = file_get_contents($htmlPart->_body_file);
261 $htmlBody = $htmlPart->_body;
263 $msg->setValue(
'emsg_htmlbody', $htmlBody);
266 foreach ($partList as $i => & $part) {
268 if ($part->_body_file !=
'') {
271 file_put_contents(
$tmpfile, $part->_body);
273 $msg->storeFile(
'emsg_attach',
$tmpfile, $part->_filename, $i);
283 if ($htmlPart !== null && $htmlBody !=
'') {
285 foreach ($partList as $i => & $part) {
286 $cid = preg_replace(
'/^<(.+)>$/',
'\1', isset($part->_headers[
'Content-ID']) ? $part->_headers[
'Content-ID'] :
'');
288 $htmlBody = str_replace(sprintf(
"cid:%s", $cid) , $msg->getfileLink(
'emsg_attach', $i) , $htmlBody);
293 $msg->disableEditControl();
294 $msg->setValue(
'emsg_htmlbody', $htmlBody);
295 $err = $msg->modify(
true);
296 $msg->enableEditControl();
304 } elseif (is_a($mimemail, \Dcp\Mail\Message::className)) {
312 if (isset($mimemail->body)) {
313 $partList[] = $mimemail->body;
315 if (count($mimemail->bodyRelated) > 0) {
316 foreach ($mimemail->bodyRelated as $part) {
320 if (isset($mimemail->altBody)) {
321 $partList[] = $mimemail->altBody;
323 if (count($mimemail->attachments) > 0) {
324 foreach ($mimemail->attachments as $part) {
339 $otherPartList = array();
340 foreach ($partList as $i => $part) {
341 if (!isset($textPart) && isset($part) && $part->getMimeType() ==
'text/plain') {
343 } elseif (!isset($htmlPart) && isset($part) && $part->getMimeType() ==
'text/html') {
346 $otherPartList[] = $part;
350 if ($textPart !== null) {
351 $data = $textPart->getData();
352 $msg->setValue(\Dcp\AttributeIdentifiers\Sentmessage::emsg_textbody,
$data);
355 if ($htmlPart !== null) {
356 $data = $htmlPart->getData();
357 $msg->setValue(\Dcp\AttributeIdentifiers\Sentmessage::emsg_htmlbody,
$data);
360 foreach ($otherPartList as $i => $part) {
365 if (file_put_contents(
$tmpfile, $part->getData()) ===
false) {
369 $msg->setFile(\Dcp\AttributeIdentifiers\Sentmessage::emsg_attach,
$tmpfile, $part->getName() , $i);
378 if ($htmlPart !== null) {
379 $htmlBody = $htmlPart->getData();
381 foreach ($otherPartList as $i => $part) {
382 if (isset($part->cid)) {
383 $htmlBody = str_replace(sprintf(
"cid:%s", $part->cid) , $msg->getfileLink(
'emsg_attach', $i) , $htmlBody);
387 $msg->disableEditControl();
388 $msg->setValue(
'emsg_htmlbody', $htmlBody);
389 $err = $msg->modify(
true);
390 $msg->enableEditControl();
400 $msg->setValue(
"emsg_textbody", $mimemail->_txtbody);
401 $msg->setValue(
"emsg_htmlbody", $mimemail->_htmlbody);
402 $linkedbody = $mimemail->_htmlbody;
403 foreach ($mimemail->_parts as $k => $v) {
405 file_put_contents(
$tmpfile, $v[
"body"]);
406 $msg->setFile(
"emsg_attach",
$tmpfile, $v[
"name"], $k);
413 $linkedbody = $mimemail->_htmlbody;
414 foreach ($mimemail->_parts as $k => $v) {
415 $linkedbody = str_replace(
"cid:" . $v[
"cid"], $msg->getFileLink(
"emsg_attach", $k) , $linkedbody);
417 $msg->disableEditControl();
418 $msg->setValue(
"emsg_htmlbody", $linkedbody);
419 $err = $msg->modify(
true);
sendmail($to, $from, $cc, $bcc, $subject, &$mimemail, $multipart=null)
getParam($name, $def="")
must be in core or global type
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
static getTimeDate($hourdelta=0, $second=false)
__sendmail_Dcp_Mail_Message($to, $from, $cc, $bcc, $subject,\Dcp\Mail\Message &$message)
if($file) if($subject==""&&$file) if($subject=="") $err