Hi there,
I have been working on an SMTP class for the past hour. I'm fairly new to PHP, but I've coded the SMTP class from scratch and everything is fine, except...
When I send a command (for example "HELO localhost"), my server often responds with a response greater than one line.
I check for the first character of the response to be a 2, which indicates a successful execution on the mail server. This is all good, but when I send the next command and check for the response, fread() reads from the previous responses. I have come to the conclusion that multiple freads() just appends data to the fread() stack. And, because I only return the 1st character of the server's response, my pointer only moves 1 character at a time. I know that after each response, I need to move the pointer to the end of the returned data. However, when I use:
while (!feof($mysocket)) {
$response .= fgets($mysocket, 1024);
}
the above never ends. The loop goes on forever. I use fsockopen to open a connection to my mailserver. I have yet to find a way to go to the end of the fread() buffer. I try doing fread($mysocket, 4096) because my server never responds with more than 4096 bytes of data, but that just stalls the script again ( I guess fread() cannot find 4096 charactesr, so it stalls. I tried using 1024, but to no avail.
Could someone PLEASE help me out. This is an urgent situation, and I don't want to use another mail script. Mine has a ton of error handling in it. I'll share the script as soon as its done.
Thanks a lot.
Ara
ara@bluemediasolutions.com