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