How do I remove duplicate email addresses from a CSV list? / How do I delete duplicate emails in CSV?

Hello Friends, In this blog post, I am going to explain how to remove duplicate email addresses from CSV file, 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 do I 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 CSV file, Find duplicate values in CSV file, Remove Duplicates from CSV Excel.

What are the disadvantages of duplicate email addresses in CSV?

There are various disadvantages of having duplicate email addresses in the CSV files.

In a case of fewer validation emails will be sent twice and more to the same email address and this can create a problem to our reputation and can also cause the
irritation for our users or client as they will receive the same email multiple times.

Few ESP has 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 100emails. Now let’s assume we have 50 duplicate email contacts then it will be a waste of 50 emails for us as they are the 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 the emails. And after removing the duplicate email addresses you can download them to a CSV file.


1. You just to install these software applications for developing 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.

duplicateemail4


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>”;
foreach ($array2 as $key1) {
foreach ($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 “Some thing 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
foreach ($file as $value) {
foreach ($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>”;
foreach ($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 “Some thing went wrong”;
}
?></div>
</div>
</div>
</body>
</html>
[/code]


csvdown.php:

[code]
<?php
ini_set(“display_errors”, 0);
?>
<?php
try {
$array2 = json_decode($_POST[‘lists1’]);
foreach ($array2 as $key) {
foreach ($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 “Some thing went wrong”;
}
?>
[/code]


emaildown.php:

[code]
<?php
ini_set(“display_errors”, 0);
?>
<?php

try {
$array2 = json_decode($_POST[‘lists’]);
foreach ($array2 as $key) {
foreach ($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 “Some thing 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:raleway;
}
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:raleway;
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:raleway;
}
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:raleway;
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:raleway;
margin-top: -50px;
}
#or:hover{
color: #204d74;
z-index: 8;
}
#file{
color:lightblue;
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 the list of unique email ids.
And 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 than just run the project and you will get the output as shown in the below image.

duplicateemail1


Now either enter email addresses manually by copy and paste or upload a CSV file.
duplicateemail2


Now click the submit button and see the output with a download option as shown in the below image.

duplicateemail3


Conclusion:

So, within this extensive blog post, we have learned How to I 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 and 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 [email protected] 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 feedbacks in the comment section below.

Have a great time! Sayonara!

Anurag

I am a blogger by passion, a software engineer by profession, a singer by consideration and rest of things that I do is for my destination.