Issue in sending mail using php and smtp

I cant sent email using smtp and php.
I am using one form with email,subject message, etc i want to sent an email to that email (in form) while submit button click. I am givin the code bellow(only php)

 
 if(isset($_POST['Submit']))
{
 require ("req_mail.php");
        $from = "it@comradeinfosystems.com";
 $to = $_POST['TEmail'];
 $namefrom = "COMRADE";
 $nameto = "CLIENT";
        $subject = "AMC Request:$namefrom | $amc "; 
 $message  = "From: $from" . $newLine; 
        $message .= "CompanyID: $namefrom" . $newLine; 
        $message .= "Mobile No: $office" . $newLine; 
 $comments = $_POST['comments'];
 authSendEmail($from, $namefrom, $to, $nameto, $subject, $message, $comments);	 
 echo "Thanks";
}   

req_mail.php is this


function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message, $comments)
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
    $smtpServer = "mymail.brinkster.com"; 
    $port = "25"; 
    $timeout = "30"; 
    $username = "it@comradeinfosystems.com"; 
    $password = "daddycool"; 
    $localhost = "mail.brinkster.com"; 
    $newLine = "\\r\
"; 
/* * * * CONFIGURATION END * * * * */

//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect)) 
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";
}

//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";

//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";

//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";

//Say Hello to SMTP
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";

//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";

//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";

//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

fputs($smtpConnect, "To: $to\
From: $from\
Subject: $subject\
$headers\
\
$message\
\
Comments:$comments\
.\
");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";

// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine); 
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse"; 
}

Why not just use mail() ?

The mail function is probably a lot easier to use than communicating directly with an SMTP server, as tangoforce suggests.

However, if you must use SMTP (due to mail() not working or something), I’d suggest looking at a library such as PHPMailer or Swift Mailer (http://www.swiftmailer.org/). It’ll make your life a lot easier than trying to talk to the SMTP server yourself.

Lastly, you might want to remove your username and password from the code you posted above. Some people might use that info to send spam from your server! :o