Some documentation. Let's talk about it in wikitech-l.
[mediawiki.git] / includes / UserMailer.php
blob90ce0596161f684a9adc14b0595fe35a9fe3368b
1 <?php
2 /**
3 * Provide mail capabilities
5 */
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.
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
18 function userMailer( $to, $from, $subject, $body ) {
19 global $wgUser, $wgSMTP, $wgOutputEncoding, $wgErrorString;
21 $qto = wfQuotedPrintable( $to );
23 if (is_array( $wgSMTP ))
25 require_once( 'Mail.php' );
27 $timestamp = time();
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';
40 // Create the mail object using the Mail::factory method
41 $mail_object =& Mail::factory('smtp', $wgSMTP);
43 $mailResult =& $mail_object->send($to, $headers, $body);
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.';
54 else
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";
63 $wgErrorString = '';
64 set_error_handler( 'mailErrorHandler' );
65 mail( $to, $subject, $body, $headers );
66 restore_error_handler();
68 return $wgErrorString;
72 /**
75 function mailErrorHandler( $code, $string ) {
76 global $wgErrorString;
77 $wgErrorString = preg_replace( "/^mail\(\): /", "", $string );