Menu
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.
[code] tags.
[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]
[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]
[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]
[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]
[code=php]
header('Location: http://'.$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
.'/'.$_POST['fruit'].'.html');
[/code]
[CODE][email protected]
[email protected]
[email protected]
[email protected][/CODE]
[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]
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]
0.1.9 — BETA 6.1