473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

PHP check a email.txt file or MySQL if exists before sending a message

Hi guys,

I've downloaded couple email list scripts at hotscripts but none of them do what I wanted. Can you help me?

Basically, I have an emaillist.txt (code from this site http://www.phptutorial.info/scripts/mailinglist/) which allow user to subscribe and unsubscribe.

If user selects subscribe, enter an email and that email is already in the emaillist.txt, a message is sent to that email saying thank you you've already subscribed.

If user selects subscribe, and email is not in the emailist.txt, a message is sent saying something like thank you for your interest, your email will be added to our emaillist as soon as possible. (*I will add the email into the emaillist.txt manually)

If user selects the unsubscribe, the message will say... sorry you have to leave etc.

The reason I do this is because I don't want to send out newsletter to those who aren't interested, or that they're not in group or friends.

Any suggestion would be greatly appreciated.
Nov 21 '06 #1
4 4209
[PHP]
$str = strtoupper(file_get_contents("emaillist.txt"));
if (strpos($str, strtoupper($InputedEmail)))
{//Already in file
}
else
{//New to file
}
[/PHP]
$InputedEmail will have to be declared yourself
strtoupper() lets makes all the characters uppercase to prevent captialization differences.
Nov 21 '06 #2
I just looked at that URL in your post and depending on how much of that you used, you may be able to take out the strtoupper() s and might need one strtolower(). It's up to you, but the code above will work regardless, though it might have redundancies.
Nov 21 '06 #3
So... is this correct? I don't have php to test it... please help.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $str = strtoupper(file_get_contents("emaillist.txt"));
  4. if (strpos($str, strtoupper($email)))
  5.     {
  6.  
  7.       if ($_SERVER['REQUEST_METHOD'] == "POST") {
  8.  
  9.             $realname = strip_tags($realname);
  10.             $email = strip_tags($email);
  11.             $feedback = "You already subscribed."
  12.  
  13.             $subject = "Send Mail Feedback";
  14.             $message = "$realname, $email\n\n$feedback";
  15.  
  16.         mail($email, $subject, $message);
  17.  
  18.     }
  19. }
  20.  
  21. else
  22.     {
  23.     //New to file
  24.       if ($_SERVER['REQUEST_METHOD'] == "POST") {
  25.  
  26.             $realname = strip_tags($realname);
  27.             $email = strip_tags($email);
  28.             $feedback = "You haven't subscribed yet.  We will add you into our mailing list."
  29.  
  30.             $subject = "Sorry";
  31.             $message = "$realname, $email\n\n$feedback";
  32.  
  33.         mail($email, $subject, $message);
  34.  
  35.     } 
  36.  
  37.  
  38. ?>
  39.  
  40. <html>
  41. <head>
  42.   <title></title>
  43. </head>
  44. <body>
  45.  
  46.  
  47. <?php 
  48. if ($_SERVER['REQUEST_METHOD'] == "POST") {
  49.  
  50.     $realname = $_POST['realname']; 
  51.     $email = $_POST['email']; 
  52.     $feedback = $_POST['feedback']; 
  53.  
  54.     echo("<p><b>The following message was sent to $email\n");
  55.     echo("$feedback");
  56.  
  57.     }
  58.     else {
  59. ?>
  60.  
  61.  
  62.   <form action="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD="POST">
  63.     Name: <input type="text" name="realname" size="25"></td></tr>
  64.     Email: <input type="text" name="email" size="25"></td></tr>
  65.     Feedback: <textarea name="feedback" rows="4" cols="40" wrap="physical"></textarea>
  66.   <input type="submit" value="Send Feedback">
  67.   </table>
  68.   </form>
  69.  
  70.  
  71. <?php } ?>
  72.  
  73. </body>
  74. </html>
  75.  
Nov 21 '06 #4
Hey, I tested the script, however it doesn't work correctly.

It went to the else statement. Any idea why?

the emaillist.txt file contains

myemail1@yahoo.com,
myemail2@yahoo.com,
myemail3@abc.com

I'm not sure if it matter with breakline, or a comma added after each one

Thanks
Nov 22 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: John | last post by:
I have over 5000 thumbnail pictures of size 5kb each. I would like to able to load all 5000 pictures and view 50 per page using mysql_data_seek(). I would like to know what are the advantages and...
5
by: Dan Williams | last post by:
Apologies for the cross-post but i thought i'd aim for the largest audience possible. I have a web site that users have to register to with their email address. The site then emails the user...
2
by: Jonathan | last post by:
I am looking for a simple way to check if a database table exists. I keep getting advice to use "Try.. Catch" and other error handling methods, but I obviously don't want to have to display an...
0
by: Alex82 | last post by:
I can't use it....for example i have to create a column that accept values between 1 to 120...i can't enumerate all of them....or i have to accept a value different from NULL if an other column has...
3
by: NurAzije | last post by:
Hi, I have a huge mailling list and want to check which mails are real and which does not exists to reduce the size, is there a function which will check if mail@mailserver.somthing exists or not...
10
by: Ricardo Luceac | last post by:
Hi all. I'm having a problem with this, I have look if a file exists, if don't wait till it is created and if it exists I need to open it. I do the following: for (; ; ) {
4
by: Ken D. | last post by:
I have an asp page that collects data on referrals. The user inputs the information and selects the rep to receive the referral. My data is being saved to a backend database (SQL) and the user is...
8
by: shapper | last post by:
Hello, I am trying to send an email using Asp.Net 2.0. I am getting the following error: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: No such...
3
by: trint | last post by:
How can I do this with my c# code with my website(because the file is there, but the code doesn't return it)?: if(File.Exists(String.Format("~/images/categories/{0}", sFileName)) return...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.