Verzeichnisstruktur phpBB-2.0.0
- Veröffentlicht
- 03.04.2002
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
smtp.php
001 <?php
002 /***************************************************************************
003 * smtp.php
004 * -------------------
005 * begin : Wed May 09 2001
006 * copyright : (C) 2001 The phpBB Group
007 * email : support@phpbb.com
008 *
009 * $Id$
010 *
011 ***************************************************************************/
012
013 /***************************************************************************
014 *
015 * This program is free software; you can redistribute it and/or modify
016 * it under the terms of the GNU General Public License as published by
017 * the Free Software Foundation; either version 2 of the License, or
018 * (at your option) any later version.
019 *
020 ***************************************************************************/
021
022 define('SMTP_INCLUDED', 1);
023
024 //
025 // This function has been modified as provided
026 // by SirSir to allow multiline responses when
027 // using SMTP Extensions
028 //
029 function server_parse($socket, $response, $line = __LINE__)
030 {
031 $server_response = '';
032 while (substr($server_response, 3, 1) != ' ')
033 {
034 if (!($server_response = fgets($socket, 256)))
035 {
036 message_die(GENERAL_ERROR, "Couldn't get mail server response codes", "", $line, __FILE__);
037 }
038 }
039
040 if (!(substr($server_response, 0, 3) == $response))
041 {
042 message_die(GENERAL_ERROR, "Ran into problems sending Mail. Response: $server_response", "", $line, __FILE__);
043 }
044 }
045
046 // Replacement or substitute for PHP's mail command
047 function smtpmail($mail_to, $subject, $message, $headers = '')
048 {
049 global $board_config;
050
051 // Fix any bare linefeeds in the message to make it RFC821 Compliant.
052 $message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);
053
054 if ($headers != '')
055 {
056 if (is_array($headers))
057 {
058 if (sizeof($headers) > 1)
059 {
060 $headers = join("\n", $headers);
061 }
062 else
063 {
064 $headers = $headers[0];
065 }
066 }
067 $headers = chop($headers);
068
069 // Make sure there are no bare linefeeds in the headers
070 $headers = preg_replace('#(?<!\r)\n#si', "\r\n", $headers);
071
072 // Ok this is rather confusing all things considered,
073 // but we have to grab bcc and cc headers and treat them differently
074 // Something we really didn't take into consideration originally
075 $header_array = explode("\r\n", $headers);
076 @reset($header_array);
077
078 $headers = '';
079 while(list(, $header) = each($header_array))
080 {
081 if (preg_match('#^cc:#si', $header))
082 {
083 $cc = preg_replace('#^cc:(.*)#si', '\1', $header);
084 }
085 else if (preg_match('#^bcc:#si', $header))
086 {
087 $bcc = preg_replace('#^bcc:(.*)#si', '\1', $header);
088 $header = '';
089 }
090 $headers .= ($header != '') ? $header . "\r\n" : '';
091 }
092
093 $headers = chop($headers);
094 $cc = explode(', ', $cc);
095 $bcc = explode(', ', $bcc);
096 }
097
098 if (trim($subject) == '')
099 {
100 message_die(GENERAL_ERROR, "No email Subject specified", "", __LINE__, __FILE__);
101 }
102
103 if (trim($message) == '')
104 {
105 message_die(GENERAL_ERROR, "Email message was blank", "", __LINE__, __FILE__);
106 }
107
108 // Ok we have error checked as much as we can to this point let's get on
109 // it already.
110 if( !$socket = @fsockopen($board_config['smtp_host'], 25, $errno, $errstr, 20) )
111 {
112 message_die(GENERAL_ERROR, "Could not connect to smtp host : $errno : $errstr", "", __LINE__, __FILE__);
113 }
114
115 // Wait for reply
116 server_parse($socket, "220", __LINE__);
117
118 // Do we want to use AUTH?, send RFC2554 EHLO, else send RFC821 HELO
119 // This improved as provided by SirSir to accomodate
120 if( !empty($board_config['smtp_username']) && !empty($board_config['smtp_password']) )
121 {
122 fputs($socket, "EHLO " . $board_config['smtp_host'] . "\r\n");
123 server_parse($socket, "250", __LINE__);
124
125 fputs($socket, "AUTH LOGIN\r\n");
126 server_parse($socket, "334", __LINE__);
127
128 fputs($socket, base64_encode($board_config['smtp_username']) . "\r\n");
129 server_parse($socket, "334", __LINE__);
130
131 fputs($socket, base64_encode($board_config['smtp_password']) . "\r\n");
132 server_parse($socket, "235", __LINE__);
133 }
134 else
135 {
136 fputs($socket, "HELO " . $board_config['smtp_host'] . "\r\n");
137 server_parse($socket, "250", __LINE__);
138 }
139
140 // From this point onward most server response codes should be 250
141 // Specify who the mail is from....
142 fputs($socket, "MAIL FROM: <" . $board_config['board_email'] . ">\r\n");
143 server_parse($socket, "250", __LINE__);
144
145 // Specify each user to send to and build to header.
146 $to_header = '';
147
148 // Add an additional bit of error checking to the To field.
149 $mail_to = (trim($mail_to) == '') ? 'Undisclosed-recipients:;' : trim($mail_to);
150 if (preg_match('#[^ ]+\@[^ ]+#', $mail_to))
151 {
152 fputs($socket, "RCPT TO: <$mail_to>\r\n");
153 server_parse($socket, "250", __LINE__);
154 }
155
156 // Ok now do the CC and BCC fields...
157 @reset($bcc);
158 while(list(, $bcc_address) = each($bcc))
159 {
160 // Add an additional bit of error checking to bcc header...
161 $bcc_address = trim($bcc_address);
162 if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address))
163 {
164 fputs($socket, "RCPT TO: <$bcc_address>\r\n");
165 server_parse($socket, "250", __LINE__);
166 }
167 }
168
169 @reset($cc);
170 while(list(, $cc_address) = each($cc))
171 {
172 // Add an additional bit of error checking to cc header
173 $cc_address = trim($cc_address);
174 if (preg_match('#[^ ]+\@[^ ]+#', $cc_address))
175 {
176 fputs($socket, "RCPT TO: <$cc_address>\r\n");
177 server_parse($socket, "250", __LINE__);
178 }
179 }
180
181 // Ok now we tell the server we are ready to start sending data
182 fputs($socket, "DATA\r\n");
183
184 // This is the last response code we look for until the end of the message.
185 server_parse($socket, "354", __LINE__);
186
187 // Send the Subject Line...
188 fputs($socket, "Subject: $subject\r\n");
189
190 // Now the To Header.
191 fputs($socket, "To: $mail_to\r\n");
192
193 // Now any custom headers....
194 fputs($socket, "$headers\r\n\r\n");
195
196 // Ok now we are ready for the message...
197 fputs($socket, "$message\r\n");
198
199 // Ok the all the ingredients are mixed in let's cook this puppy...
200 fputs($socket, ".\r\n");
201 server_parse($socket, "250", __LINE__);
202
203 // Now tell the server we are done and close the socket...
204 fputs($socket, "QUIT\r\n");
205 fclose($socket);
206
207 return TRUE;
208 }
209
210 ?>