Revision 533
Added by doc almost 17 years ago
class.smtp.php | ||
---|---|---|
1 | 1 |
<?php |
2 |
//////////////////////////////////////////////////// |
|
3 |
// SMTP - PHP SMTP class |
|
4 |
// |
|
5 |
// Version 1.02 |
|
6 |
// |
|
7 |
// Define an SMTP class that can be used to connect |
|
8 |
// and communicate with any SMTP server. It implements |
|
9 |
// all the SMTP functions defined in RFC821 except TURN. |
|
10 |
// |
|
11 |
// Author: Chris Ryan |
|
12 |
// |
|
13 |
// License: LGPL, see LICENSE |
|
14 |
//////////////////////////////////////////////////// |
|
2 |
/*~ class.smtp.php |
|
3 |
.---------------------------------------------------------------------------. |
|
4 |
| Software: PHPMailer - PHP email class | |
|
5 |
| Version: 2.0.0 rc1 | |
|
6 |
| Contact: via sourceforge.net support pages (also www.codeworxtech.com) | |
|
7 |
| Info: http://phpmailer.sourceforge.net | |
|
8 |
| Support: http://sourceforge.net/projects/phpmailer/ | |
|
9 |
| ------------------------------------------------------------------------- | |
|
10 |
| Author: Andy Prevost (project admininistrator) | |
|
11 |
| Author: Brent R. Matzelle (original founder) | |
|
12 |
| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. | |
|
13 |
| Copyright (c) 2001-2003, Brent R. Matzelle | |
|
14 |
| ------------------------------------------------------------------------- | |
|
15 |
| License: Distributed under the Lesser General Public License (LGPL) | |
|
16 |
| http://www.gnu.org/copyleft/lesser.html | |
|
17 |
| This program is distributed in the hope that it will be useful - WITHOUT | |
|
18 |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
|
19 |
| FITNESS FOR A PARTICULAR PURPOSE. | |
|
20 |
| ------------------------------------------------------------------------- | |
|
21 |
| We offer a number of paid services (www.codeworxtech.com): | |
|
22 |
| - Web Hosting on highly optimized fast and secure servers | |
|
23 |
| - Technology Consulting | |
|
24 |
| - Oursourcing (highly qualified programmers and graphic designers) | |
|
25 |
'---------------------------------------------------------------------------' |
|
15 | 26 |
|
16 | 27 |
/** |
17 | 28 |
* SMTP is rfc 821 compliant and implements all the rfc 821 SMTP |
... | ... | |
21 | 32 |
* @package PHPMailer |
22 | 33 |
* @author Chris Ryan |
23 | 34 |
*/ |
35 |
|
|
24 | 36 |
class SMTP |
25 | 37 |
{ |
26 |
/** |
|
27 |
* SMTP server port |
|
28 |
* @var int |
|
29 |
*/ |
|
30 |
var $SMTP_PORT = 25; |
|
31 |
|
|
32 |
/** |
|
33 |
* SMTP reply line ending |
|
34 |
* @var string |
|
35 |
*/ |
|
36 |
var $CRLF = "\r\n"; |
|
37 |
|
|
38 |
/** |
|
39 |
* Sets whether debugging is turned on |
|
40 |
* @var bool |
|
41 |
*/ |
|
42 |
var $do_debug; # the level of debug to perform |
|
38 |
/** |
|
39 |
* SMTP server port |
|
40 |
* @var int |
|
41 |
*/ |
|
42 |
var $SMTP_PORT = 25; |
|
43 | 43 |
|
44 |
/**#@+ |
|
45 |
* @access private |
|
46 |
*/ |
|
47 |
var $smtp_conn; # the socket to the server |
|
48 |
var $error; # error if any on the last call |
|
49 |
var $helo_rply; # the reply the server sent to us for HELO |
|
50 |
/**#@-*/ |
|
44 |
/** |
|
45 |
* SMTP reply line ending |
|
46 |
* @var string |
|
47 |
*/ |
|
48 |
var $CRLF = "\r\n"; |
|
51 | 49 |
|
52 |
/** |
|
53 |
* Initialize the class so that the data is in a known state. |
|
54 |
* @access public |
|
55 |
* @return void |
|
56 |
*/ |
|
57 |
function SMTP() { |
|
58 |
$this->smtp_conn = 0; |
|
59 |
$this->error = null; |
|
60 |
$this->helo_rply = null; |
|
50 |
/** |
|
51 |
* Sets whether debugging is turned on |
|
52 |
* @var bool |
|
53 |
*/ |
|
54 |
var $do_debug; # the level of debug to perform |
|
61 | 55 |
|
62 |
$this->do_debug = 0; |
|
63 |
} |
|
56 |
/** |
|
57 |
* Sets VERP use on/off (default is off) |
|
58 |
* @var bool |
|
59 |
*/ |
|
60 |
var $do_verp = false; |
|
64 | 61 |
|
65 |
/************************************************************* |
|
66 |
* CONNECTION FUNCTIONS * |
|
67 |
***********************************************************/ |
|
62 |
/**#@+ |
|
63 |
* @access private |
|
64 |
*/ |
|
65 |
var $smtp_conn; # the socket to the server |
|
66 |
var $error; # error if any on the last call |
|
67 |
var $helo_rply; # the reply the server sent to us for HELO |
|
68 |
/**#@-*/ |
|
68 | 69 |
|
69 |
/** |
|
70 |
* Connect to the server specified on the port specified. |
|
71 |
* If the port is not specified use the default SMTP_PORT. |
|
72 |
* If tval is specified then a connection will try and be |
|
73 |
* established with the server for that number of seconds. |
|
74 |
* If tval is not specified the default is 30 seconds to |
|
75 |
* try on the connection. |
|
76 |
* |
|
77 |
* SMTP CODE SUCCESS: 220 |
|
78 |
* SMTP CODE FAILURE: 421 |
|
79 |
* @access public |
|
80 |
* @return bool |
|
81 |
*/ |
|
82 |
function Connect($host,$port=0,$tval=30) { |
|
83 |
# set the error val to null so there is no confusion |
|
84 |
$this->error = null; |
|
70 |
/** |
|
71 |
* Initialize the class so that the data is in a known state. |
|
72 |
* @access public |
|
73 |
* @return void |
|
74 |
*/ |
|
75 |
function SMTP() { |
|
76 |
$this->smtp_conn = 0; |
|
77 |
$this->error = null; |
|
78 |
$this->helo_rply = null; |
|
85 | 79 |
|
86 |
# make sure we are __not__ connected |
|
87 |
if($this->connected()) { |
|
88 |
# ok we are connected! what should we do? |
|
89 |
# for now we will just give an error saying we |
|
90 |
# are already connected |
|
91 |
$this->error = |
|
92 |
array("error" => "Already connected to a server"); |
|
93 |
return false; |
|
94 |
} |
|
80 |
$this->do_debug = 0; |
|
81 |
} |
|
95 | 82 |
|
96 |
if(empty($port)) {
|
|
97 |
$port = $this->SMTP_PORT;
|
|
98 |
}
|
|
83 |
/*************************************************************
|
|
84 |
* CONNECTION FUNCTIONS *
|
|
85 |
***********************************************************/
|
|
99 | 86 |
|
100 |
#connect to the smtp server |
|
101 |
$this->smtp_conn = fsockopen($host, # the host of the server |
|
102 |
$port, # the port to use |
|
103 |
$errno, # error number if any |
|
104 |
$errstr, # error message if any |
|
105 |
$tval); # give up after ? secs |
|
106 |
# verify we connected properly |
|
107 |
if(empty($this->smtp_conn)) { |
|
108 |
$this->error = array("error" => "Failed to connect to server", |
|
109 |
"errno" => $errno, |
|
110 |
"errstr" => $errstr); |
|
111 |
if($this->do_debug >= 1) { |
|
112 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
113 |
": $errstr ($errno)" . $this->CRLF; |
|
114 |
} |
|
115 |
return false; |
|
116 |
} |
|
87 |
/** |
|
88 |
* Connect to the server specified on the port specified. |
|
89 |
* If the port is not specified use the default SMTP_PORT. |
|
90 |
* If tval is specified then a connection will try and be |
|
91 |
* established with the server for that number of seconds. |
|
92 |
* If tval is not specified the default is 30 seconds to |
|
93 |
* try on the connection. |
|
94 |
* |
|
95 |
* SMTP CODE SUCCESS: 220 |
|
96 |
* SMTP CODE FAILURE: 421 |
|
97 |
* @access public |
|
98 |
* @return bool |
|
99 |
*/ |
|
100 |
function Connect($host,$port=0,$tval=30) { |
|
101 |
# set the error val to null so there is no confusion |
|
102 |
$this->error = null; |
|
117 | 103 |
|
118 |
# sometimes the SMTP server takes a little longer to respond |
|
119 |
# so we will give it a longer timeout for the first read |
|
120 |
// Windows still does not have support for this timeout function |
|
121 |
if(substr(PHP_OS, 0, 3) != "WIN") |
|
122 |
socket_set_timeout($this->smtp_conn, $tval, 0); |
|
104 |
# make sure we are __not__ connected |
|
105 |
if($this->connected()) { |
|
106 |
# ok we are connected! what should we do? |
|
107 |
# for now we will just give an error saying we |
|
108 |
# are already connected |
|
109 |
$this->error = array("error" => "Already connected to a server"); |
|
110 |
return false; |
|
111 |
} |
|
123 | 112 |
|
124 |
# get any announcement stuff |
|
125 |
$announce = $this->get_lines(); |
|
113 |
if(empty($port)) { |
|
114 |
$port = $this->SMTP_PORT; |
|
115 |
} |
|
126 | 116 |
|
127 |
# set the timeout of any socket functions at 1/10 of a second |
|
128 |
//if(function_exists("socket_set_timeout")) |
|
129 |
// socket_set_timeout($this->smtp_conn, 0, 100000); |
|
117 |
#connect to the smtp server |
|
118 |
$this->smtp_conn = fsockopen($host, # the host of the server |
|
119 |
$port, # the port to use |
|
120 |
$errno, # error number if any |
|
121 |
$errstr, # error message if any |
|
122 |
$tval); # give up after ? secs |
|
123 |
# verify we connected properly |
|
124 |
if(empty($this->smtp_conn)) { |
|
125 |
$this->error = array("error" => "Failed to connect to server", |
|
126 |
"errno" => $errno, |
|
127 |
"errstr" => $errstr); |
|
128 |
if($this->do_debug >= 1) { |
|
129 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
130 |
": $errstr ($errno)" . $this->CRLF; |
|
131 |
} |
|
132 |
return false; |
|
133 |
} |
|
130 | 134 |
|
131 |
if($this->do_debug >= 2) { |
|
132 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce; |
|
133 |
} |
|
135 |
# sometimes the SMTP server takes a little longer to respond |
|
136 |
# so we will give it a longer timeout for the first read |
|
137 |
// Windows still does not have support for this timeout function |
|
138 |
if(substr(PHP_OS, 0, 3) != "WIN") |
|
139 |
socket_set_timeout($this->smtp_conn, $tval, 0); |
|
134 | 140 |
|
135 |
return true; |
|
141 |
# get any announcement stuff |
|
142 |
$announce = $this->get_lines(); |
|
143 |
|
|
144 |
# set the timeout of any socket functions at 1/10 of a second |
|
145 |
//if(function_exists("socket_set_timeout")) |
|
146 |
// socket_set_timeout($this->smtp_conn, 0, 100000); |
|
147 |
|
|
148 |
if($this->do_debug >= 2) { |
|
149 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce; |
|
136 | 150 |
} |
137 | 151 |
|
138 |
/** |
|
139 |
* Performs SMTP authentication. Must be run after running the |
|
140 |
* Hello() method. Returns true if successfully authenticated. |
|
141 |
* @access public |
|
142 |
* @return bool |
|
143 |
*/ |
|
144 |
function Authenticate($username, $password) { |
|
145 |
// Start authentication |
|
146 |
fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|
152 |
return true; |
|
153 |
} |
|
147 | 154 |
|
148 |
$rply = $this->get_lines(); |
|
149 |
$code = substr($rply,0,3); |
|
155 |
/** |
|
156 |
* Performs SMTP authentication. Must be run after running the |
|
157 |
* Hello() method. Returns true if successfully authenticated. |
|
158 |
* @access public |
|
159 |
* @return bool |
|
160 |
*/ |
|
161 |
function Authenticate($username, $password) { |
|
162 |
// Start authentication |
|
163 |
fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|
150 | 164 |
|
151 |
if($code != 334) { |
|
152 |
$this->error = |
|
153 |
array("error" => "AUTH not accepted from server", |
|
154 |
"smtp_code" => $code, |
|
155 |
"smtp_msg" => substr($rply,4)); |
|
156 |
if($this->do_debug >= 1) { |
|
157 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
158 |
": " . $rply . $this->CRLF; |
|
159 |
} |
|
160 |
return false; |
|
161 |
} |
|
165 |
$rply = $this->get_lines(); |
|
166 |
$code = substr($rply,0,3); |
|
162 | 167 |
|
163 |
// Send encoded username |
|
164 |
fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); |
|
168 |
if($code != 334) { |
|
169 |
$this->error = |
|
170 |
array("error" => "AUTH not accepted from server", |
|
171 |
"smtp_code" => $code, |
|
172 |
"smtp_msg" => substr($rply,4)); |
|
173 |
if($this->do_debug >= 1) { |
|
174 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
175 |
": " . $rply . $this->CRLF; |
|
176 |
} |
|
177 |
return false; |
|
178 |
} |
|
165 | 179 |
|
166 |
$rply = $this->get_lines();
|
|
167 |
$code = substr($rply,0,3);
|
|
180 |
// Send encoded username
|
|
181 |
fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
|
|
168 | 182 |
|
169 |
if($code != 334) { |
|
170 |
$this->error = |
|
171 |
array("error" => "Username not accepted from server", |
|
172 |
"smtp_code" => $code, |
|
173 |
"smtp_msg" => substr($rply,4)); |
|
174 |
if($this->do_debug >= 1) { |
|
175 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
176 |
": " . $rply . $this->CRLF; |
|
177 |
} |
|
178 |
return false; |
|
179 |
} |
|
183 |
$rply = $this->get_lines(); |
|
184 |
$code = substr($rply,0,3); |
|
180 | 185 |
|
181 |
// Send encoded password |
|
182 |
fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); |
|
186 |
if($code != 334) { |
|
187 |
$this->error = |
|
188 |
array("error" => "Username not accepted from server", |
|
189 |
"smtp_code" => $code, |
|
190 |
"smtp_msg" => substr($rply,4)); |
|
191 |
if($this->do_debug >= 1) { |
|
192 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
193 |
": " . $rply . $this->CRLF; |
|
194 |
} |
|
195 |
return false; |
|
196 |
} |
|
183 | 197 |
|
184 |
$rply = $this->get_lines();
|
|
185 |
$code = substr($rply,0,3);
|
|
198 |
// Send encoded password
|
|
199 |
fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
|
|
186 | 200 |
|
187 |
if($code != 235) { |
|
188 |
$this->error = |
|
189 |
array("error" => "Password not accepted from server", |
|
190 |
"smtp_code" => $code, |
|
191 |
"smtp_msg" => substr($rply,4)); |
|
192 |
if($this->do_debug >= 1) { |
|
193 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
194 |
": " . $rply . $this->CRLF; |
|
195 |
} |
|
196 |
return false; |
|
197 |
} |
|
201 |
$rply = $this->get_lines(); |
|
202 |
$code = substr($rply,0,3); |
|
198 | 203 |
|
199 |
return true; |
|
204 |
if($code != 235) { |
|
205 |
$this->error = |
|
206 |
array("error" => "Password not accepted from server", |
|
207 |
"smtp_code" => $code, |
|
208 |
"smtp_msg" => substr($rply,4)); |
|
209 |
if($this->do_debug >= 1) { |
|
210 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
211 |
": " . $rply . $this->CRLF; |
|
212 |
} |
|
213 |
return false; |
|
200 | 214 |
} |
201 | 215 |
|
202 |
/** |
|
203 |
* Returns true if connected to a server otherwise false |
|
204 |
* @access private |
|
205 |
* @return bool |
|
206 |
*/ |
|
207 |
function Connected() { |
|
208 |
if(!empty($this->smtp_conn)) { |
|
209 |
$sock_status = socket_get_status($this->smtp_conn); |
|
210 |
if($sock_status["eof"]) { |
|
211 |
# hmm this is an odd situation... the socket is |
|
212 |
# valid but we aren't connected anymore |
|
213 |
if($this->do_debug >= 1) { |
|
214 |
echo "SMTP -> NOTICE:" . $this->CRLF . |
|
215 |
"EOF caught while checking if connected"; |
|
216 |
} |
|
217 |
$this->Close(); |
|
218 |
return false; |
|
219 |
} |
|
220 |
return true; # everything looks good |
|
216 |
return true; |
|
217 |
} |
|
218 |
|
|
219 |
/** |
|
220 |
* Returns true if connected to a server otherwise false |
|
221 |
* @access private |
|
222 |
* @return bool |
|
223 |
*/ |
|
224 |
function Connected() { |
|
225 |
if(!empty($this->smtp_conn)) { |
|
226 |
$sock_status = socket_get_status($this->smtp_conn); |
|
227 |
if($sock_status["eof"]) { |
|
228 |
# hmm this is an odd situation... the socket is |
|
229 |
# valid but we are not connected anymore |
|
230 |
if($this->do_debug >= 1) { |
|
231 |
echo "SMTP -> NOTICE:" . $this->CRLF . |
|
232 |
"EOF caught while checking if connected"; |
|
221 | 233 |
} |
234 |
$this->Close(); |
|
222 | 235 |
return false; |
236 |
} |
|
237 |
return true; # everything looks good |
|
223 | 238 |
} |
239 |
return false; |
|
240 |
} |
|
224 | 241 |
|
225 |
/** |
|
226 |
* Closes the socket and cleans up the state of the class. |
|
227 |
* It is not considered good to use this function without |
|
228 |
* first trying to use QUIT. |
|
229 |
* @access public |
|
230 |
* @return void |
|
231 |
*/ |
|
232 |
function Close() { |
|
233 |
$this->error = null; # so there is no confusion |
|
234 |
$this->helo_rply = null; |
|
235 |
if(!empty($this->smtp_conn)) { |
|
236 |
# close the connection and cleanup |
|
237 |
fclose($this->smtp_conn); |
|
238 |
$this->smtp_conn = 0; |
|
239 |
} |
|
242 |
/** |
|
243 |
* Closes the socket and cleans up the state of the class. |
|
244 |
* It is not considered good to use this function without |
|
245 |
* first trying to use QUIT. |
|
246 |
* @access public |
|
247 |
* @return void |
|
248 |
*/ |
|
249 |
function Close() { |
|
250 |
$this->error = null; # so there is no confusion |
|
251 |
$this->helo_rply = null; |
|
252 |
if(!empty($this->smtp_conn)) { |
|
253 |
# close the connection and cleanup |
|
254 |
fclose($this->smtp_conn); |
|
255 |
$this->smtp_conn = 0; |
|
240 | 256 |
} |
257 |
} |
|
241 | 258 |
|
259 |
/*************************************************************** |
|
260 |
* SMTP COMMANDS * |
|
261 |
*************************************************************/ |
|
242 | 262 |
|
243 |
/*************************************************************** |
|
244 |
* SMTP COMMANDS * |
|
245 |
*************************************************************/ |
|
263 |
/** |
|
264 |
* Issues a data command and sends the msg_data to the server |
|
265 |
* finializing the mail transaction. $msg_data is the message |
|
266 |
* that is to be send with the headers. Each header needs to be |
|
267 |
* on a single line followed by a <CRLF> with the message headers |
|
268 |
* and the message body being seperated by and additional <CRLF>. |
|
269 |
* |
|
270 |
* Implements rfc 821: DATA <CRLF> |
|
271 |
* |
|
272 |
* SMTP CODE INTERMEDIATE: 354 |
|
273 |
* [data] |
|
274 |
* <CRLF>.<CRLF> |
|
275 |
* SMTP CODE SUCCESS: 250 |
|
276 |
* SMTP CODE FAILURE: 552,554,451,452 |
|
277 |
* SMTP CODE FAILURE: 451,554 |
|
278 |
* SMTP CODE ERROR : 500,501,503,421 |
|
279 |
* @access public |
|
280 |
* @return bool |
|
281 |
*/ |
|
282 |
function Data($msg_data) { |
|
283 |
$this->error = null; # so no confusion is caused |
|
246 | 284 |
|
247 |
/** |
|
248 |
* Issues a data command and sends the msg_data to the server |
|
249 |
* finializing the mail transaction. $msg_data is the message |
|
250 |
* that is to be send with the headers. Each header needs to be |
|
251 |
* on a single line followed by a <CRLF> with the message headers |
|
252 |
* and the message body being seperated by and additional <CRLF>. |
|
253 |
* |
|
254 |
* Implements rfc 821: DATA <CRLF> |
|
255 |
* |
|
256 |
* SMTP CODE INTERMEDIATE: 354 |
|
257 |
* [data] |
|
258 |
* <CRLF>.<CRLF> |
|
259 |
* SMTP CODE SUCCESS: 250 |
|
260 |
* SMTP CODE FAILURE: 552,554,451,452 |
|
261 |
* SMTP CODE FAILURE: 451,554 |
|
262 |
* SMTP CODE ERROR : 500,501,503,421 |
|
263 |
* @access public |
|
264 |
* @return bool |
|
265 |
*/ |
|
266 |
function Data($msg_data) { |
|
267 |
$this->error = null; # so no confusion is caused |
|
285 |
if(!$this->connected()) { |
|
286 |
$this->error = array( |
|
287 |
"error" => "Called Data() without being connected"); |
|
288 |
return false; |
|
289 |
} |
|
268 | 290 |
|
269 |
if(!$this->connected()) { |
|
270 |
$this->error = array( |
|
271 |
"error" => "Called Data() without being connected"); |
|
272 |
return false; |
|
273 |
} |
|
291 |
fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|
274 | 292 |
|
275 |
fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|
293 |
$rply = $this->get_lines(); |
|
294 |
$code = substr($rply,0,3); |
|
276 | 295 |
|
277 |
$rply = $this->get_lines(); |
|
278 |
$code = substr($rply,0,3); |
|
296 |
if($this->do_debug >= 2) { |
|
297 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
298 |
} |
|
279 | 299 |
|
280 |
if($this->do_debug >= 2) { |
|
281 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
282 |
} |
|
300 |
if($code != 354) { |
|
301 |
$this->error = |
|
302 |
array("error" => "DATA command not accepted from server", |
|
303 |
"smtp_code" => $code, |
|
304 |
"smtp_msg" => substr($rply,4)); |
|
305 |
if($this->do_debug >= 1) { |
|
306 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
307 |
": " . $rply . $this->CRLF; |
|
308 |
} |
|
309 |
return false; |
|
310 |
} |
|
283 | 311 |
|
284 |
if($code != 354) { |
|
285 |
$this->error = |
|
286 |
array("error" => "DATA command not accepted from server", |
|
287 |
"smtp_code" => $code, |
|
288 |
"smtp_msg" => substr($rply,4)); |
|
289 |
if($this->do_debug >= 1) { |
|
290 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
291 |
": " . $rply . $this->CRLF; |
|
292 |
} |
|
293 |
return false; |
|
294 |
} |
|
312 |
# the server is ready to accept data! |
|
313 |
# according to rfc 821 we should not send more than 1000 |
|
314 |
# including the CRLF |
|
315 |
# characters on a single line so we will break the data up |
|
316 |
# into lines by \r and/or \n then if needed we will break |
|
317 |
# each of those into smaller lines to fit within the limit. |
|
318 |
# in addition we will be looking for lines that start with |
|
319 |
# a period '.' and append and additional period '.' to that |
|
320 |
# line. NOTE: this does not count towards are limit. |
|
295 | 321 |
|
296 |
# the server is ready to accept data! |
|
297 |
# according to rfc 821 we should not send more than 1000 |
|
298 |
# including the CRLF |
|
299 |
# characters on a single line so we will break the data up |
|
300 |
# into lines by \r and/or \n then if needed we will break |
|
301 |
# each of those into smaller lines to fit within the limit. |
|
302 |
# in addition we will be looking for lines that start with |
|
303 |
# a period '.' and append and additional period '.' to that |
|
304 |
# line. NOTE: this does not count towards are limit. |
|
322 |
# normalize the line breaks so we know the explode works |
|
323 |
$msg_data = str_replace("\r\n","\n",$msg_data); |
|
324 |
$msg_data = str_replace("\r","\n",$msg_data); |
|
325 |
$lines = explode("\n",$msg_data); |
|
305 | 326 |
|
306 |
# normalize the line breaks so we know the explode works |
|
307 |
$msg_data = str_replace("\r\n","\n",$msg_data); |
|
308 |
$msg_data = str_replace("\r","\n",$msg_data); |
|
309 |
$lines = explode("\n",$msg_data); |
|
327 |
# we need to find a good way to determine is headers are |
|
328 |
# in the msg_data or if it is a straight msg body |
|
329 |
# currently I am assuming rfc 822 definitions of msg headers |
|
330 |
# and if the first field of the first line (':' sperated) |
|
331 |
# does not contain a space then it _should_ be a header |
|
332 |
# and we can process all lines before a blank "" line as |
|
333 |
# headers. |
|
334 |
$field = substr($lines[0],0,strpos($lines[0],":")); |
|
335 |
$in_headers = false; |
|
336 |
if(!empty($field) && !strstr($field," ")) { |
|
337 |
$in_headers = true; |
|
338 |
} |
|
310 | 339 |
|
311 |
# we need to find a good way to determine is headers are |
|
312 |
# in the msg_data or if it is a straight msg body |
|
313 |
# currently I'm assuming rfc 822 definitions of msg headers |
|
314 |
# and if the first field of the first line (':' sperated) |
|
315 |
# does not contain a space then it _should_ be a header |
|
316 |
# and we can process all lines before a blank "" line as |
|
317 |
# headers. |
|
318 |
$field = substr($lines[0],0,strpos($lines[0],":")); |
|
340 |
$max_line_length = 998; # used below; set here for ease in change |
|
341 |
|
|
342 |
while(list(,$line) = @each($lines)) { |
|
343 |
$lines_out = null; |
|
344 |
if($line == "" && $in_headers) { |
|
319 | 345 |
$in_headers = false; |
320 |
if(!empty($field) && !strstr($field," ")) { |
|
321 |
$in_headers = true; |
|
346 |
} |
|
347 |
# ok we need to break this line up into several |
|
348 |
# smaller lines |
|
349 |
while(strlen($line) > $max_line_length) { |
|
350 |
$pos = strrpos(substr($line,0,$max_line_length)," "); |
|
351 |
|
|
352 |
# Patch to fix DOS attack |
|
353 |
if(!$pos) { |
|
354 |
$pos = $max_line_length - 1; |
|
322 | 355 |
} |
323 | 356 |
|
324 |
$max_line_length = 998; # used below; set here for ease in change |
|
357 |
$lines_out[] = substr($line,0,$pos); |
|
358 |
$line = substr($line,$pos + 1); |
|
359 |
# if we are processing headers we need to |
|
360 |
# add a LWSP-char to the front of the new line |
|
361 |
# rfc 822 on long msg headers |
|
362 |
if($in_headers) { |
|
363 |
$line = "\t" . $line; |
|
364 |
} |
|
365 |
} |
|
366 |
$lines_out[] = $line; |
|
325 | 367 |
|
326 |
while(list(,$line) = @each($lines)) { |
|
327 |
$lines_out = null; |
|
328 |
if($line == "" && $in_headers) { |
|
329 |
$in_headers = false; |
|
330 |
} |
|
331 |
# ok we need to break this line up into several |
|
332 |
# smaller lines |
|
333 |
while(strlen($line) > $max_line_length) { |
|
334 |
$pos = strrpos(substr($line,0,$max_line_length)," "); |
|
335 |
|
|
336 |
# Patch to fix DOS attack |
|
337 |
if(!$pos) { |
|
338 |
$pos = $max_line_length - 1; |
|
339 |
} |
|
340 |
|
|
341 |
$lines_out[] = substr($line,0,$pos); |
|
342 |
$line = substr($line,$pos + 1); |
|
343 |
# if we are processing headers we need to |
|
344 |
# add a LWSP-char to the front of the new line |
|
345 |
# rfc 822 on long msg headers |
|
346 |
if($in_headers) { |
|
347 |
$line = "\t" . $line; |
|
348 |
} |
|
349 |
} |
|
350 |
$lines_out[] = $line; |
|
351 |
|
|
352 |
# now send the lines to the server |
|
353 |
while(list(,$line_out) = @each($lines_out)) { |
|
354 |
if(strlen($line_out) > 0) |
|
355 |
{ |
|
356 |
if(substr($line_out, 0, 1) == ".") { |
|
357 |
$line_out = "." . $line_out; |
|
358 |
} |
|
359 |
} |
|
360 |
fputs($this->smtp_conn,$line_out . $this->CRLF); |
|
361 |
} |
|
368 |
# now send the lines to the server |
|
369 |
while(list(,$line_out) = @each($lines_out)) { |
|
370 |
if(strlen($line_out) > 0) |
|
371 |
{ |
|
372 |
if(substr($line_out, 0, 1) == ".") { |
|
373 |
$line_out = "." . $line_out; |
|
374 |
} |
|
362 | 375 |
} |
376 |
fputs($this->smtp_conn,$line_out . $this->CRLF); |
|
377 |
} |
|
378 |
} |
|
363 | 379 |
|
364 |
# ok all the message data has been sent so lets get this
|
|
365 |
# over with aleady
|
|
366 |
fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
|
|
380 |
# ok all the message data has been sent so lets get this |
|
381 |
# over with aleady |
|
382 |
fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); |
|
367 | 383 |
|
368 |
$rply = $this->get_lines();
|
|
369 |
$code = substr($rply,0,3);
|
|
384 |
$rply = $this->get_lines(); |
|
385 |
$code = substr($rply,0,3); |
|
370 | 386 |
|
371 |
if($this->do_debug >= 2) {
|
|
372 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
|
|
373 |
}
|
|
387 |
if($this->do_debug >= 2) { |
|
388 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
389 |
} |
|
374 | 390 |
|
375 |
if($code != 250) { |
|
376 |
$this->error = |
|
377 |
array("error" => "DATA not accepted from server", |
|
378 |
"smtp_code" => $code, |
|
379 |
"smtp_msg" => substr($rply,4)); |
|
380 |
if($this->do_debug >= 1) { |
|
381 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
382 |
": " . $rply . $this->CRLF; |
|
383 |
} |
|
384 |
return false; |
|
385 |
} |
|
386 |
return true; |
|
391 |
if($code != 250) { |
|
392 |
$this->error = |
|
393 |
array("error" => "DATA not accepted from server", |
|
394 |
"smtp_code" => $code, |
|
395 |
"smtp_msg" => substr($rply,4)); |
|
396 |
if($this->do_debug >= 1) { |
|
397 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
398 |
": " . $rply . $this->CRLF; |
|
399 |
} |
|
400 |
return false; |
|
387 | 401 |
} |
402 |
return true; |
|
403 |
} |
|
388 | 404 |
|
389 |
/**
|
|
390 |
* Expand takes the name and asks the server to list all the
|
|
391 |
* people who are members of the _list_. Expand will return
|
|
392 |
* back and array of the result or false if an error occurs.
|
|
393 |
* Each value in the array returned has the format of:
|
|
394 |
* [ <full-name> <sp> ] <path>
|
|
395 |
* The definition of <path> is defined in rfc 821
|
|
396 |
*
|
|
397 |
* Implements rfc 821: EXPN <SP> <string> <CRLF>
|
|
398 |
*
|
|
399 |
* SMTP CODE SUCCESS: 250
|
|
400 |
* SMTP CODE FAILURE: 550
|
|
401 |
* SMTP CODE ERROR : 500,501,502,504,421
|
|
402 |
* @access public
|
|
403 |
* @return string array
|
|
404 |
*/
|
|
405 |
function Expand($name) {
|
|
406 |
$this->error = null; # so no confusion is caused
|
|
405 |
/** |
|
406 |
* Expand takes the name and asks the server to list all the |
|
407 |
* people who are members of the _list_. Expand will return |
|
408 |
* back and array of the result or false if an error occurs. |
|
409 |
* Each value in the array returned has the format of: |
|
410 |
* [ <full-name> <sp> ] <path> |
|
411 |
* The definition of <path> is defined in rfc 821 |
|
412 |
* |
|
413 |
* Implements rfc 821: EXPN <SP> <string> <CRLF> |
|
414 |
* |
|
415 |
* SMTP CODE SUCCESS: 250 |
|
416 |
* SMTP CODE FAILURE: 550 |
|
417 |
* SMTP CODE ERROR : 500,501,502,504,421 |
|
418 |
* @access public |
|
419 |
* @return string array |
|
420 |
*/ |
|
421 |
function Expand($name) { |
|
422 |
$this->error = null; # so no confusion is caused |
|
407 | 423 |
|
408 |
if(!$this->connected()) {
|
|
409 |
$this->error = array(
|
|
410 |
"error" => "Called Expand() without being connected");
|
|
411 |
return false;
|
|
412 |
}
|
|
424 |
if(!$this->connected()) { |
|
425 |
$this->error = array( |
|
426 |
"error" => "Called Expand() without being connected"); |
|
427 |
return false; |
|
428 |
} |
|
413 | 429 |
|
414 |
fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
|
|
430 |
fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF); |
|
415 | 431 |
|
416 |
$rply = $this->get_lines();
|
|
417 |
$code = substr($rply,0,3);
|
|
432 |
$rply = $this->get_lines(); |
|
433 |
$code = substr($rply,0,3); |
|
418 | 434 |
|
419 |
if($this->do_debug >= 2) {
|
|
420 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
|
|
421 |
}
|
|
435 |
if($this->do_debug >= 2) { |
|
436 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
437 |
} |
|
422 | 438 |
|
423 |
if($code != 250) {
|
|
424 |
$this->error =
|
|
425 |
array("error" => "EXPN not accepted from server",
|
|
426 |
"smtp_code" => $code,
|
|
427 |
"smtp_msg" => substr($rply,4));
|
|
428 |
if($this->do_debug >= 1) {
|
|
429 |
echo "SMTP -> ERROR: " . $this->error["error"] .
|
|
430 |
": " . $rply . $this->CRLF;
|
|
431 |
}
|
|
432 |
return false;
|
|
433 |
}
|
|
439 |
if($code != 250) { |
|
440 |
$this->error = |
|
441 |
array("error" => "EXPN not accepted from server", |
|
442 |
"smtp_code" => $code, |
|
443 |
"smtp_msg" => substr($rply,4)); |
|
444 |
if($this->do_debug >= 1) { |
|
445 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
446 |
": " . $rply . $this->CRLF; |
|
447 |
} |
|
448 |
return false; |
|
449 |
} |
|
434 | 450 |
|
435 |
# parse the reply and place in our array to return to user |
|
436 |
$entries = explode($this->CRLF,$rply); |
|
437 |
while(list(,$l) = @each($entries)) { |
|
438 |
$list[] = substr($l,4); |
|
439 |
} |
|
440 |
|
|
441 |
return $list; |
|
451 |
# parse the reply and place in our array to return to user |
|
452 |
$entries = explode($this->CRLF,$rply); |
|
453 |
while(list(,$l) = @each($entries)) { |
|
454 |
$list[] = substr($l,4); |
|
442 | 455 |
} |
443 | 456 |
|
444 |
/** |
|
445 |
* Sends the HELO command to the smtp server. |
|
446 |
* This makes sure that we and the server are in |
|
447 |
* the same known state. |
|
448 |
* |
|
449 |
* Implements from rfc 821: HELO <SP> <domain> <CRLF> |
|
450 |
* |
|
451 |
* SMTP CODE SUCCESS: 250 |
|
452 |
* SMTP CODE ERROR : 500, 501, 504, 421 |
|
453 |
* @access public |
|
454 |
* @return bool |
|
455 |
*/ |
|
456 |
function Hello($host="") { |
|
457 |
$this->error = null; # so no confusion is caused |
|
457 |
return $list; |
|
458 |
} |
|
458 | 459 |
|
459 |
if(!$this->connected()) { |
|
460 |
$this->error = array( |
|
461 |
"error" => "Called Hello() without being connected"); |
|
462 |
return false; |
|
463 |
} |
|
460 |
/** |
|
461 |
* Sends the HELO command to the smtp server. |
|
462 |
* This makes sure that we and the server are in |
|
463 |
* the same known state. |
|
464 |
* |
|
465 |
* Implements from rfc 821: HELO <SP> <domain> <CRLF> |
|
466 |
* |
|
467 |
* SMTP CODE SUCCESS: 250 |
|
468 |
* SMTP CODE ERROR : 500, 501, 504, 421 |
|
469 |
* @access public |
|
470 |
* @return bool |
|
471 |
*/ |
|
472 |
function Hello($host="") { |
|
473 |
$this->error = null; # so no confusion is caused |
|
464 | 474 |
|
465 |
# if a hostname for the HELO wasn't specified determine |
|
466 |
# a suitable one to send |
|
467 |
if(empty($host)) { |
|
468 |
# we need to determine some sort of appopiate default |
|
469 |
# to send to the server |
|
470 |
$host = "localhost"; |
|
471 |
} |
|
475 |
if(!$this->connected()) { |
|
476 |
$this->error = array( |
|
477 |
"error" => "Called Hello() without being connected"); |
|
478 |
return false; |
|
479 |
} |
|
472 | 480 |
|
473 |
// Send extended hello first (RFC 2821) |
|
474 |
if(!$this->SendHello("EHLO", $host)) |
|
475 |
{ |
|
476 |
if(!$this->SendHello("HELO", $host)) |
|
477 |
return false; |
|
478 |
} |
|
481 |
# if a hostname for the HELO was not specified determine |
|
482 |
# a suitable one to send |
|
483 |
if(empty($host)) { |
|
484 |
# we need to determine some sort of appopiate default |
|
485 |
# to send to the server |
|
486 |
$host = "localhost"; |
|
487 |
} |
|
479 | 488 |
|
480 |
return true; |
|
489 |
// Send extended hello first (RFC 2821) |
|
490 |
if(!$this->SendHello("EHLO", $host)) |
|
491 |
{ |
|
492 |
if(!$this->SendHello("HELO", $host)) |
|
493 |
return false; |
|
481 | 494 |
} |
482 | 495 |
|
483 |
/** |
|
484 |
* Sends a HELO/EHLO command. |
|
485 |
* @access private |
|
486 |
* @return bool |
|
487 |
*/ |
|
488 |
function SendHello($hello, $host) { |
|
489 |
fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|
496 |
return true; |
|
497 |
} |
|
490 | 498 |
|
491 |
$rply = $this->get_lines(); |
|
492 |
$code = substr($rply,0,3); |
|
499 |
/** |
|
500 |
* Sends a HELO/EHLO command. |
|
501 |
* @access private |
|
502 |
* @return bool |
|
503 |
*/ |
|
504 |
function SendHello($hello, $host) { |
|
505 |
fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|
493 | 506 |
|
494 |
if($this->do_debug >= 2) { |
|
495 |
echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply; |
|
496 |
} |
|
507 |
$rply = $this->get_lines(); |
|
508 |
$code = substr($rply,0,3); |
|
497 | 509 |
|
498 |
if($code != 250) { |
|
499 |
$this->error = |
|
500 |
array("error" => $hello . " not accepted from server", |
|
501 |
"smtp_code" => $code, |
|
502 |
"smtp_msg" => substr($rply,4)); |
|
503 |
if($this->do_debug >= 1) { |
|
504 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
505 |
": " . $rply . $this->CRLF; |
|
506 |
} |
|
507 |
return false; |
|
508 |
} |
|
510 |
if($this->do_debug >= 2) { |
|
511 |
echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply; |
|
512 |
} |
|
509 | 513 |
|
510 |
$this->helo_rply = $rply; |
|
511 |
|
|
512 |
return true; |
|
514 |
if($code != 250) { |
|
515 |
$this->error = |
|
516 |
array("error" => $hello . " not accepted from server", |
|
517 |
"smtp_code" => $code, |
|
518 |
"smtp_msg" => substr($rply,4)); |
|
519 |
if($this->do_debug >= 1) { |
|
520 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
521 |
": " . $rply . $this->CRLF; |
|
522 |
} |
|
523 |
return false; |
|
513 | 524 |
} |
514 | 525 |
|
515 |
/** |
|
516 |
* Gets help information on the keyword specified. If the keyword |
|
517 |
* is not specified then returns generic help, ussually contianing |
|
518 |
* A list of keywords that help is available on. This function |
|
519 |
* returns the results back to the user. It is up to the user to |
|
520 |
* handle the returned data. If an error occurs then false is |
|
521 |
* returned with $this->error set appropiately. |
|
522 |
* |
|
523 |
* Implements rfc 821: HELP [ <SP> <string> ] <CRLF> |
|
524 |
* |
|
525 |
* SMTP CODE SUCCESS: 211,214 |
|
526 |
* SMTP CODE ERROR : 500,501,502,504,421 |
|
527 |
* @access public |
|
528 |
* @return string |
|
529 |
*/ |
|
530 |
function Help($keyword="") { |
|
531 |
$this->error = null; # to avoid confusion |
|
526 |
$this->helo_rply = $rply; |
|
532 | 527 |
|
533 |
if(!$this->connected()) { |
|
534 |
$this->error = array( |
|
535 |
"error" => "Called Help() without being connected"); |
|
536 |
return false; |
|
537 |
} |
|
528 |
return true; |
|
529 |
} |
|
538 | 530 |
|
539 |
$extra = ""; |
|
540 |
if(!empty($keyword)) { |
|
541 |
$extra = " " . $keyword; |
|
542 |
} |
|
531 |
/** |
|
532 |
* Gets help information on the keyword specified. If the keyword |
|
533 |
* is not specified then returns generic help, ussually contianing |
|
534 |
* A list of keywords that help is available on. This function |
|
535 |
* returns the results back to the user. It is up to the user to |
|
536 |
* handle the returned data. If an error occurs then false is |
|
537 |
* returned with $this->error set appropiately. |
|
538 |
* |
|
539 |
* Implements rfc 821: HELP [ <SP> <string> ] <CRLF> |
|
540 |
* |
|
541 |
* SMTP CODE SUCCESS: 211,214 |
|
542 |
* SMTP CODE ERROR : 500,501,502,504,421 |
|
543 |
* @access public |
|
544 |
* @return string |
|
545 |
*/ |
|
546 |
function Help($keyword="") { |
|
547 |
$this->error = null; # to avoid confusion |
|
543 | 548 |
|
544 |
fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF); |
|
549 |
if(!$this->connected()) { |
|
550 |
$this->error = array( |
|
551 |
"error" => "Called Help() without being connected"); |
|
552 |
return false; |
|
553 |
} |
|
545 | 554 |
|
546 |
$rply = $this->get_lines(); |
|
547 |
$code = substr($rply,0,3); |
|
555 |
$extra = ""; |
|
556 |
if(!empty($keyword)) { |
|
557 |
$extra = " " . $keyword; |
|
558 |
} |
|
548 | 559 |
|
549 |
if($this->do_debug >= 2) { |
|
550 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
551 |
} |
|
560 |
fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF); |
|
552 | 561 |
|
553 |
if($code != 211 && $code != 214) { |
|
554 |
$this->error = |
|
555 |
array("error" => "HELP not accepted from server", |
|
556 |
"smtp_code" => $code, |
|
557 |
"smtp_msg" => substr($rply,4)); |
|
558 |
if($this->do_debug >= 1) { |
|
559 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
560 |
": " . $rply . $this->CRLF; |
|
561 |
} |
|
562 |
return false; |
|
563 |
} |
|
562 |
$rply = $this->get_lines(); |
|
563 |
$code = substr($rply,0,3); |
|
564 | 564 |
|
565 |
return $rply; |
|
565 |
if($this->do_debug >= 2) { |
|
566 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
566 | 567 |
} |
567 | 568 |
|
568 |
/** |
|
569 |
* Starts a mail transaction from the email address specified in |
|
570 |
* $from. Returns true if successful or false otherwise. If True |
|
571 |
* the mail transaction is started and then one or more Recipient |
|
572 |
* commands may be called followed by a Data command. |
|
573 |
* |
|
574 |
* Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF> |
|
575 |
* |
|
576 |
* SMTP CODE SUCCESS: 250 |
|
577 |
* SMTP CODE SUCCESS: 552,451,452 |
|
578 |
* SMTP CODE SUCCESS: 500,501,421 |
|
579 |
* @access public |
|
580 |
* @return bool |
|
581 |
*/ |
|
582 |
function Mail($from) { |
|
583 |
$this->error = null; # so no confusion is caused |
|
569 |
if($code != 211 && $code != 214) { |
|
570 |
$this->error = |
|
571 |
array("error" => "HELP not accepted from server", |
|
572 |
"smtp_code" => $code, |
|
573 |
"smtp_msg" => substr($rply,4)); |
|
574 |
if($this->do_debug >= 1) { |
|
575 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
576 |
": " . $rply . $this->CRLF; |
|
577 |
} |
|
578 |
return false; |
|
579 |
} |
|
584 | 580 |
|
585 |
if(!$this->connected()) { |
|
586 |
$this->error = array( |
|
587 |
"error" => "Called Mail() without being connected"); |
|
588 |
return false; |
|
589 |
} |
|
581 |
return $rply; |
|
582 |
} |
|
590 | 583 |
|
591 |
fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $this->CRLF); |
|
584 |
/** |
|
585 |
* Starts a mail transaction from the email address specified in |
|
586 |
* $from. Returns true if successful or false otherwise. If True |
|
587 |
* the mail transaction is started and then one or more Recipient |
|
588 |
* commands may be called followed by a Data command. |
|
589 |
* |
|
590 |
* Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF> |
|
591 |
* |
|
592 |
* SMTP CODE SUCCESS: 250 |
|
593 |
* SMTP CODE SUCCESS: 552,451,452 |
|
594 |
* SMTP CODE SUCCESS: 500,501,421 |
|
595 |
* @access public |
|
596 |
* @return bool |
|
597 |
*/ |
|
598 |
function Mail($from) { |
|
599 |
$this->error = null; # so no confusion is caused |
|
592 | 600 |
|
593 |
$rply = $this->get_lines(); |
|
594 |
$code = substr($rply,0,3); |
|
601 |
if(!$this->connected()) { |
|
602 |
$this->error = array( |
|
603 |
"error" => "Called Mail() without being connected"); |
|
604 |
return false; |
|
605 |
} |
|
595 | 606 |
|
596 |
if($this->do_debug >= 2) { |
|
597 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
598 |
} |
|
607 |
$useVerp = ($this->do_verp ? "XVERP" : ""); |
|
608 |
fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); |
|
599 | 609 |
|
600 |
if($code != 250) { |
|
601 |
$this->error = |
|
602 |
array("error" => "MAIL not accepted from server", |
|
603 |
"smtp_code" => $code, |
|
604 |
"smtp_msg" => substr($rply,4)); |
|
605 |
if($this->do_debug >= 1) { |
|
606 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
607 |
": " . $rply . $this->CRLF; |
|
608 |
} |
|
609 |
return false; |
|
610 |
} |
|
611 |
return true; |
|
610 |
$rply = $this->get_lines(); |
|
611 |
$code = substr($rply,0,3); |
|
612 |
|
|
613 |
if($this->do_debug >= 2) { |
|
614 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
612 | 615 |
} |
613 | 616 |
|
614 |
/** |
|
615 |
* Sends the command NOOP to the SMTP server. |
|
616 |
* |
|
617 |
* Implements from rfc 821: NOOP <CRLF> |
|
618 |
* |
|
619 |
* SMTP CODE SUCCESS: 250 |
|
620 |
* SMTP CODE ERROR : 500, 421 |
|
621 |
* @access public |
|
622 |
* @return bool |
|
623 |
*/ |
|
624 |
function Noop() { |
|
625 |
$this->error = null; # so no confusion is caused |
|
617 |
if($code != 250) { |
|
618 |
$this->error = |
|
619 |
array("error" => "MAIL not accepted from server", |
|
620 |
"smtp_code" => $code, |
|
621 |
"smtp_msg" => substr($rply,4)); |
|
622 |
if($this->do_debug >= 1) { |
|
623 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
624 |
": " . $rply . $this->CRLF; |
|
625 |
} |
|
626 |
return false; |
|
627 |
} |
|
628 |
return true; |
|
629 |
} |
|
626 | 630 |
|
627 |
if(!$this->connected()) { |
|
628 |
$this->error = array( |
|
629 |
"error" => "Called Noop() without being connected"); |
|
630 |
return false; |
|
631 |
} |
|
631 |
/** |
|
632 |
* Sends the command NOOP to the SMTP server. |
|
633 |
* |
|
634 |
* Implements from rfc 821: NOOP <CRLF> |
|
635 |
* |
|
636 |
* SMTP CODE SUCCESS: 250 |
|
637 |
* SMTP CODE ERROR : 500, 421 |
|
638 |
* @access public |
|
639 |
* @return bool |
|
640 |
*/ |
|
641 |
function Noop() { |
|
642 |
$this->error = null; # so no confusion is caused |
|
632 | 643 |
|
633 |
fputs($this->smtp_conn,"NOOP" . $this->CRLF); |
|
644 |
if(!$this->connected()) { |
|
645 |
$this->error = array( |
|
646 |
"error" => "Called Noop() without being connected"); |
|
647 |
return false; |
|
648 |
} |
|
634 | 649 |
|
635 |
$rply = $this->get_lines(); |
|
636 |
$code = substr($rply,0,3); |
|
650 |
fputs($this->smtp_conn,"NOOP" . $this->CRLF); |
|
637 | 651 |
|
638 |
if($this->do_debug >= 2) { |
|
639 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
640 |
} |
|
652 |
$rply = $this->get_lines(); |
|
653 |
$code = substr($rply,0,3); |
|
641 | 654 |
|
642 |
if($code != 250) { |
|
643 |
$this->error = |
|
644 |
array("error" => "NOOP not accepted from server", |
|
645 |
"smtp_code" => $code, |
|
646 |
"smtp_msg" => substr($rply,4)); |
|
647 |
if($this->do_debug >= 1) { |
|
648 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
649 |
": " . $rply . $this->CRLF; |
|
650 |
} |
|
651 |
return false; |
|
652 |
} |
|
653 |
return true; |
|
655 |
if($this->do_debug >= 2) { |
|
656 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
654 | 657 |
} |
655 | 658 |
|
656 |
/**
|
|
657 |
* Sends the quit command to the server and then closes the socket
|
|
658 |
* if there is no error or the $close_on_error argument is true.
|
|
659 |
*
|
|
660 |
* Implements from rfc 821: QUIT <CRLF>
|
|
661 |
*
|
|
662 |
* SMTP CODE SUCCESS: 221
|
|
663 |
* SMTP CODE ERROR : 500
|
|
664 |
* @access public
|
|
665 |
* @return bool
|
|
666 |
*/
|
|
667 |
function Quit($close_on_error=true) {
|
|
668 |
$this->error = null; # so there is no confusion
|
|
659 |
if($code != 250) {
|
|
660 |
$this->error =
|
|
661 |
array("error" => "NOOP not accepted from server",
|
|
662 |
"smtp_code" => $code,
|
|
663 |
"smtp_msg" => substr($rply,4));
|
|
664 |
if($this->do_debug >= 1) {
|
|
665 |
echo "SMTP -> ERROR: " . $this->error["error"] .
|
|
666 |
": " . $rply . $this->CRLF;
|
|
667 |
}
|
|
668 |
return false;
|
|
669 |
}
|
|
670 |
return true;
|
|
671 |
}
|
|
669 | 672 |
|
670 |
if(!$this->connected()) { |
|
671 |
$this->error = array( |
|
672 |
"error" => "Called Quit() without being connected"); |
|
673 |
return false; |
|
674 |
} |
|
673 |
/** |
|
674 |
* Sends the quit command to the server and then closes the socket |
|
675 |
* if there is no error or the $close_on_error argument is true. |
|
676 |
* |
|
677 |
* Implements from rfc 821: QUIT <CRLF> |
|
678 |
* |
|
679 |
* SMTP CODE SUCCESS: 221 |
|
680 |
* SMTP CODE ERROR : 500 |
|
681 |
* @access public |
|
682 |
* @return bool |
|
683 |
*/ |
|
684 |
function Quit($close_on_error=true) { |
|
685 |
$this->error = null; # so there is no confusion |
|
675 | 686 |
|
676 |
# send the quit command to the server |
|
677 |
fputs($this->smtp_conn,"quit" . $this->CRLF); |
|
687 |
if(!$this->connected()) { |
|
688 |
$this->error = array( |
|
689 |
"error" => "Called Quit() without being connected"); |
|
690 |
return false; |
|
691 |
} |
|
678 | 692 |
|
679 |
# get any good-bye messages
|
|
680 |
$byemsg = $this->get_lines();
|
|
693 |
# send the quit command to the server
|
|
694 |
fputs($this->smtp_conn,"quit" . $this->CRLF);
|
|
681 | 695 |
|
682 |
if($this->do_debug >= 2) { |
|
683 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg; |
|
684 |
} |
|
696 |
# get any good-bye messages |
|
697 |
$byemsg = $this->get_lines(); |
|
685 | 698 |
|
686 |
$rval = true; |
|
687 |
$e = null; |
|
699 |
if($this->do_debug >= 2) { |
|
700 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg; |
|
701 |
} |
|
688 | 702 |
|
689 |
$code = substr($byemsg,0,3); |
|
690 |
if($code != 221) { |
|
691 |
# use e as a tmp var cause Close will overwrite $this->error |
|
692 |
$e = array("error" => "SMTP server rejected quit command", |
|
693 |
"smtp_code" => $code, |
|
694 |
"smtp_rply" => substr($byemsg,4)); |
|
695 |
$rval = false; |
|
696 |
if($this->do_debug >= 1) { |
|
697 |
echo "SMTP -> ERROR: " . $e["error"] . ": " . |
|
698 |
$byemsg . $this->CRLF; |
|
699 |
} |
|
700 |
} |
|
703 |
$rval = true; |
|
704 |
$e = null; |
|
701 | 705 |
|
702 |
if(empty($e) || $close_on_error) { |
|
703 |
$this->Close(); |
|
704 |
} |
|
706 |
$code = substr($byemsg,0,3); |
|
707 |
if($code != 221) { |
|
708 |
# use e as a tmp var cause Close will overwrite $this->error |
|
709 |
$e = array("error" => "SMTP server rejected quit command", |
|
710 |
"smtp_code" => $code, |
|
711 |
"smtp_rply" => substr($byemsg,4)); |
|
712 |
$rval = false; |
|
713 |
if($this->do_debug >= 1) { |
|
714 |
echo "SMTP -> ERROR: " . $e["error"] . ": " . |
|
715 |
$byemsg . $this->CRLF; |
|
716 |
} |
|
717 |
} |
|
705 | 718 |
|
706 |
return $rval; |
|
719 |
if(empty($e) || $close_on_error) { |
|
720 |
$this->Close(); |
|
707 | 721 |
} |
708 | 722 |
|
709 |
/** |
|
710 |
* Sends the command RCPT to the SMTP server with the TO: argument of $to. |
|
711 |
* Returns true if the recipient was accepted false if it was rejected. |
|
712 |
* |
|
713 |
* Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF> |
|
714 |
* |
|
715 |
* SMTP CODE SUCCESS: 250,251 |
|
716 |
* SMTP CODE FAILURE: 550,551,552,553,450,451,452 |
|
717 |
* SMTP CODE ERROR : 500,501,503,421 |
|
718 |
* @access public |
|
719 |
* @return bool |
|
720 |
*/ |
|
721 |
function Recipient($to) { |
|
722 |
$this->error = null; # so no confusion is caused |
|
723 |
return $rval; |
|
724 |
} |
|
723 | 725 |
|
724 |
if(!$this->connected()) { |
|
725 |
$this->error = array( |
|
726 |
"error" => "Called Recipient() without being connected"); |
|
727 |
return false; |
|
728 |
} |
|
726 |
/** |
|
727 |
* Sends the command RCPT to the SMTP server with the TO: argument of $to. |
|
728 |
* Returns true if the recipient was accepted false if it was rejected. |
|
729 |
* |
|
730 |
* Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF> |
|
731 |
* |
|
732 |
* SMTP CODE SUCCESS: 250,251 |
|
733 |
* SMTP CODE FAILURE: 550,551,552,553,450,451,452 |
|
734 |
* SMTP CODE ERROR : 500,501,503,421 |
|
735 |
* @access public |
|
736 |
* @return bool |
|
737 |
*/ |
|
738 |
function Recipient($to) { |
|
739 |
$this->error = null; # so no confusion is caused |
|
729 | 740 |
|
730 |
fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|
741 |
if(!$this->connected()) { |
|
742 |
$this->error = array( |
|
743 |
"error" => "Called Recipient() without being connected"); |
|
744 |
return false; |
|
745 |
} |
|
731 | 746 |
|
732 |
$rply = $this->get_lines(); |
|
733 |
$code = substr($rply,0,3); |
|
747 |
fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|
734 | 748 |
|
735 |
if($this->do_debug >= 2) { |
|
736 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
737 |
} |
|
749 |
$rply = $this->get_lines(); |
|
750 |
$code = substr($rply,0,3); |
|
738 | 751 |
|
739 |
if($code != 250 && $code != 251) { |
|
740 |
$this->error = |
|
741 |
array("error" => "RCPT not accepted from server", |
|
742 |
"smtp_code" => $code, |
|
743 |
"smtp_msg" => substr($rply,4)); |
|
744 |
if($this->do_debug >= 1) { |
|
745 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
746 |
": " . $rply . $this->CRLF; |
|
747 |
} |
|
748 |
return false; |
|
749 |
} |
|
750 |
return true; |
|
752 |
if($this->do_debug >= 2) { |
|
753 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
751 | 754 |
} |
752 | 755 |
|
753 |
/** |
|
754 |
* Sends the RSET command to abort and transaction that is |
|
755 |
* currently in progress. Returns true if successful false |
|
756 |
* otherwise. |
|
757 |
* |
|
758 |
* Implements rfc 821: RSET <CRLF> |
|
759 |
* |
|
760 |
* SMTP CODE SUCCESS: 250 |
|
761 |
* SMTP CODE ERROR : 500,501,504,421 |
|
762 |
* @access public |
|
763 |
* @return bool |
|
764 |
*/ |
|
765 |
function Reset() { |
|
766 |
$this->error = null; # so no confusion is caused |
|
756 |
if($code != 250 && $code != 251) { |
|
757 |
$this->error = |
|
758 |
array("error" => "RCPT not accepted from server", |
|
759 |
"smtp_code" => $code, |
|
760 |
"smtp_msg" => substr($rply,4)); |
|
761 |
if($this->do_debug >= 1) { |
|
762 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
763 |
": " . $rply . $this->CRLF; |
|
764 |
} |
|
765 |
return false; |
|
766 |
} |
|
767 |
return true; |
|
768 |
} |
|
767 | 769 |
|
768 |
if(!$this->connected()) { |
|
769 |
$this->error = array( |
|
770 |
"error" => "Called Reset() without being connected"); |
|
771 |
return false; |
|
772 |
} |
|
770 |
/** |
|
771 |
* Sends the RSET command to abort and transaction that is |
|
772 |
* currently in progress. Returns true if successful false |
|
773 |
* otherwise. |
|
774 |
* |
|
775 |
* Implements rfc 821: RSET <CRLF> |
|
776 |
* |
|
777 |
* SMTP CODE SUCCESS: 250 |
|
778 |
* SMTP CODE ERROR : 500,501,504,421 |
|
779 |
* @access public |
|
780 |
* @return bool |
|
781 |
*/ |
|
782 |
function Reset() { |
|
783 |
$this->error = null; # so no confusion is caused |
|
773 | 784 |
|
774 |
fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|
785 |
if(!$this->connected()) { |
|
786 |
$this->error = array( |
|
787 |
"error" => "Called Reset() without being connected"); |
|
788 |
return false; |
|
789 |
} |
|
775 | 790 |
|
776 |
$rply = $this->get_lines(); |
|
777 |
$code = substr($rply,0,3); |
|
791 |
fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|
778 | 792 |
|
779 |
if($this->do_debug >= 2) { |
|
780 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
781 |
} |
|
793 |
$rply = $this->get_lines(); |
|
794 |
$code = substr($rply,0,3); |
|
782 | 795 |
|
783 |
if($code != 250) { |
|
784 |
$this->error = |
|
785 |
array("error" => "RSET failed", |
|
786 |
"smtp_code" => $code, |
|
787 |
"smtp_msg" => substr($rply,4)); |
|
788 |
if($this->do_debug >= 1) { |
|
789 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
790 |
": " . $rply . $this->CRLF; |
|
791 |
} |
|
792 |
return false; |
|
793 |
} |
|
796 |
if($this->do_debug >= 2) { |
|
797 |
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
798 |
} |
|
794 | 799 |
|
795 |
return true; |
|
800 |
if($code != 250) { |
|
801 |
$this->error = |
|
802 |
array("error" => "RSET failed", |
|
803 |
"smtp_code" => $code, |
|
804 |
"smtp_msg" => substr($rply,4)); |
|
805 |
if($this->do_debug >= 1) { |
|
806 |
echo "SMTP -> ERROR: " . $this->error["error"] . |
|
807 |
": " . $rply . $this->CRLF; |
|
808 |
} |
|
809 |
return false; |
|
796 | 810 |
} |
797 | 811 |
|
798 |
/** |
|
799 |
* Starts a mail transaction from the email address specified in |
|
800 |
* $from. Returns true if successful or false otherwise. If True |
|
801 |
* the mail transaction is started and then one or more Recipient |
|
802 |
* commands may be called followed by a Data command. This command |
|
803 |
* will send the message to the users terminal if they are logged |
|
804 |
* in. |
|
805 |
* |
|
806 |
* Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF> |
|
807 |
* |
|
808 |
* SMTP CODE SUCCESS: 250 |
|
809 |
* SMTP CODE SUCCESS: 552,451,452 |
|
810 |
* SMTP CODE SUCCESS: 500,501,502,421 |
|
811 |
* @access public |
|
812 |
* @return bool |
|
813 |
*/ |
|
814 |
function Send($from) { |
|
815 |
$this->error = null; # so no confusion is caused |
|
812 |
return true; |
|
813 |
} |
|
816 | 814 |
|
817 |
if(!$this->connected()) { |
|
818 |
$this->error = array( |
Also available in: Unified diff
updated PHPMailer framework to version 2.0.0 (/include/phpmailer)