Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
fdl_sendmail.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Send mail using freedom sendmail
8  *
9  * @author Anakeen
10  * @version $Id: fdl_sendmail.php,v 1.1 2007/01/19 16:24:03 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 $usage = new ApiUsage();
18 
19 $usage->setDefinitionText("Send mail using freedom sendmail");
20 $to = $usage->addOptionalParameter("to", "email to send to");
21 $cc = $usage->addOptionalParameter("cc", "cc");
22 $bcc = $usage->addOptionalParameter("bcc", "bcc");
23 $subject = $usage->addOptionalParameter("subject", "subject");
24 $file = $usage->addOptionalParameter("file", "file (can be a file name or stdin");
25 $htmlmode = $usage->addOptionalParameter("htmlmode", "activacte htmlmode");
26 
27 $usage->verify();
28 /*
29  * @var Action $action
30  */
31 $from = getMailAddr($action->user->id);
32 if ($from == "") $from = getParam('SMTP_FROM');
33 if ($from == "") $from = $from = $action->user->login . '@' . php_uname('n');
34 
35 include_once ("FDL/sendmail.php");
36 include_once ("WHAT/Lib.FileMime.php");
37 
38 $tmpfile = '';
39 $message = new \Dcp\Mail\Message();
40 $data = '';
41 if ($file && $file == 'stdin') {
42  $data = file_get_contents('php://stdin');
43  $tmpfile = tempnam(getTmpDir() , 'fdl_sendmail_stdin');
44  file_put_contents($tmpfile, $data);
45  if ($htmlmode == 'Y') {
46  $mime = 'text/html';
47  } else {
48  $mime = getSysMimeFile($tmpfile);
49  $ext = getExtension($mime);
50  if ($ext != '') {
51  if (rename($tmpfile, $tmpfile . '.' . $ext) !== false) {
52  $tmpfile = $tmpfile . '.' . $ext;
53  }
54  }
55  }
56  $file = $tmpfile;
57 } elseif ($file) {
58  $mime = getSysMimeFile($file);
59 } else {
60  $mime = 'application/x-empty';
61 }
62 if ($file) {
63  if (preg_match('|text/html|', $mime)) {
64  $message->setBody(new \Dcp\Mail\Body(file_get_contents($file) , $mime));
65  } elseif (preg_match('|text|', $mime)) {
66  $message->setBody(new \Dcp\Mail\Body(file_get_contents($file) , $mime));
67  } else {
68  $message->addAttachment(new \Dcp\Mail\Attachment($file, basename($file) , $mime));
69  }
70 }
71 
72 if ($subject == "" && $file) {
73  $subject = basename($file);
74 }
75 if ($subject == "") {
76  $subject = _("no subject");
77 }
79 if ($err) {
80  print "Error:$err\n";
81 }
82 if ($tmpfile != '') {
83  unlink($tmpfile);
84 }
$tmpfile
global $action
getMailAddr($userid, $full=false)
Definition: Lib.Common.php:133
sendmail($to, $from, $cc, $bcc, $subject, &$mimemail, $multipart=null)
Definition: sendmail.php:26
$message
getSysMimeFile($f, $fn="")
$file
$to
$subject
$usage
getParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:193
$bcc
print
Definition: checklist.php:49
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
$cc
$from
$htmlmode
getExtension($smime)
if($file) if($subject==""&&$file) if($subject=="") $err
Verify arguments for wsh programs.
$data
← centre documentaire © anakeen