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;
}