Hi I have designed a function that will not use default php mail function instead it will use smtp connection.
It works fine in every way however when I add more than one reciepent it still works and sends the mail but in reciepent's mailbox it's(the mail's) to part seems as ARRAY but I want it to be seem like [email]sakkarin@hotmail.com;asdads@yahoo.com;ahmet@gmail.com[/email] etc...
What should i do?

Here is my code

function mymail($to,$from,$subject,$message,$headers,$usermail,$userpass)
{
  $server = "10.0.0.2";
  $port = 25;
  $username = $usermail;
  $password = $userpass;

  //Kullanıcı adı ve şifrenin base 64 unu gormeyi saglar
  //echo base64_encode($username)." ".base64_encode($password);

  global $GLOBAL;


  $cp = fsockopen ($server, $port, &$errno, &$errstr, 1);
  if (!$cp)
   return "Failed to even make a connection";
  $res=fgets($cp,256);
  if(substr($res,0,3) != "220") return "Failed to connect";


  fputs($cp, "HELO\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "250") return "Failed to Introduce";

  fputs($cp, "EHLO\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "250") return "Failed to Introduce";

   //Solaris teki ehlo mesajindan sonraki ciktilari socketten okumak icin
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);
   $res=fgets($cp,256);


  fputs($cp, "auth login\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "334") return "Failed to Initiate Authentication";


  fputs($cp, base64_encode($username)."\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "334") return "Failed to Provide Username for Authentication";

  fputs($cp, base64_encode($password)."\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "235") return "Failed to Authenticate";


  fputs($cp, "MAIL FROM:$from\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "250") return "MAIL FROM failed";



  if (count($to)>1)
  {
  	for ($i=0;$i<count($to);$i++)
  	{
  		fputs($cp, "RCPT TO: $to[$i]\r\n");
  		$res=fgets($cp,256);
  		if(substr($res,0,3) != "250") return "RCPT TO List failed";
  	}
  }
  else
  {
  		fputs($cp, "RCPT TO: $to\r\n");
  		$res=fgets($cp,256);
  		if(substr($res,0,3) != "250") return "RCPT TO failed";  	
  }


  fputs($cp, "DATA\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "354") return "DATA failed";


  fputs($cp, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "250") return "Message Body Failed";


  fputs($cp,".\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "221") return "QUIT failed ";

  return true;
}

    How about this bit ...

    <?php 
    // ...
    //WAS: fputs($cp, "To: $to\r\nFrom: $from\r\nSubject: 
    
    fputs($cp, "To: ".join(';', $to)."\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
      $res=fgets($cp,256);
      if(substr($res,0,3) != "250") return "Message Body Failed";
    
    // ... etc
    
    ?>

    P.

      Why reinvent the wheel? There are plenty of pre-made classes out there, such as PHPMailer...

        paulnaj wrote:

        How about this bit ...

        <?php 
        // ...
        //WAS: fputs($cp, "To: $to\r\nFrom: $from\r\nSubject: 
        
        fputs($cp, "To: ".join(';', $to)."\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
          $res=fgets($cp,256);
          if(substr($res,0,3) != "250") return "Message Body Failed";
        
        // ... etc
        
        ?>

        P.

        No the smtp connection doesn' t accept reciepents such as [email]sakkarin@hotmail.com;dakkar@hotmail.com[/email] ..... you have to put them one by one but when I put them one by one it shows as array in to part of email

          Hmm,

          $to is an array. If you put it in a string it will print 'Array'.

          Do you want to print 'Array' in the portion of the code I highlighted? I wouldn't imagine so.

          Paul.

          PS Just noticed another portion of your code where you do the same thing ...

          <?php
            		fputs($cp, "RCPT TO: $to\r\n");
            		$res=fgets($cp,256);
            		if(substr($res,0,3) != "250") return "RCPT TO failed";
          ?>

            no its like this

              	
              for ($i=0;$i<count($to);$i++)
              {
              	fputs($cp, "RCPT TO: ".$to[$i]."\r\n");
              	$res=fgets($cp,256);
              	if(substr($res,0,3) != "250") return "RCPT TO List failed";
              }
            

              I'll try once more ...

                if (count($to)>1)
                {
                	for ($i=0;$i<count($to);$i++)
                	{
                		fputs($cp, "RCPT TO: $to[$i]\r\n");
                		$res=fgets($cp,256);
                		if(substr($res,0,3) != "250") return "RCPT TO List failed";
                	}
                }
                else
                {
              //////////////////////////////////////////////////////////////////////////////////
                		fputs($cp, "RCPT TO: $to\r\n");
              //////////////////////////////////////////////////////////////////////////////////
                		$res=fgets($cp,256);
                		if(substr($res,0,3) != "250") return "RCPT TO failed";  	
                }
                Write a Reply...