Fix typo in quote conversion
[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 /* removing to: field as it should be set by the send() function below
21 UNTESTED - Hashar */
22 // $headers["To"] = $qto;
23 $headers['Subject'] = $subject;
24 $headers['MIME-Version'] = '1.0';
25 $headers['Content-type'] = 'text/plain; charset='.$wgOutputEncoding;
26 $headers['Content-transfer-encoding'] = '8bit';
27 $headers['Message-ID'] = "<{$timestamp}" . $wgUser->getName() . '@' . $wgSMTP['IDHost'] . '>';
28 $headers['X-Mailer'] = 'MediaWiki interuser e-mailer';
29
30 // Create the mail object using the Mail::factory method
31 $mail_object =& Mail::factory('smtp', $wgSMTP);
32
33 $mailResult =& $mail_object->send($to, $headers, $body);
34
35 # Based on the result return an error string,
36 if ($mailResult === true)
37 return '';
38 else if (is_object($mailResult))
39 return $mailResult->getMessage();
40 else
41 return 'Mail object return unknown error.';
42 }
43
44 else
45 {
46 $headers =
47 "MIME-Version: 1.0\n" .
48 "Content-type: text/plain; charset={$wgOutputEncoding}\n" .
49 "Content-transfer-encoding: 8bit\n" .
50 "From: {$from}\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 ?>