|
|||||||
| PHP Discussion and technical support for using and deploying PHP based websites. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Send Email To List
I run a non-profit web site for our local environmental managers group. I send out a newsletter once a month, however sometimes other needs to send it out. I need a PHP script where we can go to the web site, type in the message and it will send to the entire group. So it would need to hold a list of email addresses. I am not looking for anything fancy, but being a non-profit organization, I would like to find something free.
Any suggestions? Thanks, Jim |
|
#2
|
|||
|
|||
|
Ok, here we go. Create a file called emailgroup.php
I will not be making a login system for you...you'll have to figure that out yourself, or ask me again. Here's the code for email.php: PHP Code:
|
|
#3
|
||||
|
||||
|
zachzach:
That's ok if you want to get denied from pumping email addresses messages. You probably want to pause sending after a certain number. Also, it would be better for the user if the email addresses were in a separate file. Like this: emails.txt Code:
email_to@this.person email_to@this.person email_to@this.person email_to@this.person email_to@this.person email_to@this.person email_to@this.person email_to@this.person email_to@this.person email_to@this.person email_to@this.person email_to@this.person email_to@this.person Then create a PHP file: Code:
<?php
$message="some message";
$emails="emails.txt";
$from="youremail@mail.com";
$subject="some subject";
$counter=0;
$fp=fopen($emails,"r") or die("Cannot open file.");
while(!feof($fp)){
$email=trim(fgets($fp,4096));
if($counter%10==1){
sleep(2);
}
mail($email,$subject,$message,"From:$from");
$counter++;
}
fclose($fp);
?>
__________________
User is a four letter word! |
|
#4
|
|||
|
|||
|
I added my groups email addresses and changed the from emial address, then tested it. I got "error 404: File not found". Upon looking at the code further, I noticed it references <form action="/email.php" method="POST">. I don't have the file "email.php". Can you tell me where to get it?
Other than this, I believe this is exactly what I am looking for. Very simple. Thanks, Jim |
|
#5
|
||||
|
||||
|
Take the / out in from of the form action. And make sure the file you created with the code is named "email.php"
__________________
User is a four letter word! |
|
#6
|
|||
|
|||
|
other person whgo corrected my code(lol):
It was just a quicky code. I didn't spend much time on it, I was just trying to show the person a extreamly simplistic way of sending them |
|
#7
|
|||
|
|||
|
This worked great! Thanks.
If it's not asking too much, one other thing I would like to add is that when I click the send button, after it's done it's work sending the emails, I would like for it to take me to a particular web page. Can you show me how to modify the script to do that? Thanks again for the help. Jim |
|
#8
|
|||
|
|||
|
crh3675 - I like your ideas, so I tested it that way. Only problem is that each email address gets the note twice and it only shows the $Message. I wanted this to be a form, for our group organizations's officers to send out news to the whole chapter. So I was assuming your mod would work this way. Below is my code. See if I screwed something up. Also do I need to set the $counter to the number of emails to sleep on or have you preset that to 10 below?
Thanks, Jim code <?php $message="QCACHMM News"; $emails="emails.txt"; $from="info@queencitychmm.org"; $subject="QCACHMM News"; $counter=0; $fp=fopen($emails,"r") or die("Cannot open file."); while(!feof($fp)){ $email=trim(fgets($fp,4096)); if($counter%10==1){ sleep(2); } mail($email,$subject,$message,"From:$from"); $counter++; } fclose($fp); ?> <form action="groupemail.php" method="POST"><p> <label for="subject">Subject:</label><br /><input type="text" size="50" name="subject" id="subject"></p><p> <label for="message">Message:</label><br /><textarea rows="15" cols="75 id="message" name="message"></textarea></p><p> <br> <input type="submit" name="mode" value="Send Group Email"><br /> </p></form> |
|
#9
|
||||
|
||||
|
Here is the updated code:
Code:
<?php
if(isset($_POST["mode"]) || isset($mode)){
$redirect="http://yoursite.com/";
$body=isset($_POST["message"]) ? $_POST["message"] : $message;
$emails="emails.txt";
$from="info@queencitychmm.org";
$emailsubject=isset($_POST["subject"]) ? $_POST["subject"] : $subject;
$counter=0;
$fp=fopen($emails,"r") or die("Cannot open file.");
while(!feof($fp)){
$email=trim(fgets($fp,4096));
if($email!=""){
if($counter%10==0){
sleep(2);
}
mail($email,$mailsubject,$body,"From:".$from);
echo "Email sent to : $email<br>";
$counter++;
}
}
fclose($fp);
header("Location: $redirect");
}
?>
<form action="emails.php" method="POST"><p>
<label for="subject">Subject:</label><br /><input type="text" size="50" name="subject" id="subject"></p><p>
<label for="message">Message:</label><br /><textarea rows="15" cols="75 id="message" name="message"></textarea></p><p>
<br>
<input type="submit" name="mode" value="Send Group Email"><br />
</p></form>
__________________
User is a four letter word! Last edited by crh3675; 06-20-2004 at 10:27 AM. |
|
#10
|
|||
|
|||
|
crh3675 - This works great but there is one problem. Each email address in the "emails.txt" receives the form results twice. That is they receive two email notes, not one with the text twice. Just a little more help and it will be perfect!
Thanks again for all your help. Jim |
|
#11
|
||||
|
||||
|
Not sure why you would get 2 emails. I tested the script with no problem. I can look into it more. One thing I noticed was a misspelled variable:
mail($email,$mailsubject,$body,"From:".$from); $mailsubject should be $emailsubject
__________________
User is a four letter word! |
|
#12
|
|||
|
|||
|
crh3675 - I made the typo change and that fix the problem. I am now only getting one email for each address. Go figure.
However there is a little bug, which I can live with unless there is a quick fix. When I send the message from the form, it gives me the email addresses it sent the mail to at the top. That great, I like that confirmation. However, if I immediately send out another message (with the emails still listed at the top), it sends the old message again as well as the new message. It's like it holds the old message in cache. Clicking "refresh" does not reset the form (i.e. no sent emails at the top). I have to totally get off the page, then get back on to reset it. Now like I said, that is minor and something I can live with. I rarely send two messages back to back. Thank you again for all your help. Jim |
|
#13
|
||||
|
||||
|
Clicking the "refresh" button will re-post the form data and in fact submit to the list again. When you go back and reload the form page using the browser "reload" button, you are re-posting the data. What you need to do is NOT refresh the page but to just go to the URL in the browser. This holds true with all form posting on internet websites. You can do some workarounds using session variables to prevent multiple submissions but that would just complicate things. By the way, you can call me Craig. Glad I could help.
__________________
User is a four letter word! |
|
#14
|
|||
|
|||
|
Thanks Craig. This makes sense. I really apprciate the help. I could not have done it without you. As I build our web site I am thinking of more things I want to do, but I know so little about PHP. It's great to have you guys as a resource.
Thanks again, Jim |
|
#15
|
||||
|
||||
|
Feel free to email me at webnerd at comcast dot net if you need any other help
__________________
User is a four letter word! |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|