Jump to content


Photo

Mailing List


  • Please log in to reply
4 replies to this topic

#1 scott532

scott532
  • Members
  • PipPip
  • Member
  • 14 posts
  • LocationSanta Barbara, CA. (USA)

Posted 18 August 2006 - 06:22 PM

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

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 18 August 2006 - 09:17 PM

http://www.php.net

The very basics of PHP should help you going in the right direction. Good luck.
PHP Ninja

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 18 August 2006 - 09:31 PM

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

<?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());
}
?>

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
   
     

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 19 August 2006 - 01:40 AM

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:

$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;}
}


Legend has it that reading the manual never killed anyone.
My site

#5 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 19 August 2006 - 12:27 PM

^nice. I like that and will be using it from now on


thanks,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users