Click to See Complete Forum and Search --> : Email Check
xoxLISAxox
03-30-2008, 05:55 PM
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.
hastx
03-30-2008, 10:05 PM
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.
xoxLISAxox
03-30-2008, 10:11 PM
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
hastx
03-30-2008, 10:21 PM
post an example of your csv file format
NogDog
03-30-2008, 10:49 PM
Also take a look at the fgetcsv() function (http://www.php.net/fgetcsv[/man).
xoxLISAxox
03-31-2008, 12:43 AM
I can't attached a csv file :(
Thanks
Lisa
NogDog
03-31-2008, 01:47 AM
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.
xoxLISAxox
03-31-2008, 09:52 AM
It is really very simple, all I have is the list of email, for example:
myemail@home.net
hisemail@home.net
heremail@home.net
anotheremail@home.net
Thanks you so much,
Lis
hastx
03-31-2008, 04:39 PM
Havn't tested it but I think this is what you are looking for.
<?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');
?>
xoxLISAxox
04-04-2008, 03:43 AM
I am having a difficult time incorporating this to our existing codes. Any help will be appreciated.
<?php
$ipaddy = $_SERVER['REMOTE_ADDR'];
$mailfrom = 'email1@home.com'; // required
$mailcopy = 'email1@home.com'; // 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 .= ', email2@home.com'; //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
}
?>
in 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>
xoxLISAxox
04-06-2008, 12:32 PM
Someone please help!
xoxLISAxox
04-07-2008, 08:04 PM
Please Please Please Help!!!
:(
Sheldon
04-08-2008, 12:09 AM
I cant see where you have attempted it ?
Have you tried at all ?
Here is a quick attempt.
<?php
$ipaddy = $_SERVER['REMOTE_ADDR'];
$mailfrom = 'email1@home.com'; // required
$mailcopy = 'email1@home.com'; // 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 .= ', email2@home.com'; //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
}
?>
xoxLISAxox
04-08-2008, 12:07 PM
It's not working, it keeps bringing me to the default page:
header('Location: http://'.$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
.'/'.$_POST['fruit'].'.html');
I opened the csv file in notepad and it looks like:
myemail@home.net
hisemail@home.net
heremail@home.net
anotheremail@home.net
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
Sheldon
04-08-2008, 06:03 PM
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
<?php
$users = array("email1@domain.com","email2@domain.com","email3@domain.com","email4@domain.com");
if(in_array($_POST['email'], $users)){
// Special URL
header("Location: http://www.gozipline.com");
}else{
// Default URL
header("Location: http://www.google.com");
}
?>
xoxLISAxox
04-08-2008, 06:06 PM
Contains more than 1,000 email addresses and still growing. Is it wiser to use an array than a file?
Thanks so much,
Lis
Sheldon
04-08-2008, 06:14 PM
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.
xoxLISAxox
04-08-2008, 06:18 PM
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.
xoxLISAxox
04-09-2008, 09:40 AM
I thought this will be simple :( I can feel my gray hair coming out :eek:
xoxLISAxox
04-09-2008, 10:27 PM
Anything simpler that might work?
Sheldon
04-10-2008, 12:07 AM
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
xoxLISAxox
04-10-2008, 12:34 AM
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
Sheldon
04-10-2008, 12:37 AM
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.
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.
xoxLISAxox
04-10-2008, 12:41 AM
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
xoxLISAxox
04-10-2008, 01:28 PM
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
xoxLISAxox
04-11-2008, 11:37 AM
Anyone?
Please :(
xoxLISAxox
04-16-2008, 02:29 PM
Please Help!!
:(