Jump to content

Mailing List


scott532

Recommended Posts

Hi, I'm a beginner php user and I am trying to figure out how to access email addresses from a mysql table. I want to get that data and place it into a textarea and be able to send an email to those addresses. I also want to know if there are good ways to avoid those outgoing emails from being received by Spam catchers. Any suggestions on what types of things I should study before writing this program would be appreciated.

Thanks,
Scott
Link to comment
Share on other sites

this is a very simple mass mailer. It should give you the basic idea.

[code]
<?php
$message = mysql_real_esacpe_string(trim($_POST['message']));
$subject = mysql_real_escape_string(trim($_POST['subject']));
if ((!$message) || (!$subject)) {
    echo "You did not enter ether a subject or a message. Please try again";
    include("somepage.php");
    exit(1);
}
$sql = mysql_query("SELECT * FROM `sometable` WHERE `something` = '$something'") or die(mysql_error());
if (!$sql) {
    echo "There was an error in geting the email addresses from the database";
    include("somepage.php");
    exit(1);
}
while ($rw = mysql_fetch_assoc($sql)) {
    $email = $rw['email']; //the email field in your database
    //this is a simple mail. You may want to add more headers.
    mail($email, $subject, $message, "From: You<you@yoursite.com>\nX-Mailer: PHP/" . phpversion());
}
?>[/code]

Now you just make a simple for with a textarea and a text box. One named message and the other subject. You then would post that to this script.

Hope that helps,
Tom
   
     
Link to comment
Share on other sites

If you want a happy server, avoid the overload associated with blasting out great amounts of mail by letting the server take a break once in a while:

[code]$i=0;
while ($rw = mysql_fetch_assoc($sql)) {
    $email = $rw['email']; //the email field in your database
    //this is a simple mail. You may want to add more headers.
    mail($email, $subject, $message, "From: You<you@yoursite.com>\nX-Mailer: PHP/" . phpversion());
    $i++; // dummy counter to see if it's time for a rest
    if ($i==20) { sleep(1); $i=0;}
}

[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.