PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
error_reporting(E_ALL);
ob_implicit_flush();
$service_port = getservbyname('smtp', 'tcp');
$address = gethostbyname('smtp.gmail.com');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
while ($msg = socket_read($socket, 2048)) {
echo $msg;
}
echo "Done...";
?>
If you havn't guessed I'm trying to connect to an smtp server. The code works fine, it connects, and the SMTP server responds correctly, the only problem is the while loop will not finish. When using implicit flushing I get everything printed except for the "Done..." part, which tells me the while loop will not terminate. I know this is because message is always true because it always contains content. My question is how can I tell when I have read all the content from the stream? Is there a PHP function that will tell me how many bytes are left? Thanks.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
[quote="ole"]http://php.net/manual/en/types.comparisons.php
'' is considered false already.
Do a search for the "Done..." string in the source that the script generates.[/quote]
I am confused by what you mean. The data is printed out fine..
[quote]Attempting to connect to '209.85.133.111' on port '25'...220 mx.google.com ESMTP d38sm24762106and[/quote]
That's when it stops though and my browser just keeps saying "Loading Page.." and it never finishes. I tried the following code:
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Google's smtp servers don't communicate on port 25. Last I checked they're on a secure channel only. Plus you actually have to talk to it for it to send you more.