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