fsockopen emailing
hi, i have altered a script i had made that sends emails through fsockopen to include the use of attachments. But it errors and i dont know why because the fread reaches max execution time, could someone tell me what im doing wrong... Here is the script
PHP Code:
<?php
$random_hash = md5 ( date ( 'r' , time ()));
$from_email = $_POST [ 'from_email' ];
$to_email = $_POST [ 'to_email' ];
$from_name = $_POST [ 'from_name' ];
$subject = $_POST [ 'subject' ];
$body = $_POST [ 'body' ];
$headers []= "HELO its_me" ;
$headers []= "MAIL FROM: { $from_email } " ;
$headers []= "RCPT TO: { $from_email } " ;
$headers []= "DATA" ;
$headers []= "Received: from you.com by me.com ; Thu, 03 Jan 2006 12:33:29 -0700" ;
$headers []= "Date: Thu, 03 Jan 2006 12:33:22 -0700" ;
$headers []= "From: { $from_name } < { $from_email } >" ;
$headers []= "Subject: { $subject } " ;
$headers []= "To: { $to_email } " ;
$headers []= "Content-Type: multipart/mixed; boundary=' $random_hash '" ;
$content []= 'Content-Type: text/html' ;
$content []= '' ;
$content []= $body ;
$content []= "--" . $random_hash ;
if (isset( $_FILEs [ 'uploaded' ])){
if ( $_FILEs [ 'uploaded' ][ 'error' ]== 0 ){
$content []= 'Content-Type: text/html; charset=US-ASCII; name="alert.html"' ;
$content []= 'Content-Disposition: attachment; filename="alert.html"' ;
$content []= 'Content-Transfer-Encoding: base64' ;
$content []= "" ;
}}
$content []= '.\r\nQUIT\r\n' ;
$smtp_server = fsockopen ( "the mailservers hostname" , 25 , $errno , $errstr , 30 );
foreach( $headers as $i ){
fwrite ( $smtp_server , $i . "\r\n" );
}
foreach ( $content as $i ){
fwrite ( $smtp_server , $i . "\r\n" );}
while(! feof ( $smtp_server )){
$data = fread ( $smtp_server , '1026' );
echo "<pre>" . $data . "</pre>" ;}
fclose ( $smtp_server );
?>