thx in advance for any help on this. I've created an email invite form but the code won't let you sent the invite unless the form starts with a comma. Commas are used in the code to separate email addresses but I can't seem to figure out how to send the form without first having a comma. Here is the code. Many thanks.
//if
else{
global $main_url;
//getting values
$emails=form_get("emails");
$subject=form_get("subject");
$mes=form_get("mes");
$emails=ereg_replace("\r","",$emails);
$emails=ereg_replace("\n","",$emails);
$emails=ereg_replace(" ","",$emails);
$email=",".$email;
$email=split(",",$emails);
$email=if_empty($email);
$data[0]=$subject;
$now=time();
if($email!=''){
show_header();
echo "<table width=100% class='body'>
<tr><td class='lined title'>Invitation</td>
<tr><td class='lined'>";
foreach($email as $addr){
//if user is site member - standart invitation
$sql_query2="select mem_id from members where email='$addr'";
$num=sql_execute($sql_query2,'num');
if($num!=0){
$fr=sql_execute($sql_query2,'get');
$sql_query="select mem_id from network where mem_id='$m_id' and frd_id='$fr->mem_id'";
$num2=sql_execute($sql_query,'num');
$sql_query="select mes_id from messages_system where
(mem_id='$m_id' and frm_id='$fr->mem_id' and type='friend') or
(mem_id='$fr->mem_id' and frm_id='$m_id' and type='friend')";
$num=sql_execute($sql_query,'num');
if($m_id==$fr->mem_id){
echo "$addr: you can't invite yourself!</br>";
}//if
elseif($num>0){
echo "$addr - you already invited this user.</br>";
}//elseif
elseif($num2>0){
echo "$addr - this user is already your friend.</br>";
}//elseif
else {
$subj="Invitation to Join ".name_header($m_id,$fr->mem_id)."\'s Personal Network";
$bod="After you push \"Confirm\" button user ".name_header($m_id,$fr->mem_id).
" will be added to your friends network.";
$sql_query="insert into messages_system(mem_id,frm_id,subject,body,type,folder,date)
values('$fr->mem_id','$m_id','$subj','$bod','friend','inbox','$now')";
sql_execute($sql_query,'');
echo "$addr: Invitation is sent.</br>";
}//else
}//if a user
else {
//if user is not site member - just sending email
$sql_query="insert into invitations (mem_id,email,date) values ('$m_id','$addr','$now')";
sql_execute($sql_query,'');
$sql_query="select max(inv_id) as maxid from invitations";
$max=sql_execute($sql_query,'get');
$data[1]=$mes."
<a href='$main_url'>$main_url</a></br>
<a href='$main_url/index.php?mode=join&inv_id=$max->maxid'>$main_url/index.php?mode=join&inv_id=$max->maxid</a>";
$data[2]=name_header($m_id,"ad");
$sql_query="select email from members where mem_id='$m_id'";
$k=sql_execute($sql_query,'get');
$data[3]=$k->email;
messages($addr,"6",$data);
echo "$addr: Invitation is sent.</br>";
}//else
}//foreach
echo "</td></table>";
}//if
else {
error_screen(3);
}//else
}//else
}//function