Attachments....

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!

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Attachments....

Post by spacebiscuit »

Hi,

I am using the following code to post a message to a newsgroup....

Code: Select all

if ($fp = fsockopen($nntp_host, $nntp_port)) {
    	// Get the server response
    	200 == ($resp = fgets($fp, 1024)) or die("Unexpected response: $resp");

    	// Authenticate
    	fputs($fp, "AUTHINFO USER $user\r\n");
    	381 == ($resp = fgets($fp, 1024)) or die("Unexpected response: $resp");
    	fputs($fp, "AUTHINFO PASS $pass\r\n");
    	281 == ($resp = fgets($fp, 1024)) or die("Unexpected response: $resp");

    	// Initiate the message post
    	fputs($fp, "POST\r\n");
    	340 == ($resp = fgets($fp, 1024)) or die("Unexpected response: $resp");

    	// Send the headers
    	fputs($fp, "From: $from\r\n");
    	fputs($fp, "Subject: $subject\r\n");
    	fputs($fp, "Newsgroups: $newsgroups\r\n\r\n");
    
    	// Post the message
    	fputs($fp, "$message\r\n.\r\n");
    	if (240 == fgets($fp, 1024)){
        	print "Message posted successfully";
    				    }

    	fputs($fp, "QUIT\r\n");
    	fclose($fp);
					    }
else{
	print "Unable to connect";
    }
It works fine but I also need to be able to send binary attachments. Does anyone know how I can modify the code above to do so?

I have looked on the net and all I can come up with are 10 page classes - it must be simpler than that? I can handle the file input part, I just literally need to know how to compose the attachment and send it.

I also tried phpmailer but it does not work for newsgroups with password.

Thanks in advance,

Rob Burne.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

tried looking up the NNTP protocol?
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

it seems the nntp protocol does not support binary attachments.

I figured out that attchments have to be enccoded with uuencode to ensure compatiability with as many newsreaders as possible. PHP doesn't seem to provide any classes or functions to encode files so I had to use a stand alone application to do this and then everything worked ok.

Thanks,

Rob.
Post Reply