Web Design Forums

Welcome! Please register or log in: Forgot your password? Why register?
You are here: Web Design Forums » Programming Help » PHP » mailing list RSS

mailing list

This thread was started by pbahe and has been viewed 499 times, and contains 2 replies, with the last reply made by curare.
Post Reply
1
1 points at 100%
Posted June 2 '09 at 09:01 PM
      Posts: 9
I have a mailing list on my site www.shenanigansonmain.com/mailing.php and I have everything setup and working it stores the email address in a table but I need to know how to get the emails out of the table and send them an email automatically when they sign up welcoming them.
Thanks

Advertisement Register for free to hide these ads and participate in discussions!

2
1,251 points at 99% Moderator Repute
mlseim, WDF Moderator Private message  
Posted June 3 '09 at 08:20 AM
      Posts: 3,100
We need to see how is stores it in a table ... the script you have for that part.
If it's zero degrees outside today, and it's supposed to be twice as cold tomorrow, how cold is it going to be?

3
50 points at 100%
curare, WDF User Private message  
Posted June 11 '09 at 03:58 PM
      Posts: 48
There are a couple ways to accomplish this. First of all, if you're storing the email address as they sign up and you want to send them an email thanking them for doing so, you don't need to retrieve it from the database since you already have the email address on hand, probably in a $_POST variable. Then just send them a thank you note, like this:

// check for the required fields first
$email $_POST['email'];
$subject "Thank you for registering";

if (empty(
$email)) {
    
header("Location: /error.php");
    exit();
}


    
$message "Thank you for subscribing to our site....
    
    
    Thank you
    WebMaster, www.nowhere.com
    
    This is an automated response, please do not reply!"
;

    if (@
mail($mailto$subject$message"From: webmaster<me@nowhwere.com>\nX-Mailer: PHP/" phpversion())) {
       
header("Location: thank-you.html");
            exit();
    } else { 
    
// This echo's the error message if the email did not send. 
    // You could change the text in between the <p> tags. 
       
echo('<p>Mail could not be sent. Please use your back button to try again.</p>'); 
    }
?> 

This is very basic, no real error checking. You should do email address validation and such, but you should get the idea from this pretty easily.

Now, if you want to email them after-the-fact, say at a later date, you would do something like this:

<?php

$message 
"Thank you for subscribing to our site....
    
    
    Thank you
    WebMaster, www.nowhere.com
    
    This is an automated response, please do not reply!"
;
$subject "Thank you for registering";

//run a query to retrieve info from the table
$result mysql_query('SELECT * from users');
if (!
$result) {
    die(
'Invalid query: ' mysql_error());
}

// Use result
while ($row mysql_fetch_assoc($result)) {
@
mail($row['email'];, $subject$message"From: webmaster<me@nowhwere.com>\nX-Mailer: PHP/" phpversion());
}

// clean up after ourselves
mysql_free_result($result);
?>

Again, this is pretty simplistic and doesn't do a lot of the error checking and stuff that it should, but it should be enough to point you in the right direction. Obviously, you want to substitute your own message and subject and your database fields may be different, but you get the idea.

Hope this helps.

Post Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which Mailing List Software? Dissident General Design Discussion 1 December 13 '05 03:58 PM
Mailing List Input Lyle Christine HTML and CSS Help 0 October 16 '05 07:48 AM
External Mailing List Tool Mark_UK General Design Discussion 2 March 28 '05 12:49 AM
The [phpsec] Mailing List Wired PHP 5 January 27 '05 09:03 AM
mailing list help Firebrand Java and JSP 0 March 22 '03 03:50 PM