/    Sign up×
Community /Pin to ProfileBookmark

We have an existing page that has been working great and would like to add a feature.

We have a list of email addresses saved as an Excel file. What we need is when the user enters their email address and click on the Submit button, is to go through all the email address in the list. If found, we need it to show a different url.

Is this be possible? I wouldn’t know how to begin. Any help would be appreciated.

to post a comment
PHP

26 Comments(s)

Copy linkTweet thisAlerts:
@hastxMar 31.2008 — If You convert your excel file to csv format, then it can be read easily by php or excel...then you can loop through the file, testing for the presence of the email address.
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorMar 31.2008 — Hi thanks so much. I can convert it the file to cvs format but don't know how to code it in php.

Thanks

Lisa
Copy linkTweet thisAlerts:
@hastxMar 31.2008 — post an example of your csv file format
Copy linkTweet thisAlerts:
@NogDogMar 31.2008 — Also take a look at the [url=http://www.php.net/fgetcsv[/man]fgetcsv() function[/url].
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorMar 31.2008 — I can't attached a csv file ?

Thanks

Lisa
Copy linkTweet thisAlerts:
@NogDogMar 31.2008 — You can rename it to have a ".txt" suffix and upload it, though it would probably be simpler for all to just copy-and-paste a few lines in a post here inside of [code] tags.
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorMar 31.2008 — It is really very simple, all I have is the list of email, for example:


[email][email protected][/email]

[email][email protected][/email]

[email][email protected][/email]

[email][email protected][/email]


Thanks you so much,

Lis
Copy linkTweet thisAlerts:
@hastxMar 31.2008 — Havn't tested it but I think this is what you are looking for.

[code=php]
<?PHP
$addy = trim($_POST['addy']);//get the address you are testing from the form
$db_lines = file('email_addys.csv'); //specify your csv

/////////////////////////
// Start loop to test each line against the addy from the form input
////////////////////////

foreach($db_lines as $existing){
trim($existing);
if($addy == $existing){
header('location: page_for_existing_users.html');
exit;
}
}

header('location: page_for_new_users.html');
?>
[/code]
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 04.2008 — I am having a difficult time incorporating this to our existing codes. Any help will be appreciated.

[code=php]
<?php
$ipaddy = $_SERVER['REMOTE_ADDR'];
$mailfrom = '[email protected]'; // required
$mailcopy = '[email protected]'; // optional
$mailsubj = 'Order from '; // required
$cr = "r"; // carriage-return character
$lf = "n"; // line-feed character
$lterm = $cr.$lf; // headers and body line terminator for email
//
$messages = ''; // form fields error messages
$emailadr = ''; // email adr field
$fullname = ''; // full name field
$fruit = ''; // amount field
//
// ---------------------------------------- //
if ($_SERVER['REQUEST_METHOD'] == 'POST'):
//
$emailadr = $_POST['emailadr']; // form email adr field
$fullname = $_POST['fullname']; // form full name field
$fruit = $_POST['site']; // site field
//
if(empty($fullname)): // if full name missing or invalid
$messages .= '1. ERROR: Your FULL NAME is required<br><br>'.$lf;
elseif('' != preg_replace('/[a-z .']/i', '', $fullname, -1)):
$messages .= '1. ERROR: Your FULL NAME contains invalid characters<br>'.$lf;
elseif(1 >= preg_match_all('/w+/', $fullname, $matches)):
$messages .= '1. ERROR: Your FULL NAME is required<br><br>'.$lf;
endif;

if(empty($emailadr)): // if email address missing or invalid
$messages .= '2. ERROR: Your EMAIL ADDRESS is required<br><br>'.$lf;
elseif(0 == preg_match('/^w+([.-]?w+)*@w+([.-]?w+)*.(w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/', $emailadr)):
$messages .= '2. ERROR: Your EMAIL ADDRESS format is invalid<br>'.$lf;
endif;

if($fruit=='Select One'): // site selection
$messages .= '4. ERROR: Select a FRUIT<br><br>'.$lf;
endif;

if($fruit == "apples"):
$mailcopy .= ', [email protected]'; //add cc if apple
endif;

//
if(strlen($messages)==0): // if all validations are good
$mailheaders = 'Content-Type: text/plain;'.$lterm; // set extra mail headers
$mailheaders .= 'X-Mailer: PHP;'.$lterm;
$mailheaders .= 'X-MSMail-Priority: High;'.$lterm;
$mailheaders .= 'X-Priority: 1;'.$lterm;
$mailheaders .= 'Return-path: '.$mailfrom.$lterm;
$mailheaders .= 'Sender: '.$mailfrom.$lterm;
$mailheaders .= 'From: '.$mailfrom.$lterm;
if (isset($mailcopy)
&& !empty($mailcopy)):
$mailheaders .= 'Cc: '.$mailcopy.$lterm;
endif;
$mailbody = "
You selected $fruit!
From IP: $ipaddy
" .$lterm;
ini_set(sendmail_from, $mailfrom);
if (mail($emailadr, $mailsubj, $mailbody, $mailheaders, "-f $mailfrom")):
ini_restore(sendmail_from);
header('Location: http://'.$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
.'/'.$_POST['fruit'].'.html');
exit;
endif;
ini_restore(sendmail_from);
$messages = 'Failed to send email!';
endif;
// ---------------------------------------- //
endif;
//
function set_selected($form_field, $field_value, $field_index)
{
if (isset($_POST[$form_field])
&& !empty($_POST[$form_field])): // if form field is present in post data
if ($field_value == $_POST[$form_field]): // and equals the expected value
$result = 'selected'; // then this form field should be checked
else: // else
$result = ''; // don't check it
endif;
else: // when no post data present
if ($field_index == 0): // and this is the first form field in the group
$result = 'selected'; // then this form field should be checked
else: // else
$result = ''; // don't check it
endif;
endif;
return $result; // return the selection result
}
?>
[/code]




in html:
[code=html]
<?php
if(strlen($messages)!=0):
echo '<p style="font-size:10pt;color:red;">' .$messages. '</p><br>' .$lf;
endif;
?>
<form name="myform" action="<?=basename($_SERVER['PHP_SELF'])?>" method="post">
<label>1. Your Name<br><input type="text" style="background-color: #FFF7C0; font-weight: bold" name="fullname" size="50" value="<?=$fullname?>"/> </label><br><br>
<label>2. Your Email<br><input type="text" style="background-color: #FFF7C0; font-weight: bold" name="emailadr" size="50" value="<?=$emailadr?>"/> </label><br><br>
<select name="fruit" style="background-color: #FFF7C0; font-weight: bold">
<option <?=set_selected('site', 'Select One', 0)?>>Select One</option>
<option <?=set_selected('site', 'Oranges', 1)?>>Oranges </option>
<option <?=set_selected('site', 'Grapes', 2)?>>Grapes </option>
<option <?=set_selected('site', 'Apples', 3)?>>Apples </option>
</select><br><br>
<label><input type='submit' value="SUBMIT ORDER"></label><br><br>
[/code]
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 06.2008 — Someone please help!
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 08.2008 — Please Please Please Help!!!

?
Copy linkTweet thisAlerts:
@SheldonApr 08.2008 — I cant see where you have attempted it ?

Have you tried at all ?


Here is a quick attempt.
[code=php]<?php

$ipaddy = $_SERVER['REMOTE_ADDR'];
$mailfrom = '[email protected]'; // required
$mailcopy = '[email protected]'; // optional
$mailsubj = 'Order from '; // required
$cr = "r"; // carriage-return character
$lf = "n"; // line-feed character
$lterm = $cr.$lf; // headers and body line terminator for email
//
$messages = ''; // form fields error messages
$emailadr = ''; // email adr field
$fullname = ''; // full name field
$fruit = ''; // amount field


// PAth to your CSV File
$csvFile = "address.csv";
//
// ---------------------------------------- //
if ($_SERVER['REQUEST_METHOD'] == 'POST'):
//
$emailadr = $_POST['emailadr']; // form email adr field
$fullname = $_POST['fullname']; // form full name field
$fruit = $_POST['site']; // site field
//
if(empty($fullname)): // if full name missing or invalid
$messages .= '1. ERROR: Your FULL NAME is required<br><br>'.$lf;
elseif('' != preg_replace('/[a-z .']/i', '', $fullname, -1)):
$messages .= '1. ERROR: Your FULL NAME contains invalid characters<br>'.$lf;
elseif(1 >= preg_match_all('/w+/', $fullname, $matches)):
$messages .= '1. ERROR: Your FULL NAME is required<br><br>'.$lf;
endif;

if(empty($emailadr)): // if email address missing or invalid
$messages .= '2. ERROR: Your EMAIL ADDRESS is required<br><br>'.$lf;
elseif(0 == preg_match('/^w+([.-]?w+)*@w+([.-]?w+)*.(w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/', $emailadr)):
$messages .= '2. ERROR: Your EMAIL ADDRESS format is invalid<br>'.$lf;
endif;

if($fruit=='Select One'): // site selection
$messages .= '4. ERROR: Select a FRUIT<br><br>'.$lf;
endif;

if($fruit == "apples"):
$mailcopy .= ', [email protected]'; //add cc if apple
endif;

//
if(strlen($messages)==0): // if all validations are good
$mailheaders = 'Content-Type: text/plain;'.$lterm; // set extra mail headers
$mailheaders .= 'X-Mailer: PHP;'.$lterm;
$mailheaders .= 'X-MSMail-Priority: High;'.$lterm;
$mailheaders .= 'X-Priority: 1;'.$lterm;
$mailheaders .= 'Return-path: '.$mailfrom.$lterm;
$mailheaders .= 'Sender: '.$mailfrom.$lterm;
$mailheaders .= 'From: '.$mailfrom.$lterm;
if (isset($mailcopy)
&& !empty($mailcopy)):
$mailheaders .= 'Cc: '.$mailcopy.$lterm;
endif;
$mailbody = "
You selected $fruit!
From IP: $ipaddy
" .$lterm;
ini_set(sendmail_from, $mailfrom);
if (mail($emailadr, $mailsubj, $mailbody, $mailheaders, "-f $mailfrom")):
ini_restore(sendmail_from);
$db_lines = @file($csvFile);
if(!empty($db_lines)){
foreach($db_lines as $existing){
@trim($existing);
if($addy == $existing){
@header('location: page_for_existing_users.html');
exit;
}
}
}
header('Location: http://'.$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
.'/'.$_POST['fruit'].'.html');
exit;
endif;
ini_restore(sendmail_from);
$messages = 'Failed to send email!';
endif;
// ---------------------------------------- //
endif;
//
function set_selected($form_field, $field_value, $field_index)
{
if (isset($_POST[$form_field])
&& !empty($_POST[$form_field])): // if form field is present in post data
if ($field_value == $_POST[$form_field]): // and equals the expected value
$result = 'selected'; // then this form field should be checked
else: // else
$result = ''; // don't check it
endif;
else: // when no post data present
if ($field_index == 0): // and this is the first form field in the group
$result = 'selected'; // then this form field should be checked
else: // else
$result = ''; // don't check it
endif;
endif;
return $result; // return the selection result
}
?>[/code]
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 08.2008 — It's not working, it keeps bringing me to the default page:

[code=php]
header('Location: http://'.$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
.'/'.$_POST['fruit'].'.html');
[/code]



I opened the csv file in notepad and it looks like:

[CODE][email protected]
[email protected]
[email protected]
[email protected][/CODE]


I thought csv format will be separated by comma? I thought I'd check this file first since I have no idea how to fix the php code. All I did was save it at csv format from Excel.

Thanks so much, I appreciate all the help I can get.

Lis
Copy linkTweet thisAlerts:
@SheldonApr 08.2008 — You you have to use a CSV File? Can you not just update an array in the PHP ?

Then you can have your array of emails, and check with in_array() Thus you can even specify a different url for every one.

single dimension array[code=php]
<?php
$users = array("[email protected]","[email protected]","[email protected]","[email protected]");
if(in_array($_POST['email'], $users)){
// Special URL
header("Location: http://www.gozipline.com");
}else{
// Default URL
header("Location: http://www.google.com");
}
?>[/code]
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 08.2008 — Contains more than 1,000 email addresses and still growing. Is it wiser to use an array than a file?

Thanks so much,

Lis
Copy linkTweet thisAlerts:
@SheldonApr 08.2008 — How do you populate the list? when people use your site? if that is the case i would use a sql database? That would be the best way.
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 08.2008 — Previous post I was adviced to save the email in cvs format which I did. This is something new, we have never done this before.
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 09.2008 — I thought this will be simple ? I can feel my gray hair coming out :eek:
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 10.2008 — Anything simpler that might work?
Copy linkTweet thisAlerts:
@SheldonApr 10.2008 — I personally would use a database for this.

The CSV method will work, but you just need to get that script working, it should be pretty close that last version i sent.

look at http://php.net/fgetcsv and http://php.net/file
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 10.2008 — Thank you so much Sheldon. I will do my best and see if I can figure this out. I will post if I run into any problems.

Thanks

Lis
Copy linkTweet thisAlerts:
@SheldonApr 10.2008 — 

I thought csv format will be separated by comma? I thought I'd check this file first since I have no idea how to fix the php code. All I did was save it at csv format from Excel.
[/QUOTE]


A CSV separates column values by comma's, but Row's by line breaks, As you are by the look of it exporting one column, there is no need to add commas.
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 10.2008 — So it seems like the csv file is format correctly, thanks for verifying.

I just browse the link you have me and I'm :eek:

LOL! I am not a programmer. I can understand a little bit. But those examples are way out of my leaque.

I posted the version you sent where I incorporated your codes into our existing one. Do you need me to repost?

Thanks

Lisa
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 10.2008 — I can't get it to work, it's giving me a bunch of error messages I don't even understand.

I am so frustrated ? please help!

Lis
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 11.2008 — Anyone?

Please ?
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 16.2008 — Please Help!!

?
×

Success!

Help @xoxLISAxox spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...