include_once -> require_once
[lhc/web/wiklou.git] / includes / UserMailer.php
1 <?php
2
3 # This function will perform a direct (authenticated) login to
4 # a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
5 # array of parameters. It requires PEAR:Mail to do that.
6 # Otherwise it just uses the standard PHP 'mail' function.
7 function userMailer( $to, $from, $subject, $body )
8 {
9 global $wgUser, $wgSMTP, $wgOutputEncoding, $wgErrorString;
10
11 $qto = wfQuotedPrintable( $to );
12
13 if (is_array( $wgSMTP ))
14 {
15 require_once( "Mail.php" );
16
17 $timestamp = time();
18
19 $headers["From"] = $from;
20 $headers["To"] = $qto;
21 $headers["Subject"] = $subject;
22 $headers["MIME-Version"] = "1.0";
23 $headers["Content-type"] = "text/plain; charset={$wgOutputEncoding}";
24 $headers["Content-transfer-encoding"] = "8bit";
25 $headers["Message-ID"] = "<{$timestamp}" . $wgUser->getName() . "@" . $wgSMTP["IDHost"] . ">";
26 $headers["X-Mailer"] = "MediaWiki interuser e-mailer";
27
28 // Create the mail object using the Mail::factory method
29 $mail_object =& Mail::factory("smtp", $wgSMTP);
30
31 $mailResult =& $mail_object->send($to, $headers, $body);
32
33 # Based on the result return an error string,
34 if ($mailResult === true)
35 return "";
36 else if (is_object($mailResult))
37 return $mailResult->getMessage();
38 else
39 return "Mail object return unknown error.";
40 }
41
42 else
43 {
44 $headers =
45 "MIME-Version: 1.0\r\n" .
46 "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" .
47 "Content-transfer-encoding: 8bit\r\n" .
48 "From: {$from}\r\n" .
49 "Reply-To: {$from}\r\n" .
50 "To: {$qto}\r\n" .
51 "X-Mailer: MediaWiki interuser e-mailer";
52
53 $wgErrorString = "";
54 set_error_handler( "mailErrorHandler" );
55 mail( $to, $subject, $body, $headers );
56 restore_error_handler();
57
58 return $wgErrorString;
59 }
60 }
61
62 function mailErrorHandler( $code, $string ) {
63 global $wgErrorString;
64 $wgErrorString = preg_replace( "/^mail\(\): /", "", $string );
65 }
66
67 ?>