PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
maxtran2005
Forum Newbie
Posts: 3 Joined: Tue Nov 21, 2006 9:09 pm
Post
by maxtran2005 » Tue Nov 21, 2006 9:14 pm
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi guys,
How do I check an input email from user to a text.txt file containing the list of email seperated by comma
emaillist.txtexample of email:Code: Select all
1234@yaho.com,
asdf@asgb.com,
a24t@asf.com,
423yg@yasdf.com
Code: Select all
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$email = strip_tags($email);
$str = strtoupper(file_get_contents("emaillist.txt"));
if (strpos($str, strtoupper($email)))
{
// stuff here
mail($email, $subject, $message);
}
else
{
// stuff here
mail($email, $subject, $message);
}
}
?>
The problem is that is goes to the else statement all the times so I think I didn't do it right. Any idea?
Thanks
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Nov 21, 2006 9:34 pm
neophyte
DevNet Resident
Posts: 1537 Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota
Post
by neophyte » Tue Nov 21, 2006 9:36 pm
Do you have register globals on? Otherwise I think $email should be referenced from the form like:
maxtran2005
Forum Newbie
Posts: 3 Joined: Tue Nov 21, 2006 9:09 pm
Post
by maxtran2005 » Tue Nov 21, 2006 9:38 pm
Here's the whole script
Code: Select all
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$email = strip_tags($email);
$str = strtoupper(file_get_contents("emaillist.txt"));
if (strpos($str, strtoupper($email)))
{
$feedback = "You already subscribed.";
$subject = "Thank you";
$message = "$email and $feedback";
mail($email, $subject, $message);
}
else
{
$feedback = "You haven't subscribed yet. We will add you into our mailing list.";
$subject = "Sorry";
$message = "$email and $feedback";
mail($email, $subject, $message);
}
}
?>
<html>
<head>
<title></title>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$email = $_POST['email'];
echo("<p><b>The following message was sent to $email\n");
}
else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD="POST">
<p>
Email:
<input type="text" name="email" size="25">
</td>
</tr>
<input type="submit" value="Send Feedback">
</table>
</p>
</form>
<?php } ?>
</body>
</html>
neophyte
DevNet Resident
Posts: 1537 Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota
Post
by neophyte » Tue Nov 21, 2006 9:48 pm
Unless register globals is on $email is empty.
Code: Select all
$email = strip_tags($_POST['email']);
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Nov 21, 2006 9:48 pm
Forgot to mention,
in_array() could also be used for the last couple parts.
maxtran2005
Forum Newbie
Posts: 3 Joined: Tue Nov 21, 2006 9:09 pm
Post
by maxtran2005 » Wed Nov 22, 2006 7:55 am
sorry to ask again, I can't make it work with what you said by adding the code below
$email = strip_tags($_POST['email']);
It still goes to the else statement. Other posts are helpful but I still don't know how to use explode() in_array() like u mentioned above.
Help please.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Nov 22, 2006 2:56 pm
What have you tried with the functions I've linked?