Tuesday, December 8, 2009

Upload Email Refine it and save it to database

*


This post will help in copy all email id and pase it to textarea and click on upload button. Programme will automatically filter all invalid id and organize them and create group or add to exit group as u want.




<?php



$dbc=mysql_connect('localhost','userName','password');
mysql_select_db('database name',$dbc);





function gethtmlformat($txt){ //Function for RIght syntex for html format

$txt=str_replace('%0D%0A','',$txt);

$txt=str_replace('+','',$txt);

$txt=str_replace(',%20',',',$txt);

return($txt);



}



$action=$_REQUEST['act'];

$newGroup=$_REQUEST['newGroup'];

//echo $newGroup;

$oldGroup=$_REQUEST['group'];

$emailId=urlencode($_REQUEST['emailId']); //replace space with +

$emailId=urldecode(gethtmlformat($emailId));

//echo $emailId;

$EmailArray=explode(",",$emailId); //Create array of uploaded email string 

$totemail=count($EmailArray); //Count total email in arrary

//echo $totemail;

$count=0;

$Id;

$wrongId;

$group;

if(isset($action)){



if($newGroup!="" ){

$group=$newGroup;

}else{

$group=$oldGroup;

}

//echo $group.'<br>';



function chkEmail($email){

//echo $email;

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ // function will validate email id

return("Invalid");

}else{

return("Valid");

}



}

for($i=0;$i<$totemail;$i++){

//echo $i;

if(isset($EmailArray[$i])){

//echo $EmailArray[$i].'<br>';

if(chkEmail($EmailArray[$i])=="Valid"){

$Id.=$EmailArray[$i].',';

$count+=1;

//echo $Id.'<br>';

}elseif(chkEmail($EmailArray[$i])=="Invalid"){



$wrongId.=$EmailArray[$i].'<br>';

//echo $wrongId.'<br>';

}

}

//echo chkEmail($EmailArray[$i]);

}

//echo $Id;

//****************************start Get New ID for News letter to send*****************



$selMaxId="select max(id) from emailgroup";

$result=mysql_query($selMaxId,$dbc)or die('Error in Fetch Id'.mysql_error());

$rs=mysql_fetch_row($result);

$groupId=$rs[0];

$newgroupId=$groupId+1;



//*******************************End get New ID for Greeting ********************



//******************************Check Group Exit or not************

function chkGroup($value,$dbc){

$chk="select group_name,emailid from emailgroup where group_name='$value'";

$chkRs=mysql_query($chk,$dbc) or die('error in group:-'.mysql_error());

$value1=mysql_fetch_row($chkRs);

//echo $value.$value1[1].'<br>';

return($value1[1]);



}





//*************************************************





if($Id!=""){

$insertEmail="insert into emailgroup values($newgroupId,'$group','$Id','y',$count)";
if(mysql_query($insertEmail,$dbc)){

echo '<div class="success">Email Uploaded</div>';

}else{

echo '<div class="error">Email Uploaded Fail</div>';



}

}

if($wrongId!=""){echo '<div class="error">Wrong Email Id:-'.$wrongId.'</div>';}



}



?>

<body>



<center>

<table width="80%" border="1">

<tr>

<td colspan="2" align="center" ><img src="http://www.totalbhakti.com/wallpaper/images/logo.png" border="0"></td>

</tr>

<tr>

<td width="20%" valign="middle">

<?php include('left.php');?>

</td>

<td>



<fieldset>

<legend>Email Id Upload Panel</legend>

<form name="emailform" action="emailUpload.php" method="post">

<table width="95%" cellpadding="0" cellspacing="0" border="1">

<tr>

<td width="30%"><strong>Select Email Group</strong></td>

<td >

<select name="group" id="group" onchange="selectionShow(document.getElementById('group'),'New',document.getElementById('newGroup1'))" >

<option>General</option>

<?php









$selectGroup="select group_name from emailgroup group by group_name";

$result=mysql_query($selectGroup,$dbc) or die('error in group:-'.mysql_error());

while($row=mysql_fetch_row($result)){



echo'<option>'.$row[0].'</option>';



}



?>









<option>New</option>



</select>



</td>

</tr>

<tr id="newGroup1" style="visibility:hidden">

<td align="right">

<strong>Enter New Group</strong>

</td>

<td>

<input type="text" name="newGroup" id="newGroup" >

</td>



</tr>

<tr >



<td colspan="2" id="errorGroup" style="visibility:hidden">



</td>



</tr>

<tr>

<td align="left">

<strong>Enter Email Id's</strong>

</td>

<td>

<textarea name="emailId" id="emailId" cols="40" rows="10" ></textarea>

</td>



</tr>



<tr >



<td colspan="2" id="errorId" style="visibility:hidden">



</td>



</tr>



<tr >

<td align="right">

<input type="hidden" name="act" value="true" />

</td>

<td>

<input type="button" value="Upload" onclick="onSubmited(emailform)" >

</td>



</tr>

</table>

</form>

</fieldset>

</td>

</tr>

</table>

1 comment:

  1. if u need any help on any php porblem plz email ur problem to me on cyberomkarmca1@gmail.com

    ReplyDelete