Hello Friends, In this blog post, I am going to explain how to remove duplicate email addresses from CSV files, generally, email marketer needs this service very much to clean their email list…
….when you want bulk emails in your CSV file and you want to remove all the duplicate emails from your CSV file then this blog post…
…will let you know to develop the same functionality using HTML and PHP. Here in this blog, we will explore How to remove duplicate email addresses from a list. How do I delete duplicates in CSV?…..
…..How do you remove the duplicate values in Excel but keep one? How do I find duplicates in a CSV file? Remove duplicate entries in the CSV file, Find duplicate values in the CSV file, and Remove Duplicates from CSV Excel.
What are the disadvantages of duplicate email addresses in CSV?
There are various disadvantages to having duplicate email addresses in CSV files.
In the case of fewer validations emails will be sent twice and more to the same email address and this can create a problem for our reputation and can also cause irritation for our users or clients as they will receive the same email multiple times.
Few ESP have restrictions on the number of emails as they allow to send the campaign on an email basis. So this could be a bigger disadvantage for us in case of more and more duplicate email addresses.
for example, if we have an email list of 100 users and we have taken a plan for 100 emails. Now let’s assume we have 50 duplicate email contacts then it will be a waste of 50 emails for us as they are duplicate contacts and emails are also sent twice to these duplicate email addresses.
So this would create a problem for us. So it is very important to remove all the duplicate emails from our email lists.
What is the procedure to remove these duplicate email addresses? / How do you remove duplicate values in Excel but keep one?
this is a very simple procedure, you just need to follow the below-given procedure.
The benefit of this script code will be that you can also upload the CSV file along with a manual copy and paste of the emails. And after removing the duplicate email addresses you can download them to a CSV file.
1. You just have to install these software applications to develop this functionality to remove duplicate email addresses.
Software needed for developing this application are :
NetBeans IDE.
Xampp Server.
2. Open your NetBeans IDE and start the Apache server with the help of your Xampp control panel. Then create a project with an appropriate name. See the file hierarchical structure of the source files below.
3. now copy and paste the below code into the appropriate files and then run the product.
index.php:
[code]
<?php
session_start();
ini_set("display_errors", 0);
?>
<html>
<head>
<meta HTTP-equiv="Content-Type" content="text/Html; charset=windows-1252">
<link href="style.css" rel="stylesheet" type="text/CSS"/>
<link href="bootstrap/css/bootstrap.css" rel="stylesheet" type="text/CSS"/>
<link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" type="text/CSS"/>
<title>Remove Duplicate Email Addresses Using PHP</title>
</head>
<body>
<div class="container">
<div class="row">
<h1 class="main_heading">Remove Duplicate Email Addresses Using PHP</h1>
<div id="main">
<div id="login">
<h2>Duplicate Email Remover</h2>
<hr>
<div id="right">
<div id ="form1" >
<form method="post" action ="" id="Ctform">
<label><b>Enter Email :</b></label>
<input type="email" multiple rows="3" id ="text1" name ="email"/>
<input type="submit" id ="Dsubmit" value ="submit" name ="Dsubmit" />
</form>
<b id="or">OR</b>
<form action="<?PHP echo $_SERVER["PHP_SELF"]; ?>" method="post" enctype="multipart/form-data">
<label><b>Upload CSV :</b></label>
<label><input type="file" name="file" id="file" /></label>
<input type="submit" name="Csubmit" id="Csubmit" value="submit"/>
</form>
</div>
</div>
</div>
</div>
<div id="Csvmailcontent">
<?php
try {
if (ISSET($_POST['Dsubmit'])) {
$email = $_POST['email'];
$semail = "$email";
$arr = split(',', $semail);
$array = array_unique($arr);
$array2[] = $array;
$lists = json_encode($array2);
if (!empty($email)) {
echo"<table id ='Tid' >";
echo"<th>";
echo"<b>";
echo"Result Emails";
echo"</b>";
echo"</th>";
for each ($array2 as $key1) {
for each ($key1 as $key2) {
echo"<tr>";
echo"<td>";
echo $key2 . "<br/>";
echo"</td>";
echo"</tr>";
}
} echo"</table>";
echo"<form action='emaildown.php' method='post' >
<input type='hidden' name='lists' value='$lists' id ='lists' />
<button type='submit' value='Export CSV' id ='mailsubmit'><u>Export CSV</u></button>
</form>";
} else {
echo "<script type='text/javascript'>alert('Please Enter the Emails')</script>";
}
}
} catch (MyException $e) {
echo "Something went wrong";
}
?>
<?php
try {
if (isset($_POST['csubmit'])) {
if (isset($_FILES["file"])) {
//if there was an error uploading the file
if ($_FILES["file"] ["error"] > 0) {
echo "<script type='text/javascript'>alert('Please choose File for upload')</script>";
} else {
$storagename = $_FILES["file"]["name"];
$_SESSION['file_name'] = $storagename;
$id = $_SESSION['file_name'];
$row = 1;
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $storagename);
$file = new SplFileObject("upload/" . $storagename);
$file->setFlags(SplFileObject::READ_CSV);
$file->setCsvControl(',', '"', '\\'); // this is the default anyway though
for each ($file as $value) {
for each ($value as $row) {
$arcsv[] = $row;
}
}
$arcsv = array_unique($arcsv);
$_SESSION['csv_value'] = $arcsv;
if (empty($arcsv)) {
$arcsv = $_SESSION['csv_value'];
}
echo"<table id ='tid'>";
echo"<th>";
echo"<b>";
echo"Result Emails";
echo"</b>";
echo"</th>";
for each ($arcsv as $key) {
echo"<tr>";
echo"<td>";
echo $key. "<br/>";
echo"</td>";
echo"</tr>";
}
echo"</table>";
$arcsv1[] = $arcsv;
$lists1 = json_encode($arcsv1);
}
}
if (!empty($file)) {
echo"<form action='csvdown.php' method='post' >
<input type='hidden' name='lists1' value='$lists1' />
<button type='submit' value='Export CSV' id ='csvsubmit'><u>Export CSV<u></button>
</form>";
}
}
} catch (MyException $e) {
echo "Something went wrong";
}
?></div>
</div>
</div>
</body>
</html>
[/code]
csvdown.php:
[code]
<?php
ini_set("display_errors", 0);
?>
<?php
try {
$array2 = json_decode($_POST['lists1']);
for each ($array2 as $key) {
for each ($key as $key1) {
$array3[][] = $key1;
}
}
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
$data = $array3;
$file = fopen('php://output', 'w');
fputcsv($file, array('Emails '));
foreach ($data as $row) {
fputcsv($file, $row);
}
exit();
} catch (MyException $e) {
echo "Something went wrong";
}
?>
[/code]
emaildown.php:
[code]
<?php
ini_set("display_errors", 0);
?>
<?php
try {
$array2 = json_decode($_POST['lists']);
for each ($array2 as $key) {
for each ($key as $key1) {
$array3[][] = $key1;
}
}
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
$data = $array3;
$file = fopen('php://output', 'w');
fputcsv($file, array('Emails '));
foreach ($data as $row) {
fputcsv($file, $row, ',');
}
exit();
} catch (MyException $e) {
echo "Something went wrong";
}
?>
[/code]
style.css:
[code css]
@import URL(http://fonts.googleapis.com/css?family=Raleway);
#main{
min-width: 350px;
margin: 44px auto;
font-family: railway;
}
span{
color: red;
}
h1.main_heading {
text-align: center;
}
h2{
background-color: #FEFFED;
text-align: center;
border-radius: 10px 10px 0 0;
margin: -10px -40px;
padding: 15px;
}
hr{
border:0;
border-bottom:1px solid #ccc;
margin: 10px -40px;
margin-bottom: 30px;
}
#login{
border-radius: 10px;
font-family: railway;
border: 2px solid #ccc;
padding: 10px 40px 33px;
margin-top: 23px;
}
input[type=text],input[type=email]{
width:99.5%;
padding: 10px;
border: 1px solid #ccc;
padding-left: 5px;
font-size: 16px;
font-family: railway;
}
input[type=submit]{
width: 37%;
background-color:#FFBC00;
color: white;
border: 2px solid #FFCB00;
padding: 4px;
font-size:20px;
cursor: pointer;
border-radius: 5px;
}
#right{
overflow: hidden;
overflow-wrap: break-word;
width: 104%;
border: 1px dashed RGB(215, 215, 215);
box-shadow: 0px 5px 17px 1px #99A3AD, 0px 0px 40px #EEEEEE;
margin-left: -10%;
padding: 20px;
}
#right p{
padding: 20px;
}
form1 {
padding-top: 27px;
width: 248px;
margin: auto;
}
#right h3 {
margin-top: -8px;
text-align: center;
}
#csvmailcontent{
width:60%px;
font-family: railway;
margin-top: -4%;
}
#mailsubmit{
background: none! important;
border: none;
padding:0!important;
font: inherit;
border-bottom:1px solid #444;
cursor: pointer;
font-size: 150%;
margin-left: 45%;
}
#csvsubmit{
background: none! important;
border: none;
padding:0!important;
font: inherit;
border-bottom:1px solid #444;
cursor: pointer;
font-size: 150%;
margin-left: 45%;
}
#uploadcsv
{
margin-bottom: 5%;
}
#text1{
margin-top: 1%;
margin-bottom: 11px;
}
input#text1 {}
#or{
margin-left: 45%;
font-size: 20px;
font-family: railway;
margin-top: -50px;
}
#or: hover{
color: #204d74;
z-index: 8;
}
#file{
color: light blue;
margin-top: 3px;
margin-bottom: 4px;
}
table {
font-family: 'Raleway', sans-serif;
color:#666;
font-size:12px;
text-shadow: 1px 1px 0px #fff;
background:#eaebec;
margin:20px;
border:#ccc 1px solid;
font-size: 16px;
-moz-border-radius:3px;
-WebKit-border-radius:3px;
border-radius:3px;
-moz-box-shadow: 0 1px 2px #d1d1d1;
-webkit-box-shadow: 0 1px 2px #d1d1d1;
box-shadow: 0 1px 2px #d1d1d1;
margin: 0 auto;
}
table th {
text-align: center;
padding:21px 25px 22px 25px;
border-top:1px solid #fafafa;
border-bottom:1px solid #e0e0e0;
background: #ededed;
background: -webkit-gradient(linear, left top, left bottom, from(#ededed), to(#ebebeb));
background: -moz-linear-gradient(top, #ededed, #ebebeb);
}
table th:first-child {
text-indent: center;
padding-left:20px;
}
table tr:first-child th:first-child {
-moz-border-radius-topleft:3px;
-WebKit-border-top-left-radius:3px;
border-top-left-radius:3px;
}
table tr:first-child th:last-child {
-moz-border-radius-topright:3px;
-WebKit-border-top-right-radius:3px;
border-top-right-radius:3px;
}
table tr {
text-indent: center;
padding-left:20px;
}
table td:first-child {
text-align: center;
padding-left:20px;
border-left: 0;
}
table td {
padding:18px;
border-top: 1px solid #ffffff;
border-bottom:1px solid #e0e0e0;
border-left: 1px solid #e0e0e0;
background: #fafafa;
background: -webkit-gradient(linear, left top, left bottom, from(#fbfbfb), to(#fafafa));
background: -moz-linear-gradient(top, #fbfbfb, #fafafa);
}
table tr. even td {
background: #f6f6f6;
background: -webkit-gradient(linear, left top, left bottom, from(#f8f8f8), to(#f6f6f6));
background: -moz-linear-gradient(top, #f8f8f8, #f6f6f6);
}
table tr:last-child td:first-child {
-moz-border-radius-bottomleft:3px;
-WebKit-border-bottom-left-radius:3px;
border-bottom-left-radius:3px;
}
table tr:last-child td:last-child {
-moz-border-radius-bottomright:3px;
-WebKit-border-bottom-right-radius:3px;
border-bottom-right-radius:3px;
}
table tr: hover td {
background: #f2f2f2;
background: -webkit-gradient(linear, left top, left bottom, from(#f2f2f2), to(#f0f0f0));
background: -moz-linear-gradient(top, #f2f2f2, #f0f0f0);
}
@media only screen and (min-width:768px){
#main {
max-width: 370px;
}
}
[/code]
Once you will run the project, you will see two options to remove your duplicate email addresses.
First, you can enter multiple email addresses and copy and paste the addresses or you can upload a CSV file directly, in both cases you will get a list of unique email IDs.
You will also get an option to download your unique email addresses into a CSV File.
Note: Remember to make an upload folder in the source file.
Once you are done with all the above procedures then just run the project and you will get the output as shown in the below image.
Now either enter email addresses manually by copying and pasting or uploading a CSV file.
Now click the submit button and see the output with a download option as shown in the below image.
Conclusion:
So, within this extensive blog post, we have learned How to remove duplicate email addresses from a list. How do I delete duplicates in CSV? How do you remove duplicate values in Excel but keep one? How do I find duplicates in a CSV file? Remove duplicate entries in CSV file, Find duplicate values in CSV file, Remove Duplicates from CSV Excel
Now you can easily clean your email CSV list increase the chance for your email campaign success and filter out all the spammers and bad emails from your CSV list.
In case of any queries, you can write to us at a5theorys@gmail.com we will get back to you ASAP.
Hope! you would have enjoyed this post to remove duplicate email addresses.
Please feel free to give your important feedback in the comment section below.
Have a great time! Sayonara!